Commits

Ionel Cristian Mărieș  committed e228c4d

Removed duplicate models and tests; Slightly corrected some tests.

  • Participants
  • Parent commits 189ec4d

Comments (0)

Files changed (1)

File tests/test_project/apps/testapp/tests.py

         self.assertRaises(TypeError, lambda: TestModelC.objects.filter(cmtm_a_cache=1))
 
 
-from django.test import TestCase
-
-from models import *
-
 class InheritedFieldSyncFlagTest(TestCase):
     def setUp(self):
         self.parent = TestModelParent.objects.create(title='Parent')
 
     def test_local_value(self):
         self.child.title = 'Child'
-        self.assertEquals(self.child.title_inherited, False)
+        self.assertEquals(self.child.is_title_inherited, False)
         self.assertEquals(self.child.title, 'Child')
         self.assertEquals(self.parent.title, 'Parent')
 
 
         self.assertEquals(self.parent.title, 'Parent 1')
         self.assertEquals(self.child.title, 'Child')
-        self.assertEquals(self.child.title_inherited, False)
+        self.assertEquals(self.child.is_title_inherited, False)
 
     def test_restore_inherited_flag(self):
         self.child.title = 'Child'
 
 ##########################################
 
-
-class Stuff(models.Model):
-    pass
-
-class TestModel1(models.Model):
-    bar = models.CharField(max_length=10)
-    m2mrel = models.ManyToManyField(Stuff)
-
-class TestModel1_Cached(models.Model):
-    bar = models.CharField(max_length=10)
-    m2mrel = cachedmtmfield.CachedManyToManyField(Stuff)
-
-class TestModel2(models.Model):
-    parent = models.ForeignKey(TestModel1, null=True)
-
-    bar = models.CharField(max_length=10)
-    foo = inheritedfield.InheritedField('parent', 'bar', validate=False)
-    ifoo = inheritedfield.InheritedField('parent', 'bar', inherit_only=True)
-
-class TestModel6(models.Model): #used in test_model_field_double_inheritance
-    parent_for_6 = models.ForeignKey(TestModel1)
-    foo = inheritedfield.InheritedField('parent_for_6', 'bar')
-class TestModel7(models.Model): #used in test_model_field_double_inheritance
-    parent_for_7 = models.ForeignKey(TestModel6)
-    bogus_relation = models.ForeignKey(TestModel6, related_name="bogus", null=True)
-    boo = inheritedfield.InheritedField('parent_for_7', 'foo')
-class TestModel8(models.Model): #used in test_model_field_double_inheritance
-    parent_for_8 = models.ForeignKey(TestModel7)
-    goo = inheritedfield.InheritedField('parent_for_8', 'boo')
-
 class InheritedFieldTests(TestCase):
     def test_model_field_inheritance_broken_parent(self):
         b = TestModel2()
         b.save()
         b.foo = 'abc'
         self.assertEquals(b.foo, 'abc')
-        self.assertEquals(b.foo_local_value, 'abc')
-        self.assertEquals(b.foo_is_inherited, False)
+        self.assertEquals(b.foo_inherited_value, 'abc')
+        self.assertEquals(b.is_foo_inherited, False)
 
         # this tests handling for broken FKs
         b = TestModel2()
         b.parent_id = 99999
         b.foo = 'abc'
         self.assertEquals(b.foo, 'abc')
-        self.assertEquals(b.foo_local_value, 'abc')
-        self.assertEquals(b.foo_is_inherited, False)
+        self.assertEquals(b.foo_inherited_value, 'abc')
+        self.assertEquals(b.is_foo_inherited, False)
 
     def test_model_field_inheritance_simple(self):
         a = TestModel1(bar="123")
 
         self.assertEquals(a.bar, '123')
         self.assertEquals(b.foo, '123')
-        self.assertEquals(b.foo_is_inherited, True)
+        self.assertEquals(b.is_foo_inherited, True)
 
         b.foo = 'abc'
         self.assertEquals(a.bar, '123')
         self.assertEquals(b.foo, 'abc')
-        self.assertEquals(b.foo_local_value, 'abc')
-        self.assertEquals(b.foo_is_inherited, False)
+        self.assertEquals(b.foo_inherited_value, 'abc')
+        self.assertEquals(b.is_foo_inherited, False)
 
         self.assertEquals(b.ifoo, '123')
         a.bar = 'qwe'
                 parent = models.ForeignKey(TestModel1)
 
         except TypeError, e:
