PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modeltests/fixtures_model_package/tests.py

https://code.google.com/p/mango-py/
Python | 71 lines | 57 code | 9 blank | 5 comment | 0 complexity | 29b789279e038eb7191e0b1c5d0375fb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.core import management
  2. from django.test import TestCase
  3. from models import Article
  4. class SampleTestCase(TestCase):
  5. fixtures = ['fixture1.json', 'fixture2.json']
  6. def testClassFixtures(self):
  7. "Test cases can load fixture objects into models defined in packages"
  8. self.assertEqual(Article.objects.count(), 4)
  9. self.assertQuerysetEqual(
  10. Article.objects.all(),[
  11. "Django conquers world!",
  12. "Copyright is fine the way it is",
  13. "Poker has no place on ESPN",
  14. "Python program becomes self aware"
  15. ],
  16. lambda a: a.headline
  17. )
  18. class FixtureTestCase(TestCase):
  19. def test_initial_data(self):
  20. "Fixtures can load initial data into models defined in packages"
  21. #Syncdb introduces 1 initial data object from initial_data.json
  22. self.assertQuerysetEqual(
  23. Article.objects.all(), [
  24. "Python program becomes self aware"
  25. ],
  26. lambda a: a.headline
  27. )
  28. def test_loaddata(self):
  29. "Fixtures can load data into models defined in packages"
  30. # Load fixture 1. Single JSON file, with two objects
  31. management.call_command("loaddata", "fixture1.json", verbosity=0, commit=False)
  32. self.assertQuerysetEqual(
  33. Article.objects.all(), [
  34. "Time to reform copyright",
  35. "Poker has no place on ESPN",
  36. "Python program becomes self aware",
  37. ],
  38. lambda a: a.headline,
  39. )
  40. # Load fixture 2. JSON file imported by default. Overwrites some
  41. # existing objects
  42. management.call_command("loaddata", "fixture2.json", verbosity=0, commit=False)
  43. self.assertQuerysetEqual(
  44. Article.objects.all(), [
  45. "Django conquers world!",
  46. "Copyright is fine the way it is",
  47. "Poker has no place on ESPN",
  48. "Python program becomes self aware",
  49. ],
  50. lambda a: a.headline,
  51. )
  52. # Load a fixture that doesn't exist
  53. management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
  54. self.assertQuerysetEqual(
  55. Article.objects.all(), [
  56. "Django conquers world!",
  57. "Copyright is fine the way it is",
  58. "Poker has no place on ESPN",
  59. "Python program becomes self aware",
  60. ],
  61. lambda a: a.headline,
  62. )