| |
@@ -0,0 +1,51 @@
|
| |
+ """Test blockerbugs/util/login.py"""
|
| |
+
|
| |
+ import pytest
|
| |
+ import mock
|
| |
+ import flask_fas_openid
|
| |
+
|
| |
+ from blockerbugs.util import login
|
| |
+ from blockerbugs import app
|
| |
+
|
| |
+
|
| |
+ @pytest.fixture(autouse=True)
|
| |
+ def reset_fas(monkeypatch):
|
| |
+ """Reset login._fas to None for all tests, so that they can test its initialization. Also, it is
|
| |
+ a global variable, we don't want to change the real value, it could affect other test modules.
|
| |
+ """
|
| |
+ monkeypatch.setattr(login, '_fas', None)
|
| |
+
|
| |
+
|
| |
+ @pytest.fixture(autouse=True)
|
| |
+ def avoid_flask_setup(monkeypatch):
|
| |
+ """Flask aborts, if a setup method is called after it already handled some requests (which it
|
| |
+ already did in other test modules). We must avoid calling such setup methods.
|
| |
+ """
|
| |
+ monkeypatch.setattr(app, 'before_request', mock.MagicMock())
|
| |
+ monkeypatch.setattr(app, 'add_url_rule', mock.MagicMock())
|
| |
+
|
| |
+
|
| |
+ class TestLogin:
|
| |
+ def test_default_fakefas(self):
|
| |
+ """During a test suite run, FakeFAS should be used by default"""
|
| |
+ assert isinstance(login.getFAS(), login.FakeFAS)
|
| |
+
|
| |
+ def test_singleton(self):
|
| |
+ """A singleton _fas should not be overwritten with subsequent calls"""
|
| |
+ fas = login.getFAS()
|
| |
+ assert fas is login._fas
|
| |
+ fas2 = login.getFAS()
|
| |
+ assert fas is fas2 is login._fas
|
| |
+
|
| |
+ def test_config_fas_enabled(self, monkeypatch):
|
| |
+ """Config option FAS_ENABLED should affect the returned object"""
|
| |
+ monkeypatch.setitem(app.config, 'FAS_ENABLED', False)
|
| |
+ assert isinstance(login.getFAS(), login.FakeFAS)
|
| |
+
|
| |
+ login._fas = None
|
| |
+ monkeypatch.setitem(app.config, 'FAS_ENABLED', '')
|
| |
+ assert isinstance(login.getFAS(), login.FakeFAS)
|
| |
+
|
| |
+ login._fas = None
|
| |
+ monkeypatch.setitem(app.config, 'FAS_ENABLED', True)
|
| |
+ assert isinstance(login.getFAS(), flask_fas_openid.FAS)
|
| |
This allows to either use FAS or FakeFAS with a configuration change,
independently on the deployment type. This means we no longer need to use
TESTING=True
on our staging instance.Fixes: https://pagure.io/fedora-qa/blockerbugs/issue/182