コード例 #1
0
    def test_merge_insert(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient(firstName="roth")

        self.assertRaises(Patient.DoesNotExist, Patient.objects.get, uuid=p1.uuid)
        sp.apply_changes([p1])
        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
コード例 #2
0
    def test_merge_discard(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient.objects.create(firstName="roth")
        p1.firstName = "naris"
        p1.updated -= timedelta(seconds=60)

        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
        sp.apply_changes([p1])
        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
コード例 #3
0
 def test_merge_insert_m2m(self):
     ''' Ensure we can insert M2M association objects '''
     sp = SynchronizationProcessor(self.d1, self.models)
     p1 = Patient(firstName="roth")
     py1 = Physician.objects.create(firstName='ilise')
     rel = Patient_Physician(patient=p1, physician=py1)
     sp.apply_changes([p1, rel])
     self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
     self.assertSequenceEqual(Patient.objects.get(uuid=p1.uuid).physicians.all(), [py1])
コード例 #4
0
    def test_merge_multiple_vary(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient.objects.create(firstName="roth")
        p2 = Patient.objects.create(firstName="samsa")
        p1.firstName = "naris"
        p1.updated += timedelta(seconds=1)

        p2.firstName = "gracie"
        p2.updated -= timedelta(seconds=1)

        sp.apply_changes([p1, p2])
        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "naris")
        self.assertEqual(Patient.objects.get(uuid=p2.uuid).firstName, "samsa")
コード例 #5
0
    def test_merge_insert_m2m_both_misordered(self):
        ''' Ensure that both sides of the M2M relationship can be inserted at once
            ...and that the relationship model can be provided before the model it references
        '''
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient(firstName="roth")
        py1 = Physician(firstName='ilise', lastName='bhat', hashedPIN='1234')

        rel = Patient_Physician(patient=p1, physician=py1)

        sp.apply_changes([p1, rel, py1])
        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
        self.assertEqual(Physician.objects.get(uuid=py1.uuid).firstName, "ilise")
        self.assertSequenceEqual(Patient.objects.get(uuid=p1.uuid).physicians.all(), [py1])
コード例 #6
0
    def test_diff(self):
        ''' Test that we only sync objects from later timepoints'''
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient.objects.create(firstName="roth", synchronized=datetime(2000, 1, 1, tzinfo=pytz.utc))
        p2 = Patient.objects.create(firstName="wase", synchronized=datetime(2000, 1, 3, tzinfo=pytz.utc))
        py1 = Physician.objects.create(firstName='ilise', lastName='bhat', hashedPIN='1234',
                                       synchronized=datetime(2000, 1, 1, tzinfo=pytz.utc))
        Patient_Physician(patient=p1, physician=py1, synchronized=datetime(2000, 1, 1, tzinfo=pytz.utc)).save()
        Patient_Physician(patient=p2, physician=py1, synchronized=datetime(2000, 1, 1, tzinfo=pytz.utc)).save()
        Clinic_Physician(clinic=self.c1, physician=py1, synchronized=datetime(2000, 1, 1, tzinfo=pytz.utc)).save()
        # Turn QuerySet into patient objects
        result = sp.calculate_delta(datetime(2000, 1, 2, tzinfo=pytz.utc))
        result = [(x, list(y)) for (x, y) in result]

        self.assertEqual(result, [(Patient, [p2])])
コード例 #7
0
    def test_merge_time_travel(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient.objects.create(firstName="roth")
        p1.firstName = "naris"
        p1.synchronized += timedelta(seconds=60)

        self.assertRaises(SynchronizationProcessor.SynchronizationException, sp.apply_changes, [p1])
コード例 #8
0
    def test_merge_bad_data(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient.objects.create(firstName="roth")
        p1.firstName = None
        p1.synchronized += timedelta(seconds=60)

        self.assertRaises(ValidationError, sp.apply_changes, [p1])
        # Ensure we didn't save despite this
        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
コード例 #9
0
    def test_merge_insert_m2m_missing_fk(self):
        ''' Make sure the system rejects broken FK relationships '''
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient(firstName="roth")
        py1 = Physician(firstName='ilise', lastName='bhat', hashedPIN='1234')

        rel = Patient_Physician(patient=p1, physician=py1)

        self.assertRaises(ValidationError, sp.apply_changes, [p1, rel])
        # Ensure nothing was saved
        self.assertRaises(Patient.DoesNotExist, Patient.objects.get, uuid=p1.uuid)
        self.assertRaises(Physician.DoesNotExist, Physician.objects.get, uuid=py1.uuid)
コード例 #10
0
    def test_merge_bad_data_multiple(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        p1 = Patient.objects.create(firstName="roth")
        p2 = Patient.objects.create(firstName="samsa")
        p1.firstName = None
        p1.synchronized += timedelta(seconds=60)
        p2.firstName = "gracie"
        p2.updated += timedelta(seconds=1)

        self.assertRaises(ValidationError, sp.apply_changes, [p2, p1])
        # Reject the entire update because of a single failure
        self.assertEqual(Patient.objects.get(uuid=p2.uuid).firstName, "samsa")
        self.assertEqual(Patient.objects.get(uuid=p1.uuid).firstName, "roth")
コード例 #11
0
    def test_merge_insert_calls_hooks(self):
        sp = SynchronizationProcessor(self.d1, self.models)
        py1 = Physician(firstName="roth", lastName='bhat', hashedPIN='1234', recovery_answer="bob")

        sp.apply_changes([py1])
        assert (Physician.objects.get(uuid=py1.uuid).recovery_key.key is not None)