PageRenderTime 22ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modeltests/m2m_intermediary/tests.py

https://code.google.com/p/mango-py/
Python | 38 lines | 29 code | 9 blank | 0 comment | 0 complexity | 35646c459ce7c3d03adf66d2cda002b1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from datetime import datetime
  2. from django.test import TestCase
  3. from models import Reporter, Article, Writer
  4. class M2MIntermediaryTests(TestCase):
  5. def test_intermeiary(self):
  6. r1 = Reporter.objects.create(first_name="John", last_name="Smith")
  7. r2 = Reporter.objects.create(first_name="Jane", last_name="Doe")
  8. a = Article.objects.create(
  9. headline="This is a test", pub_date=datetime(2005, 7, 27)
  10. )
  11. w1 = Writer.objects.create(reporter=r1, article=a, position="Main writer")
  12. w2 = Writer.objects.create(reporter=r2, article=a, position="Contributor")
  13. self.assertQuerysetEqual(
  14. a.writer_set.select_related().order_by("-position"), [
  15. ("John Smith", "Main writer"),
  16. ("Jane Doe", "Contributor"),
  17. ],
  18. lambda w: (unicode(w.reporter), w.position)
  19. )
  20. self.assertEqual(w1.reporter, r1)
  21. self.assertEqual(w2.reporter, r2)
  22. self.assertEqual(w1.article, a)
  23. self.assertEqual(w2.article, a)
  24. self.assertQuerysetEqual(
  25. r1.writer_set.all(), [
  26. ("John Smith", "Main writer")
  27. ],
  28. lambda w: (unicode(w.reporter), w.position)
  29. )