Ejemplo n.º 1
0
 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())
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)