diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_django.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_django.py b/tests/test_django.py index 94e2420..8646764 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -30,6 +30,11 @@ if django_loaded and django.VERSION < (1, 7): # pragma: no cover except ImportError: 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) + @unittest.skipIf(not django_loaded, "Django not installed") class DjangoFieldTestCase(unittest.TestCase): @@ -48,6 +53,46 @@ class DjangoFieldTestCase(unittest.TestCase): obj.full_clean() + def test_version_save(self): + """Test saving object with a VersionField.""" + # first test with a null value + obj = models.PartialVersionModel() + self.assertIsNone(obj.id) + self.assertIsNone(obj.optional) + obj.save() + + # now retrieve from db + obj = refresh_from_db(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) + self.assertEqual(obj.optional_spec, spec) + + def test_spec_save(self): + """Test saving object with a SpecField.""" + # first test with a null value + obj = models.PartialVersionModel() + self.assertIsNone(obj.id) + self.assertIsNone(obj.optional_spec) + obj.save() + + # now retrieve from db + obj.refresh_from_db() + 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() + self.assertEqual(obj.optional_spec, spec) + def test_partial_spec(self): obj = models.VersionModel(version='0.1.1', spec='==0,!=0.2') self.assertEqual(semantic_version.Version('0.1.1'), obj.version) |