source/projects/tentacles/test/python/test_store_users.py
2023-06-03 13:20:43 -06:00

56 lines
1.6 KiB
Python

#!/usr/bin/env python3
from tentacles.store import Store
def test_store_initializes(store: Store):
assert isinstance(store, Store)
def test_store_savepoint(store: Store):
obj = store.savepoint()
assert hasattr(obj, "__enter__")
assert hasattr(obj, "__exit__")
flag = False
with obj:
flag = True
assert flag
def test_mkuser(store: Store, username_testy, password_testy):
res = store.try_create_user(
username=username_testy, email=username_testy, password=password_testy
)
assert res
assert store.list_users() == [(res.id, username_testy)]
def test_mksession(store: Store, uid_testy, username_testy, password_testy, login_ttl):
res = store.try_login(
username=username_testy, password=password_testy, ttl=login_ttl
)
assert res is not None
assert [it.id for it in store.list_keys(uid=uid_testy)] == [res.id]
assert store.try_key(kid=res.id).user_id == uid_testy
def test_refresh_key(store: Store, sid_testy, login_ttl):
before = store.fetch_key(kid=sid_testy)
store.refresh_key(kid=sid_testy, ttl=login_ttl * 2)
after = store.fetch_key(kid=sid_testy)
assert before != after
def tets_mkkey(store: Store, sid_testy, uid_testy):
assert store.try_key(kid=sid_testy) == uid_testy
new_key = store.create_key(kid=sid_testy, ttl=None)
assert new_key is not None
assert store.try_key(kid=new_key) == uid_testy
def test_logout(store: Store, uid_testy, sid_testy):
assert store.try_key(kid=sid_testy)
store.delete_key(uid=uid_testy, kid=sid_testy)
assert not store.try_key(kid=sid_testy)