-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.2.X] Migrated m2m_intermediary doctests. Thanks to Alex Gaynor.
Backport of r13787 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13804 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
1 parent
42f7bbd
commit a4a19b8
Showing
3 changed files
with
43 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from datetime import datetime | ||
|
||
from django.test import TestCase | ||
|
||
from models import Reporter, Article, Writer | ||
|
||
|
||
class M2MIntermediaryTests(TestCase): | ||
def test_intermeiary(self): | ||
r1 = Reporter.objects.create(first_name="John", last_name="Smith") | ||
r2 = Reporter.objects.create(first_name="Jane", last_name="Doe") | ||
|
||
a = Article.objects.create( | ||
headline="This is a test", pub_date=datetime(2005, 7, 27) | ||
) | ||
|
||
w1 = Writer.objects.create(reporter=r1, article=a, position="Main writer") | ||
w2 = Writer.objects.create(reporter=r2, article=a, position="Contributor") | ||
|
||
self.assertQuerysetEqual( | ||
a.writer_set.select_related().order_by("-position"), [ | ||
("John Smith", "Main writer"), | ||
("Jane Doe", "Contributor"), | ||
], | ||
lambda w: (unicode(w.reporter), w.position) | ||
) | ||
self.assertEqual(w1.reporter, r1) | ||
self.assertEqual(w2.reporter, r2) | ||
|
||
self.assertEqual(w1.article, a) | ||
self.assertEqual(w2.article, a) | ||
|
||
self.assertQuerysetEqual( | ||
r1.writer_set.all(), [ | ||
("John Smith", "Main writer") | ||
], | ||
lambda w: (unicode(w.reporter), w.position) | ||
) |