示例#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]
     )