Kaydet (Commit) a60948ce authored tarafından Russell Keith-Magee's avatar Russell Keith-Magee

Migrated unmanaged_models doctests. Thanks to Eric Florenzano.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst 268123e7
...@@ -123,30 +123,3 @@ class Unmanaged2(models.Model): ...@@ -123,30 +123,3 @@ class Unmanaged2(models.Model):
# table *will* be created (unless given a custom `through` as for C02 above). # table *will* be created (unless given a custom `through` as for C02 above).
class Managed1(models.Model): class Managed1(models.Model):
mm = models.ManyToManyField(Unmanaged1) mm = models.ManyToManyField(Unmanaged1)
__test__ = {'API_TESTS':"""
The main test here is that the all the models can be created without any
database errors. We can also do some more simple insertion and lookup tests
whilst we're here to show that the second of models do refer to the tables from
the first set.
# Insert some data into one set of models.
>>> a = A01.objects.create(f_a="foo", f_b=42)
>>> _ = B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
>>> c = C01.objects.create(f_a="barney", f_b=1)
>>> c.mm_a = [a]
# ... and pull it out via the other set.
>>> A02.objects.all()
[<A02: foo>]
>>> b = B02.objects.all()[0]
>>> b
<B02: fred>
>>> b.fk_a
<A02: foo>
>>> C02.objects.filter(f_a=None)
[]
>>> C02.objects.filter(mm_a=a.id)
[<C02: barney>]
"""}
from django.test import TestCase from django.test import TestCase
from django.db import connection from django.db import connection
from models import Unmanaged1, Unmanaged2, Managed1 from models import Unmanaged1, Unmanaged2, Managed1
from models import A01, A02, B01, B02, C01, C02
class SimpleTests(TestCase):
def test_simple(self):
"""
The main test here is that the all the models can be created without
any database errors. We can also do some more simple insertion and
lookup tests whilst we're here to show that the second of models do
refer to the tables from the first set.
"""
# Insert some data into one set of models.
a = A01.objects.create(f_a="foo", f_b=42)
B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
c = C01.objects.create(f_a="barney", f_b=1)
c.mm_a = [a]
# ... and pull it out via the other set.
a2 = A02.objects.all()[0]
self.assertTrue(isinstance(a2, A02))
self.assertEqual(a2.f_a, "foo")
b2 = B02.objects.all()[0]
self.assertTrue(isinstance(b2, B02))
self.assertEqual(b2.f_a, "fred")
self.assertTrue(isinstance(b2.fk_a, A02))
self.assertEqual(b2.fk_a.f_a, "foo")
self.assertEqual(list(C02.objects.filter(f_a=None)), [])
resp = list(C02.objects.filter(mm_a=a.id))
self.assertEqual(len(resp), 1)
self.assertTrue(isinstance(resp[0], C02))
self.assertEqual(resp[0].f_a, 'barney')
class ManyToManyUnmanagedTests(TestCase): class ManyToManyUnmanagedTests(TestCase):
def test_many_to_many_between_unmanaged(self): def test_many_to_many_between_unmanaged(self):
""" """
The intermediary table between two unmanaged models should not be created. The intermediary table between two unmanaged models should not be created.
...@@ -11,7 +48,7 @@ class ManyToManyUnmanagedTests(TestCase): ...@@ -11,7 +48,7 @@ class ManyToManyUnmanagedTests(TestCase):
table = Unmanaged2._meta.get_field('mm').m2m_db_table() table = Unmanaged2._meta.get_field('mm').m2m_db_table()
tables = connection.introspection.table_names() tables = connection.introspection.table_names()
self.assert_(table not in tables, "Table '%s' should not exist, but it does." % table) self.assert_(table not in tables, "Table '%s' should not exist, but it does." % table)
def test_many_to_many_between_unmanaged_and_managed(self): def test_many_to_many_between_unmanaged_and_managed(self):
""" """
An intermediary table between a managed and an unmanaged model should be created. An intermediary table between a managed and an unmanaged model should be created.
...@@ -19,4 +56,3 @@ class ManyToManyUnmanagedTests(TestCase): ...@@ -19,4 +56,3 @@ class ManyToManyUnmanagedTests(TestCase):
table = Managed1._meta.get_field('mm').m2m_db_table() table = Managed1._meta.get_field('mm').m2m_db_table()
tables = connection.introspection.table_names() tables = connection.introspection.table_names()
self.assert_(table in tables, "Table '%s' does not exist." % table) self.assert_(table in tables, "Table '%s' does not exist." % table)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment