manager_case.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. from django.test import TestCase
  2. import iepy
  3. from django.test.runner import DiscoverRunner
  4. class ManagerTestCase(TestCase):
  5. """
  6. TestCase class that clear the makes sure that the models created thru
  7. ORM are deleted between tests
  8. """
  9. # We are doing something not very clever, but fast enough (of coding):
  10. # Emulate the django test runner. The downside is that all the environment
  11. # and database stuff is setup once per TestCase (instead as it should, once
  12. # per run)
  13. @classmethod
  14. def setUpClass(cls):
  15. # ORM environment and database setup
  16. iepy.setup()
  17. cls.dj_runner = DiscoverRunner()
  18. cls.dj_runner.setup_test_environment()
  19. cls.old_config = cls.dj_runner.setup_databases()
  20. # Creating Manager instance (if requested)
  21. if hasattr(cls, 'ManagerClass'):
  22. cls.manager = cls.ManagerClass()
  23. @classmethod
  24. def tearDownClass(cls):
  25. cls.dj_runner.teardown_databases(cls.old_config)
  26. cls.dj_runner.teardown_test_environment()