2023-05-13 22:58:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from datetime import timedelta
|
2023-07-08 22:47:12 +00:00
|
|
|
import logging
|
2023-05-13 22:58:17 +00:00
|
|
|
|
|
|
|
import pytest
|
2023-06-03 21:09:50 +00:00
|
|
|
from tentacles.db import Db
|
2023-05-13 22:58:17 +00:00
|
|
|
|
2023-07-08 22:47:12 +00:00
|
|
|
# FIXME: Should this be an autouse fixture? Maybe. Doesn't buy much tho.
|
|
|
|
logging.addLevelName(logging.DEBUG - 5, "TRACE")
|
|
|
|
logging.TRACE = logging.DEBUG - 5
|
2023-05-13 22:58:17 +00:00
|
|
|
|
2023-07-08 22:47:12 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
2023-06-03 21:09:50 +00:00
|
|
|
def db():
|
|
|
|
conn = Db(":memory:")
|
2023-05-13 22:58:17 +00:00
|
|
|
conn.connect()
|
2023-07-08 22:47:12 +00:00
|
|
|
conn.migrate()
|
2023-05-13 22:58:17 +00:00
|
|
|
yield conn
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def username_testy():
|
|
|
|
return "testy@test.com"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def password_testy():
|
|
|
|
return "testpw"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-07-08 22:47:12 +00:00
|
|
|
def uid_testy(db: Db, username_testy, password_testy) -> int:
|
|
|
|
return db.try_create_user(
|
|
|
|
username=username_testy,
|
|
|
|
email=username_testy,
|
|
|
|
password=password_testy,
|
|
|
|
sid=1,
|
|
|
|
gid=0, # Note: to bypass the approve/enable machinery
|
|
|
|
).id
|
2023-05-13 22:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-07-08 22:47:12 +00:00
|
|
|
def login_ttl() -> timedelta:
|
2023-05-13 22:58:17 +00:00
|
|
|
return timedelta(hours=12)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-06-03 21:09:50 +00:00
|
|
|
def sid_testy(db: Db, uid_testy, username_testy, password_testy, login_ttl):
|
2023-07-08 22:47:12 +00:00
|
|
|
res = db.try_login(username=username_testy, password=password_testy, ttl=login_ttl)
|
|
|
|
assert res.user_id == uid_testy
|
|
|
|
return res.id
|