summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Rodger-Brown <hugo@yunojuno.com>2015-11-25 12:35:15 +0000
committerHugo Rodger-Brown <hugo@yunojuno.com>2015-11-25 12:35:15 +0000
commite8a1b3a543ab7d8b303f54e3ce48681f6c1589e7 (patch)
tree28072b2da0040c6f9b7440711217ca908a45a00b
parent0ef9524195546a607f43057207ac62c36e2bb38d (diff)
downloadsemantic-version-e8a1b3a543ab7d8b303f54e3ce48681f6c1589e7.tar.gz
Fix for failing test_django tests
I've added a save_and_refresh function to allow objects to be saved and then updated from the database, replicating the refresh_from_db method that exists in Django 1.8, and wrapping in the save method.
-rw-r--r--tests/test_django.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/tests/test_django.py b/tests/test_django.py
index 8646764..959b19c 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -31,9 +31,11 @@ if django_loaded and django.VERSION < (1, 7): # pragma: no cover
pass
# the refresh_from_db method only came in with 1.8, so in order to make this
-# work will all supported versions we have our own function
-def refresh_from_db(obj):
- return obj.__class__.objects.get(id=obj.id)
+# work will all supported versions we have our own function.
+def save_and_refresh(obj):
+ """Saves an object, and refreshes from the database."""
+ obj.save()
+ obj = obj.__class__.objects.get(id=obj.id)
@unittest.skipIf(not django_loaded, "Django not installed")
@@ -59,18 +61,14 @@ class DjangoFieldTestCase(unittest.TestCase):
obj = models.PartialVersionModel()
self.assertIsNone(obj.id)
self.assertIsNone(obj.optional)
- obj.save()
-
- # now retrieve from db
- obj = refresh_from_db(obj)
+ save_and_refresh(obj)
self.assertIsNotNone(obj.id)
self.assertIsNone(obj.optional_spec)
# now set to something that is not null
spec = semantic_version.Spec('==0,!=0.2')
obj.optional_spec = spec
- obj.save()
- obj = refresh_from_db(obj)
+ save_and_refresh(obj)
self.assertEqual(obj.optional_spec, spec)
def test_spec_save(self):
@@ -79,18 +77,14 @@ class DjangoFieldTestCase(unittest.TestCase):
obj = models.PartialVersionModel()
self.assertIsNone(obj.id)
self.assertIsNone(obj.optional_spec)
- obj.save()
-
- # now retrieve from db
- obj.refresh_from_db()
+ save_and_refresh(obj)
self.assertIsNotNone(obj.id)
self.assertIsNone(obj.optional_spec)
# now set to something that is not null
spec = semantic_version.Spec('==0,!=0.2')
obj.optional_spec = spec
- obj.save()
- obj.refresh_from_db()
+ save_and_refresh(obj)
self.assertEqual(obj.optional_spec, spec)
def test_partial_spec(self):