Skip to content

Commit

Permalink
Fix import in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavid committed Jan 30, 2025
1 parent 2eab688 commit daff7de
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions caterva2/tests/sub_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@
import httpx
import pytest

from caterva2.utils import add_user
from caterva2.services import srv_utils


def sub_auth_enabled():
return bool(os.environ.get('CATERVA2_SECRET'))
return bool(os.environ.get("CATERVA2_SECRET"))


def make_sub_user(services):
if not sub_auth_enabled():
return None

state_dir = services.state_dir / 'subscriber'
return add_user('user@example.com', password='foobar11', is_superuser=True,
state_dir=state_dir)
state_dir = services.state_dir / "subscriber"
return srv_utils.add_user(
"user@example.com", password="foobar11", is_superuser=True, state_dir=state_dir
)


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def sub_user(services):
# TODO: This does not work with external services,
# as their state directory is unknown.
# One would need to register a new user via the API there.
return make_sub_user(services)


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def sub_jwt_cookie(sub_user, services):
if not sub_user:
return None

username, password = sub_user
urlbase = services.get_urlbase('subscriber')
urlbase = services.get_urlbase("subscriber")

resp = httpx.post(f'{urlbase}/auth/jwt/login',
data={'username': username, 'password': password})
resp = httpx.post(f"{urlbase}/auth/jwt/login", data={"username": username, "password": password})
resp.raise_for_status()
return '='.join(list(resp.cookies.items())[0])
return "=".join(list(resp.cookies.items())[0])

0 comments on commit daff7de

Please sign in to comment.