refactor: sweep the platform-and-sign-in epic
Split load_config into per-section readers, use contextlib.suppress and a single condition where ruff asked, remove stale noqa comments, add the SIM and RUF100 rules, share the sign_in test helper, align AD-6 with the code and record the remaining deferred findings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N3t4WL7bd9bdHHNjEsxzqC
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"""Shared test helpers."""
|
||||
|
||||
from django.test import Client
|
||||
|
||||
from portal.accounts.session_store import LOGIN_FLOW
|
||||
from portal.adapters.idp import Flow
|
||||
|
||||
|
||||
def sign_in(adapters, username="alice", next_path=None, client=None):
|
||||
"""Run the whole flow with the fake provider; returns (client, callback response)."""
|
||||
client = client or Client()
|
||||
adapters.idp.sign_in_as(username)
|
||||
query = f"?next={next_path}" if next_path else ""
|
||||
client.get("/auth/login" + query)
|
||||
flow = Flow.from_dict(client.session[LOGIN_FLOW])
|
||||
return client, client.get("/auth/callback", adapters.idp.callback_params(flow))
|
||||
@@ -7,27 +7,27 @@ class LDAPError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SERVER_DOWN(LDAPError): # noqa: N801
|
||||
class SERVER_DOWN(LDAPError):
|
||||
pass
|
||||
|
||||
|
||||
class INVALID_CREDENTIALS(LDAPError): # noqa: N801
|
||||
class INVALID_CREDENTIALS(LDAPError):
|
||||
pass
|
||||
|
||||
|
||||
class INSUFFICIENT_ACCESS(LDAPError): # noqa: N801
|
||||
class INSUFFICIENT_ACCESS(LDAPError):
|
||||
pass
|
||||
|
||||
|
||||
class CONSTRAINT_VIOLATION(LDAPError): # noqa: N801
|
||||
class CONSTRAINT_VIOLATION(LDAPError):
|
||||
pass
|
||||
|
||||
|
||||
class UNWILLING_TO_PERFORM(LDAPError): # noqa: N801
|
||||
class UNWILLING_TO_PERFORM(LDAPError):
|
||||
pass
|
||||
|
||||
|
||||
class INVALID_SYNTAX(LDAPError): # noqa: N801
|
||||
class INVALID_SYNTAX(LDAPError):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ def test_process_exits_nonzero_naming_both_variables(tmp_path):
|
||||
LOG_LEVEL="loud",
|
||||
DJANGO_SETTINGS_MODULE="portal.config.settings",
|
||||
)
|
||||
result = subprocess.run( # noqa: S603
|
||||
result = subprocess.run(
|
||||
[sys.executable, "manage.py", "check"],
|
||||
cwd=ROOT,
|
||||
env=env,
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
from django.test import Client
|
||||
from django.utils import translation
|
||||
|
||||
from portal.tests.test_signin import sign_in
|
||||
from portal.tests.helpers import sign_in
|
||||
|
||||
pytestmark = pytest.mark.django_db(transaction=True)
|
||||
|
||||
|
||||
@@ -14,20 +14,11 @@ from portal.accounts.session_store import LOGIN_FLOW, ROLES
|
||||
from portal.accounts.sessions import SessionUser
|
||||
from portal.adapters.idp import Flow
|
||||
from portal.audit.models import AuditEntry
|
||||
from portal.tests.helpers import sign_in
|
||||
|
||||
pytestmark = pytest.mark.django_db(transaction=True)
|
||||
|
||||
|
||||
def sign_in(adapters, username="alice", next_path=None, client=None):
|
||||
"""Run the whole flow with the fake provider; returns (client, callback response)."""
|
||||
client = client or Client()
|
||||
adapters.idp.sign_in_as(username)
|
||||
query = f"?next={next_path}" if next_path else ""
|
||||
client.get("/auth/login" + query)
|
||||
flow = Flow.from_dict(client.session[LOGIN_FLOW])
|
||||
return client, client.get("/auth/callback", adapters.idp.callback_params(flow))
|
||||
|
||||
|
||||
def age_the_cache(client):
|
||||
session = client.session
|
||||
session[ROLES] = {**session[ROLES], "checked": time.time() - 3600}
|
||||
|
||||
@@ -67,10 +67,10 @@ class FakeSmtpModule:
|
||||
|
||||
return Connection()
|
||||
|
||||
def SMTP(self, *args, **kwargs): # noqa: N802
|
||||
def SMTP(self, *args, **kwargs):
|
||||
return self._connection("SMTP", args, kwargs)
|
||||
|
||||
def SMTP_SSL(self, *args, **kwargs): # noqa: N802
|
||||
def SMTP_SSL(self, *args, **kwargs):
|
||||
return self._connection("SMTP_SSL", args, kwargs)
|
||||
|
||||
def names(self):
|
||||
|
||||
Reference in New Issue
Block a user