Skip to content

Commit

Permalink
Add tests for Django's get_or_create.
Browse files Browse the repository at this point in the history
Related to issue #97.
  • Loading branch information
rbarrois committed Jul 7, 2020
1 parent 2351383 commit a7742f0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,17 @@ def test_db_interaction(self):

obj2 = models.VersionModel.objects.get(pk=o2.pk)
self.assertEqual(o2.version, obj2.version)

def test_get_or_create(self):
o1, created = models.VersionModel.objects.get_or_create(version=Version('0.1.1'), spec=SimpleSpec('==0.4.3'))
self.assertTrue(created)
self.assertIsNotNone(o1.pk)
self.assertEqual(Version('0.1.1'), o1.version)
self.assertEqual(SimpleSpec('==0.4.3'), o1.spec)

o2, created = models.VersionModel.objects.get_or_create(version=Version('0.1.1'), spec=SimpleSpec('==0.4.3'))
self.assertFalse(created)
self.assertEqual(o1, o2)
self.assertEqual(o1.pk, o2.pk)
self.assertEqual(Version('0.1.1'), o2.version)
self.assertEqual(SimpleSpec('==0.4.3'), o2.spec)

0 comments on commit a7742f0

Please sign in to comment.