Skip to content

Commit a60948c

Browse files
committed
Migrated unmanaged_models doctests. Thanks to Eric Florenzano.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13825 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 268123e commit a60948c

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

tests/modeltests/unmanaged_models/models.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,3 @@ class Meta:
123123
# table *will* be created (unless given a custom `through` as for C02 above).
124124
class Managed1(models.Model):
125125
mm = models.ManyToManyField(Unmanaged1)
126-
127-
__test__ = {'API_TESTS':"""
128-
The main test here is that the all the models can be created without any
129-
database errors. We can also do some more simple insertion and lookup tests
130-
whilst we're here to show that the second of models do refer to the tables from
131-
the first set.
132-
133-
# Insert some data into one set of models.
134-
>>> a = A01.objects.create(f_a="foo", f_b=42)
135-
>>> _ = B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
136-
>>> c = C01.objects.create(f_a="barney", f_b=1)
137-
>>> c.mm_a = [a]
138-
139-
# ... and pull it out via the other set.
140-
>>> A02.objects.all()
141-
[<A02: foo>]
142-
>>> b = B02.objects.all()[0]
143-
>>> b
144-
<B02: fred>
145-
>>> b.fk_a
146-
<A02: foo>
147-
>>> C02.objects.filter(f_a=None)
148-
[]
149-
>>> C02.objects.filter(mm_a=a.id)
150-
[<C02: barney>]
151-
152-
"""}

tests/modeltests/unmanaged_models/tests.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
11
from django.test import TestCase
22
from django.db import connection
33
from models import Unmanaged1, Unmanaged2, Managed1
4+
from models import A01, A02, B01, B02, C01, C02
5+
6+
class SimpleTests(TestCase):
7+
8+
def test_simple(self):
9+
"""
10+
The main test here is that the all the models can be created without
11+
any database errors. We can also do some more simple insertion and
12+
lookup tests whilst we're here to show that the second of models do
13+
refer to the tables from the first set.
14+
"""
15+
# Insert some data into one set of models.
16+
a = A01.objects.create(f_a="foo", f_b=42)
17+
B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
18+
c = C01.objects.create(f_a="barney", f_b=1)
19+
c.mm_a = [a]
20+
21+
# ... and pull it out via the other set.
22+
a2 = A02.objects.all()[0]
23+
self.assertTrue(isinstance(a2, A02))
24+
self.assertEqual(a2.f_a, "foo")
25+
26+
b2 = B02.objects.all()[0]
27+
self.assertTrue(isinstance(b2, B02))
28+
self.assertEqual(b2.f_a, "fred")
29+
30+
self.assertTrue(isinstance(b2.fk_a, A02))
31+
self.assertEqual(b2.fk_a.f_a, "foo")
32+
33+
self.assertEqual(list(C02.objects.filter(f_a=None)), [])
34+
35+
resp = list(C02.objects.filter(mm_a=a.id))
36+
self.assertEqual(len(resp), 1)
37+
38+
self.assertTrue(isinstance(resp[0], C02))
39+
self.assertEqual(resp[0].f_a, 'barney')
40+
441

542
class ManyToManyUnmanagedTests(TestCase):
6-
43+
744
def test_many_to_many_between_unmanaged(self):
845
"""
946
The intermediary table between two unmanaged models should not be created.
1047
"""
1148
table = Unmanaged2._meta.get_field('mm').m2m_db_table()
1249
tables = connection.introspection.table_names()
1350
self.assert_(table not in tables, "Table '%s' should not exist, but it does." % table)
14-
51+
1552
def test_many_to_many_between_unmanaged_and_managed(self):
1653
"""
1754
An intermediary table between a managed and an unmanaged model should be created.
1855
"""
1956
table = Managed1._meta.get_field('mm').m2m_db_table()
2057
tables = connection.introspection.table_names()
2158
self.assert_(table in tables, "Table '%s' does not exist." % table)
22-

0 commit comments

Comments
 (0)