app.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pytest
  2. from flaskbb import create_app
  3. from flaskbb.configs.testing import TestingConfig as Config
  4. from flaskbb.extensions import db
  5. from flaskbb.utils.populate import create_default_groups, create_default_settings
  6. @pytest.yield_fixture(autouse=True)
  7. def application():
  8. """application with context."""
  9. app = create_app(Config)
  10. ctx = app.app_context()
  11. ctx.push()
  12. yield app
  13. ctx.pop()
  14. @pytest.yield_fixture()
  15. def request_context(application):
  16. with application.test_request_context():
  17. yield
  18. @pytest.fixture()
  19. def post_request_context(application):
  20. with application.test_request_context(method="POST"):
  21. yield
  22. @pytest.fixture()
  23. def default_groups(database):
  24. """Creates the default groups"""
  25. return create_default_groups()
  26. @pytest.fixture()
  27. def default_settings(database):
  28. """Creates the default settings"""
  29. return create_default_settings()
  30. @pytest.yield_fixture()
  31. def database():
  32. """database setup."""
  33. db.create_all() # Maybe use migration instead?
  34. yield db
  35. db.drop_all()