"""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))