test_auth_views.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from flask_login import login_user
  2. from flaskbb.management import views
  3. from flaskbb.exceptions import AuthorizationRequired
  4. import pytest
  5. def test_overview_not_authorized(application, default_settings):
  6. view = views.ManagementOverview.as_view('overview')
  7. with application.test_request_context(), pytest.raises(AuthorizationRequired) as excinfo: # noqa
  8. view()
  9. assert "Authorization is required to access this area." == excinfo.value.description # noqa
  10. def test_overview_with_authorized(admin_user, application, default_settings):
  11. view = views.ManagementOverview.as_view('overview')
  12. with application.test_request_context():
  13. login_user(admin_user)
  14. resp = view()
  15. assert 'Overview' in resp
  16. def test_overview_with_supermod(super_moderator_user, application, default_settings): # noqa
  17. view = views.ManagementOverview.as_view('overview')
  18. with application.test_request_context():
  19. login_user(super_moderator_user)
  20. resp = view()
  21. assert 'Overview' in resp
  22. def test_overview_with_mod(moderator_user, application, default_settings):
  23. view = views.ManagementOverview.as_view('overview')
  24. with application.test_request_context():
  25. login_user(moderator_user)
  26. resp = view()
  27. assert 'Overview' in resp