__init__.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. """Unit test suite for the models of the application."""
  3. from nose.tools import eq_
  4. from pod.model import DBSession
  5. from pod.tests import load_app
  6. from pod.tests import setup_db, teardown_db
  7. __all__ = ['ModelTest']
  8. def setup():
  9. """Setup test fixture for all model tests."""
  10. load_app()
  11. setup_db()
  12. def teardown():
  13. """Tear down test fixture for all model tests."""
  14. teardown_db()
  15. class ModelTest(object):
  16. """Base unit test case for the models."""
  17. klass = None
  18. attrs = {}
  19. def setUp(self):
  20. """Setup test fixture for each model test method."""
  21. try:
  22. new_attrs = {}
  23. new_attrs.update(self.attrs)
  24. new_attrs.update(self.do_get_dependencies())
  25. self.obj = self.klass(**new_attrs)
  26. DBSession.add(self.obj)
  27. DBSession.flush()
  28. return self.obj
  29. except:
  30. DBSession.rollback()
  31. raise
  32. def tearDown(self):
  33. """Tear down test fixture for each model test method."""
  34. DBSession.rollback()
  35. def do_get_dependencies(self):
  36. """Get model test dependencies.
  37. Use this method to pull in other objects that need to be created
  38. for this object to be build properly.
  39. """
  40. return {}
  41. def test_create_obj(self):
  42. """Model objects can be created"""
  43. pass
  44. def test_query_obj(self):
  45. """Model objects can be queried"""
  46. obj = DBSession.query(self.klass).one()
  47. for key, value in self.attrs.items():
  48. eq_(getattr(obj, key), value)