app.py 946 B

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