__init__.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. """Unit and functional test suite for pod."""
  3. from os import getcwd, path
  4. from paste.deploy import loadapp
  5. from webtest import TestApp
  6. from gearbox.commands.setup_app import SetupAppCommand
  7. from tg import config
  8. from tg.util import Bunch
  9. from pod import model
  10. __all__ = ['setup_app', 'setup_db', 'teardown_db', 'TestController']
  11. application_name = 'main_without_authn'
  12. def load_app(name=application_name):
  13. """Load the test application."""
  14. return TestApp(loadapp('config:test.ini#%s' % name, relative_to=getcwd()))
  15. def setup_app():
  16. """Setup the application."""
  17. cmd = SetupAppCommand(Bunch(options=Bunch(verbose_level=1)), Bunch())
  18. cmd.run(Bunch(config_file='config:test.ini', section_name=None))
  19. def setup_db():
  20. """Create the database schema (not needed when you run setup_app)."""
  21. engine = config['tg.app_globals'].sa_engine
  22. model.init_model(engine)
  23. model.metadata.create_all(engine)
  24. def teardown_db():
  25. """Destroy the database schema."""
  26. engine = config['tg.app_globals'].sa_engine
  27. model.metadata.drop_all(engine)
  28. class TestController(object):
  29. """Base functional test case for the controllers.
  30. The pod application instance (``self.app``) set up in this test
  31. case (and descendants) has authentication disabled, so that developers can
  32. test the protected areas independently of the :mod:`repoze.who` plugins
  33. used initially. This way, authentication can be tested once and separately.
  34. Check pod.tests.functional.test_authentication for the repoze.who
  35. integration tests.
  36. This is the officially supported way to test protected areas with
  37. repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/).
  38. """
  39. application_under_test = application_name
  40. def setUp(self):
  41. """Setup test fixture for each functional test method."""
  42. self.app = load_app(self.application_under_test)
  43. setup_app()
  44. def tearDown(self):
  45. """Tear down test fixture for each functional test method."""
  46. model.DBSession.remove()
  47. teardown_db()