PageRenderTime 29ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/test_utils/tests_25.py

https://code.google.com/p/mango-py/
Python | 41 lines | 29 code | 12 blank | 0 comment | 10 complexity | c3b06b1bd875e33a90a0afecb9179832 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from __future__ import with_statement
  2. from django.test import TestCase
  3. from models import Person
  4. class AssertNumQueriesContextManagerTests(TestCase):
  5. def test_simple(self):
  6. with self.assertNumQueries(0):
  7. pass
  8. with self.assertNumQueries(1):
  9. Person.objects.count()
  10. with self.assertNumQueries(2):
  11. Person.objects.count()
  12. Person.objects.count()
  13. def test_failure(self):
  14. with self.assertRaises(AssertionError) as exc_info:
  15. with self.assertNumQueries(2):
  16. Person.objects.count()
  17. self.assertIn("1 queries executed, 2 expected", str(exc_info.exception))
  18. with self.assertRaises(TypeError):
  19. with self.assertNumQueries(4000):
  20. raise TypeError
  21. def test_with_client(self):
  22. person = Person.objects.create(name="test")
  23. with self.assertNumQueries(1):
  24. self.client.get("/test_utils/get_person/%s/" % person.pk)
  25. with self.assertNumQueries(1):
  26. self.client.get("/test_utils/get_person/%s/" % person.pk)
  27. with self.assertNumQueries(2):
  28. self.client.get("/test_utils/get_person/%s/" % person.pk)
  29. self.client.get("/test_utils/get_person/%s/" % person.pk)