Browse files

Add introspection rules for south

Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
  • Loading branch information...
1 parent 1a3f269 commit 966849ba373c14b12effbda624a4982d9813e434 @rbarrois committed May 22, 2012
Showing with 72 additions and 0 deletions.
  1. +21 −0 src/semantic_version/django_fields.py
  2. +51 −0 tests/test_django.py
View
21 src/semantic_version/django_fields.py
@@ -59,3 +59,24 @@ def to_python(self, value):
if isinstance(value, base.Spec):
return value
return base.Spec(value)
+
+
+def add_south_rules():
+ from south.modelsinspector import add_introspection_rules
+
+ add_introspection_rules([
+ (
+ (VersionField,),
+ [],
+ {'partial': ('partial', {'default': False})},
+ ),
+ ], ["semantic_version\.django_fields"])
+
+
+try: # pragma: no cover
+ import south
+except ImportError: # pragma: no cover
+ south = None
+
+if south: # pragma: no cover
+ add_south_rules()
View
51 tests/test_django.py
@@ -31,6 +31,13 @@
from django_test_app import models
from django.core import serializers
+try: # pragma: no cover
+ import south
+ import south.creator.freezer
+ import south.modelsinspector
+except ImportError: # pragma: no cover
+ south = None
+
@unittest.skipIf(not django_loaded, "Django not installed")
class DjangoFieldTestCase(unittest.TestCase):
@@ -98,6 +105,50 @@ def test_serialization_partial(self):
self.assertEqual(o2, obj2.object)
+@unittest.skipIf(not django_loaded or south is None, "Couldn't import south and django")
+class SouthTestCase(unittest.TestCase):
+ def test_freezing_version_model(self):
+ frozen = south.modelsinspector.get_model_fields(models.VersionModel)
+
+ self.assertEqual(frozen['version'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200'}))
+
+ self.assertEqual(frozen['spec'],
+ ('semantic_version.django_fields.SpecField', [], {'max_length': '200'}))
+
+ def test_freezing_partial_version_model(self):
+ frozen = south.modelsinspector.get_model_fields(models.PartialVersionModel)
+
+ self.assertEqual(frozen['partial'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'partial': 'True'}))
+
+ self.assertEqual(frozen['optional'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'blank': 'True', 'null': 'True'}))
+
+ self.assertEqual(frozen['optional_spec'],
+ ('semantic_version.django_fields.SpecField', [], {'max_length': '200', 'blank': 'True', 'null': 'True'}))
+
+ def test_freezing_app(self):
+ frozen = south.creator.freezer.freeze_apps('django_test_app')
+
+ # Test VersionModel
+ self.assertEqual(frozen['django_test_app.versionmodel']['version'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200'}))
+
+ self.assertEqual(frozen['django_test_app.versionmodel']['spec'],
+ ('semantic_version.django_fields.SpecField', [], {'max_length': '200'}))
+
+ # Test PartialVersionModel
+ self.assertEqual(frozen['django_test_app.partialversionmodel']['partial'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'partial': 'True'}))
+
+ self.assertEqual(frozen['django_test_app.partialversionmodel']['optional'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'blank': 'True', 'null': 'True'}))
+
+ self.assertEqual(frozen['django_test_app.partialversionmodel']['optional_spec'],
+ ('semantic_version.django_fields.SpecField', [], {'max_length': '200', 'blank': 'True', 'null': 'True'}))
+
+
if django_loaded:
from django.test import TestCase
from django.test.simple import DjangoTestSuiteRunner

0 comments on commit 966849b

Please sign in to comment.