Commits

Andrew Godwin  committed 714bc3b

Basic tests for the modelsinspector

  • Participants
  • Parent commits 1e01b85

Comments (0)

Files changed (6)

 # Ignore dist builds and egg info
 dist/*
 South.egg-info/*
+# Ignore test log
+south/tests/test.log

File south/modelsinspector.py

     attrname, options = descriptor
     value = get_attribute(field, attrname)
     # Lazy-eval functions get eval'd.
-    # Annoyingly, we can't do an isinstance() test
     if isinstance(value, Promise):
         value = unicode(value)
     # If the value is the same as the default, omit it for clarity

File south/tests/__init__.py

 
 import unittest
+import os
+import sys
 from django.conf import settings
 from south.hacks import hacks
 
+# Add the tests directory so fakeapp is on sys.path
+test_root = os.path.dirname(__file__)
+sys.path.append(test_root)
+
 # Note: the individual test files are imported below this.
 
 class Monkeypatcher(unittest.TestCase):
         """
         Changes the Django environment so we can run tests against our test apps.
         """
+        # Set the installed apps
         hacks.set_installed_apps(["fakeapp", "otherfakeapp"])
     
     
     from south.tests.logic import *
     from south.tests.autodetection import *
     from south.tests.logger import *
+    from south.tests.inspector import *

File south/tests/inspector.py

+import unittest
+
+from south.tests import Monkeypatcher
+from south.modelsinspector import *
+from fakeapp.models import HorribleModel
+
+class TestModelInspector(Monkeypatcher):
+
+    """
+    Tests if the various parts of the modelinspector work.
+    """
+    
+    def test_get_value(self):
+        
+        # Let's start nicely.
+        name = HorribleModel._meta.get_field_by_name("name")[0]
+        slug = HorribleModel._meta.get_field_by_name("slug")[0]
+        user = HorribleModel._meta.get_field_by_name("user")[0]
+        
+        # Simple int retrieval
+        self.assertEqual(
+            get_value(name, ["max_length", {}]),
+            "255",
+        )
+        
+        # Bool retrieval
+        self.assertEqual(
+            get_value(slug, ["unique", {}]),
+            "True",
+        )
+        
+        # String retrieval
+        self.assertEqual(
+            get_value(user, ["rel.related_name", {}]),
+            "'horribles'",
+        )
+        
+        # Default triggering
+        self.assertEqual(
+            get_value(slug, ["unique", {"default": False}]),
+            "True",
+        )
+        self.assertRaises(
+            IsDefault,
+            get_value,
+            slug,
+            ["unique", {"default": True}],
+        )
+    

File south/tests/logger.py

     def test_db_execute_logging_nofile(self):
         """ Does logging degrade nicely if SOUTH_DEBUG_ON not set?
         """
-        settings.SOUTH_DEBUG_ON = False     # this needs to be set to False
-                                            # to avoid issues where other tests
-                                            # set this to True. settings is shared
-                                            # between these tests.
+        settings.SOUTH_LOGGING_ON = False     # this needs to be set to False
+                                              # to avoid issues where other tests
+                                              # set this to True. settings is shared
+                                              # between these tests.
         db.create_table("test9", [('email_confirmed', models.BooleanField(default=False))])
         
     def test_db_execute_logging_validfile(self):
         """ Does logging work when passing in a valid file?
         """
-        settings.SOUTH_DEBUG_ON = True
+        settings.SOUTH_LOGGING_ON = True
         settings.SOUTH_LOGGING_FILE = self.test_path
         db.create_table("test10", [('email_confirmed', models.BooleanField(default=False))])
         
     def test_db_execute_logging_missingfilename(self):
         """ Does logging raise an error if there is a missing filename?
         """
-        settings.SOUTH_DEBUG_ON = True
+        settings.SOUTH_LOGGING_ON = True
+        settings.SOUTH_LOGGING_FILE = None
         self.assertRaises(IOError,
             db.create_table, "test11", [('email_confirmed', models.BooleanField(default=False))])
         

File south/tests/logic.py

 from south.tests import Monkeypatcher
 from south.utils import snd
 
-# Add the tests directory so fakeapp is on sys.path
-test_root = os.path.dirname(__file__)
-sys.path.append(test_root)
-
-
 class TestMigrationLogic(Monkeypatcher):
 
     """