Skip to content

Commit d25515e

Browse files
committed
Isolate test that does reload to fix cross-talk failure
1 parent e08cc74 commit d25515e

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

ansible_base/authentication/authenticator_plugins/ldap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def validate(self, attrs):
363363
class LDAPSettings(BaseLDAPSettings):
364364
def __init__(self, prefix: str = 'AUTH_LDAP_', defaults: dict = {}):
365365
# This init method double checks the passed defaults while initializing a settings objects
366-
super(LDAPSettings, self).__init__(prefix, defaults)
366+
super().__init__(prefix, defaults)
367367

368368
# SERVER_URI needs to be a string, not an array
369369
setattr(self, 'SERVER_URI', ','.join(defaults['SERVER_URI']))

test_app/tests/authentication/authenticator_plugins/test_ldap.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import importlib
21
from collections import OrderedDict
32
from unittest import mock
43
from unittest.mock import MagicMock
@@ -680,27 +679,3 @@ def test_ldap_user_search_validation(
680679
)
681680
def test_ldap_search_field_is_single_search(value, expected_result):
682681
assert LDAPSearchField.is_single_search(value) is expected_result
683-
684-
685-
@pytest.mark.django_db
686-
@pytest.mark.parametrize(
687-
"username",
688-
[
689-
("Timmy"),
690-
("TIMMY"),
691-
("TiMmY"),
692-
],
693-
)
694-
def test_get_or_build_user(username, ldap_authenticator):
695-
from ansible_base.authentication.authenticator_plugins import ldap
696-
697-
with mock.patch(
698-
'ansible_base.authentication.utils.authentication.get_or_create_authenticator_user', return_value=(None, None, None)
699-
) as get_or_create_authenticator_user:
700-
importlib.reload(ldap)
701-
plugin = AuthenticatorPlugin(database_instance=ldap_authenticator)
702-
ldap_object = MagicMock()
703-
plugin.get_or_build_user(username, ldap_object)
704-
assert get_or_create_authenticator_user.called
705-
assert username.lower() in get_or_create_authenticator_user.call_args[0]
706-
assert username not in get_or_create_authenticator_user.call_args[0]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import importlib
2+
from unittest import mock
3+
from unittest.mock import MagicMock
4+
5+
import pytest
6+
7+
from ansible_base.authentication.authenticator_plugins import ldap
8+
9+
10+
@pytest.mark.django_db
11+
@pytest.mark.parametrize(
12+
"username",
13+
[
14+
("Timmy"),
15+
("TIMMY"),
16+
("TiMmY"),
17+
],
18+
)
19+
def test_get_or_build_user(username, ldap_authenticator):
20+
with mock.patch(
21+
'ansible_base.authentication.utils.authentication.get_or_create_authenticator_user', return_value=(None, None, None)
22+
) as get_or_create_authenticator_user:
23+
importlib.reload(ldap)
24+
plugin = ldap.AuthenticatorPlugin(database_instance=ldap_authenticator)
25+
ldap_object = MagicMock()
26+
plugin.get_or_build_user(username, ldap_object)
27+
assert get_or_create_authenticator_user.called
28+
assert username.lower() in get_or_create_authenticator_user.call_args[0]
29+
assert username not in get_or_create_authenticator_user.call_args[0]

0 commit comments

Comments
 (0)