hellocomputer/test/test_user.py

43 lines
1.1 KiB
Python
Raw Normal View History

2024-06-11 17:20:32 +02:00
from pathlib import Path
import hellocomputer
2024-07-26 11:59:13 +02:00
from hellocomputer.config import Settings, StorageEngines
2024-06-16 09:31:33 +02:00
from hellocomputer.db.users import OwnershipDB, UserDB
2024-06-11 17:20:32 +02:00
2024-07-25 00:10:09 +02:00
settings = Settings(
storage_engine=StorageEngines.local,
path=Path(hellocomputer.__file__).parents[2] / "test" / "output",
)
2024-06-11 17:20:32 +02:00
def test_create_user():
2024-07-25 00:10:09 +02:00
user = UserDB(settings)
2024-06-11 17:20:32 +02:00
user_data = {"name": "John Doe", "email": "[email protected]"}
user_data = user.dump_user_record(user_data, record_id="test")
assert user_data["name"] == "John Doe"
def test_user_exists():
2024-07-25 00:10:09 +02:00
user = UserDB(settings)
2024-06-11 17:20:32 +02:00
user_data = {"name": "John Doe", "email": "[email protected]"}
user.dump_user_record(user_data, record_id="test")
assert user.user_exists("[email protected]")
assert not user.user_exists("notpresent")
2024-06-11 18:54:10 +02:00
def test_assign_owner():
assert (
2024-07-25 00:10:09 +02:00
OwnershipDB(settings).set_ownersip(
2024-06-12 11:04:28 +02:00
"something.something@something", "testsession", "test"
2024-06-11 18:54:10 +02:00
)
2024-06-12 11:04:28 +02:00
== "testsession"
2024-06-11 18:54:10 +02:00
)
2024-06-12 11:04:28 +02:00
def test_get_sessions():
2024-07-25 00:10:09 +02:00
assert OwnershipDB(settings).sessions("something.something@something") == [
"testsession"
]