-            self.assertEquals(e.args[0], "InheritedField: no_parent does not exist on <class 'test_project.apps.testapp.models.TestModel4_Invalid'>.")
+            self.assertEquals(e.args[0], "InheritedField: no_parent does not exist on <class 'test_project.apps.testapp.tests.TestModel4_Invalid'>.")
         else:
             self.fail("Didn't raise any TypeError (no_parent test)")
 
                 parent = models.ForeignKey(TestModel6_Invalid)
                 foo = inheritedfield.InheritedField('parent', 'no_bar')
         except TypeError, e:
-            self.assertEquals(e.args[0], "InheritedField: no_bar does not exist in <class 'test_project.apps.testapp.models.TestModel6_Invalid'>.")
+            self.assertEquals(e.args[0], "InheritedField: no_bar does not exist in <class 'test_project.apps.testapp.tests.TestModel6_Invalid'>.")
         else:
             self.fail("Didn't raise any TypeError (no_bar (target field) test)")
 
 
         self.assertEquals(b.foo, '123')
         self.assertEquals(d.goo, '123')
-        self.assertEquals(b.foo_is_inherited, True)
-        self.assertEquals(d.goo_is_inherited, True)
+        self.assertEquals(b.is_foo_inherited, True)
+        self.assertEquals(d.is_goo_inherited, True)
 
         c.boo = 'abc'
         self.assertEquals(c.boo, 'abc')
-        self.assertEquals(c.boo_is_inherited, False)
+        self.assertEquals(c.is_boo_inherited, False)
         self.assertEquals(c.get_boo_display(), "abc")
         self.assertEquals(d.goo, 'abc')
-        self.assertEquals(d.goo_is_inherited, True)
+        self.assertEquals(d.is_goo_inherited, True)
         self.assertEquals(d.get_goo_display(), "abc *Inherited")
 
 
 ######################################################
 
 
-class InheritedFieldTests(TestCase):
-    def test_model_field_inheritance_broken_parent(self):
-        b = TestModel2()
-        b.save()
-        b.foo = 'abc'
-        self.assertEquals(b.foo, 'abc')
-        self.assertEquals(b.foo_value, 'abc')
-        self.assertEquals(b.is_foo_inherited, False)
 
