Skip to content

Commit 6e5426e

Browse files
committed
fix: linting issues
Signed-off-by: Nicolas <32845761+nicoklaus@users.noreply.github.com>
1 parent dab3dba commit 6e5426e

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

dejacode/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import ldap
1818
from django_auth_ldap.config import GroupOfNamesType
1919
from django_auth_ldap.config import LDAPSearch
20+
2021
from dejacode_toolkit.ldap import build_user_search
2122

2223
# The home directory of the dejacode user that owns the installation.

dejacode_toolkit/ldap.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
import json
1010

11-
import ldap
1211
from django.core.exceptions import ImproperlyConfigured
12+
13+
import ldap
1314
from django_auth_ldap.config import LDAPSearch
1415
from django_auth_ldap.config import LDAPSearchUnion
1516

1617

1718
def build_user_search(user_searches, user_dn, user_filterstr):
18-
"""Return the ``AUTH_LDAP_USER_SEARCH`` object.
19+
"""
20+
Return the ``AUTH_LDAP_USER_SEARCH`` object.
1921
2022
When ``user_searches`` (a raw JSON string) is provided, parse and validate
2123
it and return an ``LDAPSearchUnion``. Otherwise, fall back to a single
@@ -27,9 +29,7 @@ def build_user_search(user_searches, user_dn, user_filterstr):
2729
try:
2830
definitions = json.loads(user_searches)
2931
except json.JSONDecodeError as e:
30-
raise ImproperlyConfigured(
31-
f"Invalid JSON in AUTH_LDAP_USER_SEARCHES: {e}"
32-
) from e
32+
raise ImproperlyConfigured(f"Invalid JSON in AUTH_LDAP_USER_SEARCHES: {e}") from e
3333

3434
if not isinstance(definitions, list):
3535
raise ImproperlyConfigured("AUTH_LDAP_USER_SEARCHES must be a JSON list")
@@ -40,9 +40,7 @@ def build_user_search(user_searches, user_dn, user_filterstr):
4040
searches = []
4141
for index, entry in enumerate(definitions):
4242
if not isinstance(entry, dict):
43-
raise ImproperlyConfigured(
44-
f"AUTH_LDAP_USER_SEARCHES[{index}] must be a JSON object"
45-
)
43+
raise ImproperlyConfigured(f"AUTH_LDAP_USER_SEARCHES[{index}] must be a JSON object")
4644

4745
base_dn = entry.get("base")
4846
filterstr = entry.get("filter")

dje/tests/test_ldap_config.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django_auth_ldap.config import LDAPSearch
1313
from django_auth_ldap.config import LDAPSearchUnion
1414

15-
from dejacode.ldap_config import build_user_search
15+
from dejacode_toolkit.ldap import build_user_search
1616

1717

1818
class BuildUserSearchTestCase(SimpleTestCase):
@@ -51,24 +51,18 @@ def test_build_user_search_entry_not_object_raises(self):
5151

5252
def test_build_user_search_missing_base_raises(self):
5353
raw = '[{"filter": "(uid=%(user)s)"}]'
54-
with self.assertRaisesMessage(
55-
ImproperlyConfigured, "[0] must define 'base' and 'filter'"
56-
):
54+
with self.assertRaisesMessage(ImproperlyConfigured, "[0] must define 'base' and 'filter'"):
5755
build_user_search(raw, "", "")
5856

5957
def test_build_user_search_missing_filter_raises(self):
6058
raw = '[{"base": "ou=a,dc=example,dc=com"}]'
61-
with self.assertRaisesMessage(
62-
ImproperlyConfigured, "[0] must define 'base' and 'filter'"
63-
):
59+
with self.assertRaisesMessage(ImproperlyConfigured, "[0] must define 'base' and 'filter'"):
6460
build_user_search(raw, "", "")
6561

6662
def test_build_user_search_error_index_points_to_bad_entry(self):
6763
raw = (
6864
'[{"base": "ou=a,dc=example,dc=com", "filter": "(uid=%(user)s)"},'
6965
' {"base": "ou=b,dc=example,dc=com"}]'
7066
)
71-
with self.assertRaisesMessage(
72-
ImproperlyConfigured, "[1] must define 'base' and 'filter'"
73-
):
67+
with self.assertRaisesMessage(ImproperlyConfigured, "[1] must define 'base' and 'filter'"):
7468
build_user_search(raw, "", "")

0 commit comments

Comments
 (0)