# HG changeset patch # User RhodeCode Admin # Date 2024-04-25 09:40:13 # Node ID b5200639d0cd4b4a28af9292a208f8bf4c3d8dd8 # Parent 1ab522cfae1fdcd304b39cb1481c9a8b5f72165c fix(2fa): fixed tests to use mock instead of global value which causes some other tests to fail diff --git a/rhodecode/apps/login/tests/test_2fa.py b/rhodecode/apps/login/tests/test_2fa.py --- a/rhodecode/apps/login/tests/test_2fa.py +++ b/rhodecode/apps/login/tests/test_2fa.py @@ -1,5 +1,7 @@ import pytest +import mock +from rhodecode.lib.type_utils import AttributeDict from rhodecode.model.meta import Session from rhodecode.tests.fixture import Fixture from rhodecode.tests.routes import route_path @@ -14,10 +16,6 @@ class Test2FA(object): def setup_class(cls): cls.password = 'valid-one' - @classmethod - def teardown_class(cls): - SettingsModel().create_or_update_setting('auth_rhodecode_global_2fa', False) - def test_redirect_to_2fa_setup_if_enabled_for_user(self, user_util): user = user_util.create_user(password=self.password) user.has_enabled_2fa = True @@ -63,5 +61,7 @@ class Test2FA(object): def test_2fa_state_when_forced_by_admin(self, user_util): user = user_util.create_user(password=self.password) user.has_enabled_2fa = False - SettingsModel().create_or_update_setting('auth_rhodecode_global_2fa', True) - assert user.has_enabled_2fa + with mock.patch.object( + SettingsModel, 'get_setting_by_name', lambda *a, **kw: AttributeDict(app_settings_value=True)): + + assert user.has_enabled_2fa