50 lines
972 B
Python
50 lines
972 B
Python
#!/usr/bin/env python3
|
|
|
|
from datetime import timedelta
|
|
|
|
import pytest
|
|
from tentacles.db import Db
|
|
|
|
|
|
@pytest.yield_fixture
|
|
def db():
|
|
conn = Db(":memory:")
|
|
conn.connect()
|
|
yield conn
|
|
conn.close()
|
|
|
|
|
|
@pytest.fixture
|
|
def username_testy():
|
|
return "testy@test.com"
|
|
|
|
|
|
@pytest.fixture
|
|
def password_testy():
|
|
return "testpw"
|
|
|
|
|
|
@pytest.fixture
|
|
def uid_testy(db: Db, username_testy, password_testy):
|
|
with db.savepoint():
|
|
return db.try_create_user(
|
|
username=username_testy,
|
|
email=username_testy,
|
|
password=password_testy,
|
|
sid=1,
|
|
).id
|
|
|
|
|
|
@pytest.fixture
|
|
def login_ttl():
|
|
return timedelta(hours=12)
|
|
|
|
|
|
@pytest.fixture
|
|
def sid_testy(db: Db, uid_testy, username_testy, password_testy, login_ttl):
|
|
with db.savepoint():
|
|
res = db.try_login(
|
|
username=username_testy, password=password_testy, ttl=login_ttl
|
|
)
|
|
assert res.user_id == uid_testy
|
|
return res.id
|