/
test_models.py
791 lines (661 loc) · 26.8 KB
/
test_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
"""
Unittests for opal.models
"""
import os
import datetime
from mock import patch, MagicMock
from django.conf import settings
from django.utils import timezone
from opal import models
from opal.core import exceptions
from opal.models import (
Subrecord, Tagging, Patient, InpatientAdmission, Symptom,
)
from opal.core.test import OpalTestCase
from opal.core import patient_lists
from opal.tests import test_patient_lists
from opal.tests.models import (
FamousLastWords, PatientColour, ExternalSubRecord, SymptomComplex,
PatientConsultation, Birthday, DogOwner, HatWearer, InvisibleHatWearer,
HouseOwner, HoundOwner, Colour, FavouriteColour, Dinner
)
class PatientRecordAccessTestCase(OpalTestCase):
def test_to_dict(self):
patient = models.Patient.objects.create()
access = models.PatientRecordAccess.objects.create(
user=self.user, patient=patient)
self.assertEqual(patient.id, access.to_dict(self.user)['patient'])
self.assertEqual(self.user.username, access.to_dict(self.user)['username'])
self.assertIsInstance(
access.to_dict(self.user)['datetime'], datetime.datetime
)
class PatientTestCase(OpalTestCase):
def test_create_episode(self):
patient = models.Patient()
patient.save()
episode = patient.create_episode()
self.assertEqual(models.Episode, episode.__class__)
self.assertEqual(patient, episode.patient)
@patch("opal.models.application.get_app")
def test_created_with_the_default_episode(self, get_app):
test_app = MagicMock()
test_app.default_episode_category ="testcategory"
get_app.return_value = test_app
_, episode = self.new_patient_and_episode_please()
self.assertEqual(episode.category_name, "testcategory")
def test_create_episode_category(self):
patient = models.Patient.objects.create()
e = patient.create_episode(category_name='testcategory')
self.assertEqual('testcategory', e.category_name)
def test_bulk_update_patient_subrecords(self):
original_patient = models.Patient()
d = {
"demographics": [{
"first_name": "Samantha",
"surname": "Sun",
"hospital_number": "123312"
}],
"patient_colour": [
{"name": "green"},
{"name": "purple"},
]
}
original_patient.bulk_update(d, self.user)
patient = Patient.objects.get()
demographics = patient.demographics_set.get()
self.assertEqual(demographics.first_name, "Samantha")
self.assertEqual(demographics.surname, "Sun")
self.assertEqual(demographics.hospital_number, "123312")
colours = patient.patientcolour_set.all()
self.assertEqual(len(colours), 2)
self.assertTrue(patient.episode_set.exists())
def test_bulk_update_patient_subrecords_respects_order(self):
patient = models.Patient()
d = {
"demographics": [{
"first_name": "Samantha",
"surname": "Sun",
"hospital_number": "123312"
}],
"patient_colour": [
{"name": "green"},
{"name": "purple"},
]
}
patient.bulk_update(d, self.user)
colours = patient.patientcolour_set.all()
self.assertEqual(colours[0].name, "green")
self.assertEqual(colours[1].name, "purple")
def test_bulk_update_with_existing_patient_episode(self):
original_patient = models.Patient()
original_patient.save()
original_episode = original_patient.create_episode()
d = {
"demographics": [{
"first_name": "Samantha",
"surname": "Sun",
"hospital_number": "123312"
}],
"patient_colour": [
{"name": "green"},
{"name": "purple"},
]
}
original_patient.bulk_update(d, self.user)
patient = Patient.objects.get()
demographics = patient.demographics_set.get()
self.assertEqual(demographics.first_name, "Samantha")
self.assertEqual(demographics.surname, "Sun")
self.assertEqual(demographics.hospital_number, "123312")
colours = patient.patientcolour_set.all()
self.assertEqual(len(colours), 2)
self.assertEqual(colours[0].name, "green")
self.assertEqual(colours[1].name, "purple")
self.assertTrue(patient.episode_set.get(), original_episode)
def test_bulk_update_without_demographics(self):
original_patient = models.Patient()
d = {
"patient_colour": [
{"name": "green"},
{"name": "purple"},
]
}
original_patient.bulk_update(d, self.user)
self.assertEqual(
original_patient.demographics_set.first().hospital_number, ""
)
def test_bulk_update_tagging(self):
original_patient = models.Patient()
original_patient.save()
d = {
"demographics": [{
"first_name": "Samantha",
"surname": "Sun",
"hospital_number": "123312"
}],
"tagging": [
{"id": 1, 'inpatient': True},
]
}
original_patient.bulk_update(d, self.user)
episode = original_patient.episode_set.first()
self.assertEqual(['inpatient'], episode.get_tag_names(self.user))
def test_bulk_update_episode_subrecords_without_episode(self):
original_patient = models.Patient()
d = {
"demographics": [{
"first_name": "Samantha",
"surname": "Sun",
"hospital_number": "123312"
}],
"hat_wearer": [
{"name": "bowler"},
{"name": "wizard"},
],
"location": [
{
"ward": "a ward",
"bed": "a bed"
},
]
}
self.assertFalse(models.Episode.objects.exists())
original_patient.bulk_update(d, self.user)
patient = Patient.objects.get()
demographics = patient.demographics_set.get()
self.assertEqual(demographics.first_name, "Samantha")
self.assertEqual(demographics.surname, "Sun")
self.assertEqual(demographics.hospital_number, "123312")
self.assertEqual(models.Episode.objects.count(), 1)
episode = patient.episode_set.get()
hat_wearers = episode.hatwearer_set.all()
self.assertEqual(len(hat_wearers), 2)
self.assertEqual(hat_wearers[0].name, "bowler")
self.assertEqual(hat_wearers[1].name, "wizard")
self.assertEqual(hat_wearers[0].episode, episode)
self.assertEqual(hat_wearers[1].episode, episode)
location = episode.location_set.get()
self.assertEqual(location.bed, "a bed")
self.assertEqual(location.ward, "a ward")
def test_bulk_update_create_new_episode_for_preexisting_patient_if_not_passed_explicitly(self):
original_patient = models.Patient()
d = {
"demographics": [{
"first_name": "Samantha",
"surname": "Sun",
"hospital_number": "123312"
}],
"hat_wearer": [
{"name": "bowler"},
{"name": "wizard"},
],
"location": [
{
"ward": "a ward",
"bed": "a bed"
},
]
}
original_patient.save()
original_patient.create_episode()
self.assertEqual(1, original_patient.episode_set.count())
original_patient.bulk_update(d, self.user)
self.assertEqual(2, original_patient.episode_set.count())
self.assertEqual(models.Episode.objects.count(), 2)
location = original_patient.episode_set.last().location_set.first()
self.assertEqual(location.ward, "a ward")
class SubrecordTestCase(OpalTestCase):
@patch('opal.models.find_template')
def test_get_template(self, find):
find.return_value = "found"
result = Subrecord._get_template("a_{}_b")
find.assert_called_once_with(["a_subrecord_b"])
self.assertEqual(result, "found")
@patch('opal.models.find_template')
def test_get_template_with_prefixes(self, find):
find.return_value = "found"
result = Subrecord._get_template("a_{}_b", prefixes=["onions"])
find.assert_called_once_with([
os.path.join("a_onions", "subrecord_b"),
"a_subrecord_b"
])
self.assertEqual(result, "found")
def test_get_display_name_from_property(self):
self.assertEqual('Wearer of Hats', HatWearer.get_display_name())
def test_get_display_name_from_meta_verbose_name(self):
self.assertEqual(
'Invisible Wearer of Hats',
InvisibleHatWearer.get_display_name()
)
def test_get_display_name_from_verbose_name_but_capwords(self):
self.assertEqual(
'Dog Owner',
DogOwner.get_display_name()
)
def test_date_time_deserialisation(self):
patient, _ = self.new_patient_and_episode_please()
birthday_date = "10/1/2000"
birthday_party= "11/2/2016 20:30:10"
birthday = Birthday()
birthday.update_from_dict(dict(
birth_date=birthday_date,
party=birthday_party,
patient_id=patient.id
), self.user)
bday = Birthday.objects.get()
self.assertEqual(bday.patient_id, patient.id)
self.assertEqual(bday.birth_date, datetime.date(2000, 1, 10))
# stip off miliseconds, we don't use them
start = bday.party.isoformat()[:19]
expected_start = '2016-02-11T20:30:10'
self.assertEqual(start, expected_start)
def test_display_template_does_not_exist(self):
self.assertEqual(None, Subrecord.get_display_template())
def test_time_deserialisation(self):
_, episode = self.new_patient_and_episode_please()
dinner_time = "20:00:00"
dinner = Dinner()
dinner.update_from_dict(dict(
episode_id=episode.id,
time=dinner_time
), self.user)
reloaded = Dinner.objects.get()
self.assertEqual(
reloaded.time, datetime.time(20)
)
def test_time_serialisation(self):
_, episode = self.new_patient_and_episode_please()
dinner = episode.dinner_set.create(time=datetime.time(20))
result = dinner.to_dict(self.user)
self.assertEqual(
result["time"], datetime.time(20, 0)
)
@patch('opal.models.find_template')
def test_display_template(self, find):
Subrecord.get_display_template()
find.assert_called_with(['records/subrecord.html'])
def test_detail_template_does_not_exist(self):
self.assertEqual(None, Subrecord.get_detail_template())
@patch('opal.models.find_template')
def test_detail_template(self, find):
Subrecord.get_detail_template()
find.assert_called_with([
'records/subrecord_detail.html',
'records/subrecord.html'
])
@patch('opal.models.find_template')
def test_detail_template_prefixes(self, find):
find.return_value = None
Subrecord.get_detail_template(prefixes=['onions'])
self.assertEqual(
find.call_args_list[0][0][0],
[
'records/onions/subrecord_detail.html',
'records/onions/subrecord.html',
'records/subrecord_detail.html',
'records/subrecord.html'
]
)
def test_form_template_does_not_exist(self):
self.assertEqual(None, Subrecord.get_form_template())
@patch('opal.models.find_template')
def test_form_template(self, find):
Subrecord.get_form_template()
find.assert_called_with(['forms/subrecord_form.html'])
def test_get_form_url(self):
url = Subrecord.get_form_url()
self.assertEqual(url, '/templates/forms/subrecord.html')
@patch('opal.models.find_template')
def test_form_template_prefixes(self, find):
Subrecord.get_form_template(prefixes=['onions'])
find.assert_called_with([
'forms/onions/subrecord_form.html',
'forms/subrecord_form.html'
])
def test_get_modal_template_does_not_exist(self):
self.assertEqual(None, Subrecord.get_modal_template())
@patch('opal.models.find_template')
@patch('opal.models.Subrecord.get_form_template')
def test_modal_template_no_form_template(self, modal, find):
modal.return_value = None
Subrecord.get_modal_template()
find.assert_called_with(['modals/subrecord_modal.html'])
def test_get_normal_field_title(self):
name_title = PatientColour._get_field_title("name")
self.assertEqual(name_title, "Name")
def test_get_foreign_key_or_free_text_title(self):
dog_title = DogOwner._get_field_title("dog")
self.assertEqual(dog_title, "Dog")
def test_get_title_over_many_to_many(self):
hats = HatWearer._get_field_title("hats")
self.assertEqual(hats, "Hats")
def test_get_title_over_reverse_foreign_key(self):
hats = HouseOwner._get_field_title("house")
self.assertEqual(hats, "Houses")
def test_verbose_name(self):
only_words = FamousLastWords._get_field_title("words")
self.assertEqual(only_words, "Only Words")
def test_enum(self):
enum = FavouriteColour.get_field_enum('name')
self.assertEqual(enum, ["purple", "yellow", "blue"])
def test_description(self):
description = FavouriteColour.get_field_description('name')
self.assertEqual(description, "orange is the new black")
def test_verbose_name_abbreviation(self):
# if a word is an abbreviation already, don't title case it!
osd = DogOwner._get_field_title("ownership_start_date")
self.assertEqual(osd, "OSD")
def test_get_defaults(self):
self.assertEqual("Catherine", DogOwner._get_field_default("name"))
def test_callable_defaults(self):
self.assertEqual("Philipa", HoundOwner._get_field_default("name"))
def test_defaults_if_there_are_no_defaults(self):
self.assertEqual(None, HatWearer._get_field_default("name"))
def test_get_defaults_from_free_text_and_foreign_key(self):
self.assertEqual("spaniel", DogOwner._get_field_default("dog"))
def test_get_defaults_from_free_text_and_foreign_key_lambda(self):
self.assertEqual("spaniel", HoundOwner._get_field_default("dog"))
def test_get_defaults_from_ftfk_when_there_are_no_defaults(self):
self.assertEqual(None, Colour._get_field_default("name"))
def test_get_defaults_with_an_datetime_throws_an_error(self):
name = Colour._meta.get_field("name")
with patch.object(name, "get_default") as get_default:
get_default.return_value = datetime.datetime.now()
with self.assertRaises(exceptions.APIError):
Colour._get_field_default("name")
def test_get_defaults_with_a_date_throws_an_error(self):
name = Colour._meta.get_field("name")
with patch.object(name, "get_default") as get_default:
get_default.return_value = datetime.date.today()
with self.assertRaises(exceptions.APIError):
Colour._get_field_default("name")
class BulkUpdateFromDictsTest(OpalTestCase):
def test_bulk_update_from_dict(self):
self.assertFalse(PatientColour.objects.exists())
patient_colours = [
{"name": "purple"},
{"name": "blue"}
]
patient = Patient.objects.create()
colours = PatientColour.bulk_update_from_dicts(
patient, patient_colours, self.user
)
expected_patient_colours = set(["purple", "blue"])
new_patient_colours = set(PatientColour.objects.values_list(
"name", flat=True
))
self.assertEqual(
expected_patient_colours, new_patient_colours
)
self.assertEqual(colours[0].name, "purple")
self.assertEqual(colours[1].name, "blue")
def test_bulk_update_existing_from_dict(self):
patient = Patient.objects.create()
patient_colours = []
for colour in ["green", "red"]:
patient_colours.append(
PatientColour.objects.create(patient=patient, name=colour)
)
patient_colours = [
{"name": "purple", "id": patient_colours[0].id},
{"name": "blue", "id": patient_colours[1].id}
]
colours = PatientColour.bulk_update_from_dicts(
patient, patient_colours, self.user
)
expected_patient_colours = ["purple", "blue"]
new_patient_colours = list(PatientColour.objects.values_list(
"name", flat=True
))
self.assertEqual(
expected_patient_colours, new_patient_colours
)
self.assertEqual(
expected_patient_colours, [i.name for i in colours]
)
def test_bulk_update_multiple_singletons_from_dict(self):
patient = Patient.objects.create()
famous_last_words = [
{"words": "so long and thanks for all the fish"},
{"words": "A towel is the most important item"},
]
with self.assertRaises(ValueError):
FamousLastWords.bulk_update_from_dicts(
patient, famous_last_words, self.user
)
def test_bulk_update_singleton(self):
patient = Patient.objects.create()
famous_model = FamousLastWords.objects.get()
famous_model.set_consistency_token()
famous_model.save()
famous_last_words = [
{"words": "A towel is the most important item"},
]
with self.assertRaises(exceptions.APIError):
FamousLastWords.bulk_update_from_dicts(
patient, famous_last_words, self.user
)
def test_bulk_update_singleton_with_force(self):
patient = Patient.objects.create()
famous_model = FamousLastWords.objects.get()
famous_model.set_consistency_token()
famous_model.save()
famous_last_words = [
{"words": "A towel is the most important item"},
]
FamousLastWords.bulk_update_from_dicts(
patient, famous_last_words, self.user, force=True
)
result = FamousLastWords.objects.get()
self.assertEqual(result.words, list(famous_last_words[0].values())[0])
class InpatientAdmissionTestCase(OpalTestCase):
def test_updates_with_external_identifer(self):
patient = models.Patient()
patient.save()
yesterday = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(1))
InpatientAdmission.objects.create(
datetime_of_admission=yesterday,
external_identifier="1",
patient=patient
)
now = timezone.make_aware(datetime.datetime.now()).strftime(
settings.DATETIME_INPUT_FORMATS[0]
)
update_dict = dict(
datetime_of_admission=now,
external_identifier="1",
patient_id=patient.id
)
a = InpatientAdmission()
a.update_from_dict(update_dict, self.user)
result = InpatientAdmission.objects.get()
self.assertEqual(
result.datetime_of_admission.date(),
datetime.date.today()
)
def test_no_external_identifier(self):
patient = models.Patient()
patient.save()
yesterday = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(1))
InpatientAdmission.objects.create(
datetime_of_admission=yesterday,
external_identifier="1",
patient=patient
)
now = datetime.datetime.now().strftime(
settings.DATETIME_INPUT_FORMATS[0]
)
update_dict = dict(
datetime_of_admission=now,
patient_id=patient.id
)
a = InpatientAdmission()
a.update_from_dict(update_dict, self.user)
results = InpatientAdmission.objects.all()
self.assertEqual(2, len(results))
self.assertEqual(
results[0].datetime_of_admission.date(),
yesterday.date()
)
self.assertEqual(
results[1].datetime_of_admission.date(),
datetime.date.today()
)
def test_doesnt_update_empty_external_identifier(self):
patient = models.Patient()
patient.save()
yesterday = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(1))
InpatientAdmission.objects.create(
datetime_of_admission=yesterday,
external_identifier="",
patient=patient
)
now = datetime.datetime.now().strftime(
settings.DATETIME_INPUT_FORMATS[0]
)
update_dict = dict(
datetime_of_admission=now,
external_identifier="",
patient_id=patient.id
)
a = InpatientAdmission()
a.update_from_dict(update_dict, self.user)
results = InpatientAdmission.objects.all()
self.assertEqual(2, len(results))
self.assertEqual(
results[0].datetime_of_admission.date(),
yesterday.date()
)
self.assertEqual(
results[1].datetime_of_admission.date(),
datetime.date.today()
)
def test_doesnt_update_a_different_patient(self):
other_patient = Patient.objects.create()
patient = models.Patient()
patient.save()
yesterday = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(1))
InpatientAdmission.objects.create(
datetime_of_admission=yesterday,
external_identifier="1",
patient=patient
)
now = datetime.datetime.now().strftime(
settings.DATETIME_INPUT_FORMATS[0]
)
update_dict = dict(
datetime_of_admission=now,
external_identifier="",
patient_id=other_patient.id
)
a = InpatientAdmission()
a.update_from_dict(update_dict, self.user)
results = InpatientAdmission.objects.all()
self.assertEqual(2, len(results))
self.assertEqual(
results[0].datetime_of_admission.date(),
yesterday.date()
)
self.assertEqual(
results[1].datetime_of_admission.date(),
datetime.date.today()
)
def test_update_from_dict_no_id_or_patient_id(self):
a = InpatientAdmission()
with self.assertRaises(ValueError):
a.update_from_dict({})
class PatientConsultationTestCase(OpalTestCase):
def setUp(self):
_, self.episode = self.new_patient_and_episode_please()
self.patient_consultation = PatientConsultation.objects.create(
episode_id=self.episode.id
)
def test_if_when_is_set(self):
when = datetime.datetime(2016, 6, 10, 12, 2, 20)
patient_consultation_dict = dict(
when='10/06/2016 12:02:20',
)
self.patient_consultation.update_from_dict(patient_consultation_dict, self.user)
patient_consultation = self.episode.patientconsultation_set.first()
self.assertEqual(patient_consultation.when.year, when.year)
self.assertEqual(patient_consultation.when.month, when.month)
self.assertEqual(patient_consultation.when.day, when.day)
def test_if_when_is_not_set(self):
now = timezone.now()
patient_consultation_dict = dict()
self.patient_consultation.update_from_dict(patient_consultation_dict, self.user)
patient_consultation = self.episode.patientconsultation_set.first()
self.assertTrue(patient_consultation.when >= now)
class SymptomComplexTestCase(OpalTestCase):
def setUp(self):
self.patient, self.episode = self.new_patient_and_episode_please()
super(SymptomComplexTestCase, self).setUp()
self.symptom_1 = Symptom.objects.create(name="tiredness")
self.symptom_2 = Symptom.objects.create(name="alertness")
self.symptom_3 = Symptom.objects.create(name="apathy")
self.symptom_complex = SymptomComplex.objects.create(
duration="a week",
details="information",
consistency_token=1111,
episode=self.episode
)
self.symptom_complex.symptoms.add(self.symptom_2, self.symptom_3)
def test_to_dict(self):
expected_data = dict(
id=self.symptom_complex.id,
consistency_token=self.symptom_complex.consistency_token,
symptoms=["alertness", "apathy"],
duration="a week",
details="information",
episode_id=1,
updated=None,
updated_by_id=None,
created=None,
created_by_id=None
)
self.assertEqual(
expected_data, self.symptom_complex.to_dict(self.user)
)
def test_update_from_dict(self):
data = {
u'consistency_token': self.symptom_complex.consistency_token,
u'id': self.symptom_complex.id,
u'symptoms': [u'alertness', u'tiredness'],
u'duration': 'a month',
u'details': 'other information'
}
self.symptom_complex.update_from_dict(data, self.user)
new_symptoms = self.symptom_complex.symptoms.values_list(
"name", flat=True
)
self.assertEqual(set(new_symptoms), set([u'alertness', u'tiredness']))
self.assertEqual(self.symptom_complex.duration, 'a month')
self.assertEqual(
self.symptom_complex.details, 'other information'
)
class TaggingTestCase(OpalTestCase):
def test_display_template(self):
self.assertEqual('tagging.html', Tagging.get_display_template())
def test_form_template(self):
self.assertEqual('tagging_modal.html', Tagging.get_form_template())
@patch.object(patient_lists.TaggedPatientList, "list")
def test_field_schema(self, patient_list):
patient_list.return_value = [test_patient_lists.TaggingTestPatientList]
expected = [
{'name': 'eater', 'title': 'Eater', 'type': 'boolean'},
{'type': 'boolean', 'name': 'herbivore', 'title': 'Herbivore'}
]
schema = Tagging.build_field_schema()
self.assertEqual(expected, schema)
class AbstractDemographicsTestCase(OpalTestCase):
def test_name(self):
d = models.Demographics(first_name='Jane',
surname='Doe',
middle_name='Obsidian')
self.assertEqual('Jane Doe', d.name)
class ExternalSystemTestCase(OpalTestCase):
def test_get_footer(self):
self.assertEqual(
ExternalSubRecord.get_modal_footer_template(),
"partials/_sourced_modal_footer.html"
)