def test_it_creates_the_reference(self): sut = CreateModelWithReferenceAction( self.external_system, TestPerson, 'PersonJohn', ['first_name'], {'first_name': 'John', 'last_name': 'Smith'}) sut.execute() self.assertEqual(1, ExternalKeyMapping.objects.count())
def test_it_creates_the_reference_if_the_model_object_already_exists(self): john = TestPerson.objects.create(first_name='John') sut = CreateModelWithReferenceAction( self.external_system, TestPerson, 'PersonJohn', ['first_name'], {'first_name': 'John', 'last_name': 'Smith'}) sut.execute() self.assertEqual(1, TestPerson.objects.count()) self.assertEqual(1, ExternalKeyMapping.objects.count()) self.assertEqual(john, ExternalKeyMapping.objects.first().content_object)
def test_it_updates_the_reference_if_the_model_does_not_exist(self): mapping = ExternalKeyMapping.objects.create( external_system=self.external_system, external_key='PersonJohn', content_type=ContentType.objects.get_for_model(TestPerson), object_id=0) sut = CreateModelWithReferenceAction( self.external_system, TestPerson, 'PersonJohn', ['first_name'], {'first_name': 'John', 'last_name': 'Smith'}) sut.execute() self.assertEqual(1, ExternalKeyMapping.objects.count()) mapping.refresh_from_db() self.assertNotEqual(None, mapping.content_object)