-        # this tests handling for broken FKs
-        b = TestModel2()
-        b.parent_id = 99999
-        b.foo = 'abc'
-        self.assertEquals(b.foo, 'abc')
-        self.assertEquals(b.foo_value, 'abc')
-        self.assertEquals(b.is_foo_inherited, False)
-
-    def test_model_field_inheritance_simple(self):
-        a = TestModel1(bar="123")
-        a.save()
-
-        b = TestModel2(parent=a)
-        b.save()
-
-        self.assertEquals(a.bar, '123')
-        self.assertEquals(b.foo, '123')
-        self.assertEquals(b.is_foo_inherited, True)
-
-        b.foo = 'abc'
-        self.assertEquals(a.bar, '123')
-        self.assertEquals(b.foo, 'abc')
-        self.assertEquals(b.foo_value, 'abc')
-        self.assertEquals(b.is_foo_inherited, False)
-
-        self.assertEquals(b.ifoo, '123')
-        a.bar = 'qwe'
-        self.assertEquals(b.ifoo, 'qwe')
-
-        from dcfields.inheritedfield import InheritedOnlyException
-        try:
-            b.ifoo = 'fail'
-        except InheritedOnlyException, e:
-            self.assertEquals(e.args[0], "Can't set value for field ifoo on TestModel2 object (field is inherit_only). Try to set it on parent.bar.")
-
-        else:
-            self.fail("Didn't raise any TypeError")
-
-    def test_model_field_inheritance_silly(self):
-        class TestModel3_Valid(models.Model):
-            parent = models.ForeignKey(TestModel1)
-            foo = inheritedfield.InheritedField('parent', 'bar')
-            m2mrel = inheritedfield.InheritedField('parent')
-
-
-        class TestModel_Temp2(models.Model):
-            parent = models.ForeignKey("TestModel_Temp1")
-            m2mrel = inheritedfield.InheritedField('parent')
-        class TestModel_Temp1(models.Model):
-            m2mrel = models.ManyToManyField(Stuff)
-
-    def test_model_field_inheritance_validation(self):
-        try:
-            class TestModel4_Invalid(models.Model):
-                foo = inheritedfield.InheritedField('no_parent', 'bar')
-                parent = models.ForeignKey(TestModel1)
-
-        except TypeError, e:
-            self.assertEquals(e.args[0], "InheritedField: no_parent does not exist on <class 'test_project.apps.testapp.models.TestModel4_Invalid'>.")
-        else:
-            self.fail("Didn't raise any TypeError (no_parent test)")
-
-        try:
-            class TestModel5_Invalid(models.Model):
-                parent = models.ForeignKey(TestModel1)
-                foo = inheritedfield.InheritedField('parent', 'no_bar')
-        except TypeError, e:
-            self.assertEquals(e.args[0], "InheritedField: no_bar does not exist in <class 'test_project.apps.testapp.models.TestModel1'>.")
-        else:
-            self.fail("Didn't raise any TypeError (no_bar (target field) test)")
-
-        try:
-            class TestModel6_Invalid(models.Model):
-                parent = models.ForeignKey(TestModel2)
-                foo = inheritedfield.InheritedField('parent', 'bar')
-            class TestModel7_Invalid(models.Model):
-                parent = models.ForeignKey(TestModel6_Invalid)
-                foo = inheritedfield.InheritedField('parent', 'no_bar')
-        except TypeError, e:
-            self.assertEquals(e.args[0], "InheritedField: no_bar does not exist in <class 'test_project.apps.testapp.models.TestModel6_Invalid'>.")
-        else:
-            self.fail("Didn't raise any TypeError (no_bar (target field) test)")
-
-    def test_parent_not_a_rel(self):
-        try:
-            class TestModel8_Invalid(models.Model):
-                parent = models.BooleanField()
-                foo = inheritedfield.InheritedField('parent', 'bar')
-        except TypeError, e:
-            self.assertEquals(e.args[0], "InheritedField: parent is a <class 'django.db.models.fields.BooleanField'> instead of a RelatedField.")
-        else:
-            self.fail("Didn't raise any TypeError (no_bar (target field) test)")
-
-        class TestModel9_Invalid(models.Model):
-            parent = models.BooleanField()
-            foo = inheritedfield.InheritedField('parent', 'bar', validate=False)
-        #should work :)
-
-
-    def test_select_related(self):
-        self.assertFalse(hasattr(TestModel8, "FIELD_INHERITANCE_REL"))
-        qs = TestModel8.objects.filter()
-        self.assertTrue(hasattr(TestModel8, "FIELD_INHERITANCE_REL"))
-        self.assertEquals(`qs.query.select_related`, "{'parent_for_8': {'parent_for_7': {'parent_for_6': {}}}}")
-        self.assertEquals(TestModel8.FIELD_INHERITANCE_REL, set(['parent_for_8__parent_for_7__parent_for_6']))
-        qs = TestModel2.objects.filter()
-        self.assertEquals(`qs.query.select_related`, "{'parent': {}}")
-
-    def test_model_field_double_inheritance(self):
-        a = TestModel1(bar="123")
-        a.save()
-
-        b = TestModel6(parent_for_6=a)
-        b.save()
-
-        c = TestModel7(parent_for_7=b)
-        c.save()
-
-        d = TestModel8(parent_for_8=c)
-        d.save()
-
-        self.assertEquals(b.foo, '123')
-        self.assertEquals(d.goo, '123')
-        self.assertEquals(b.is_foo_inherited, True)
-        self.assertEquals(d.is_goo_inherited, True)
-
-        c.boo = 'abc'
-        self.assertEquals(c.boo, 'abc')
-        self.assertEquals(c.is_boo_inherited, False)
-        self.assertEquals(c.get_boo_display(), "abc")
-        self.assertEquals(d.goo, 'abc')
-        self.assertEquals(d.is_goo_inherited, True)
-        self.assertEquals(d.get_goo_display(), "abc *Inherited")
 
 class CachedManyToManyTests(TestCase):
     #def test_that_is_not_a_test(self):