예제 #1
0
파일: test_models.py 프로젝트: tjguk/opal
 def test_bulk_update_from_dict(self):
     self.assertFalse(PatientColour.objects.exists())
     patient_colours = [{"name": "purple"}, {"name": "blue"}]
     patient = Patient.objects.create()
     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)
예제 #2
0
파일: test_models.py 프로젝트: tjguk/opal
 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
     }]
     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)
예제 #3
0
 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")
예제 #4
0
 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]
     )