vtt/test/test_db.py

41 lines
1.1 KiB
Python
Raw Normal View History

2025-09-24 01:28:23 -07:00
import pytest
import ttfrog.app
from ttfrog import schema
@pytest.fixture
def app():
ttfrog.app.load_config(defaults=None, IN_MEMORY_DB=1)
2025-09-24 22:03:30 -07:00
ttfrog.app.initialize()
2025-09-24 01:28:23 -07:00
yield ttfrog.app
ttfrog.app.db.close()
def test_create(app):
user = schema.User(name="john", email="john@foo")
assert user.uid
assert user._metadata.fields["uid"].unique
# insert
john_something = app.db.save(user)
last_insert_id = john_something.doc_id
# read back
assert app.db.User.get(doc_id=last_insert_id) == john_something
assert john_something.name == user.name
assert john_something.email == user.email
assert john_something.uid == user.uid
# update
john_something.name = "james?"
before_update = app.db.User.get(doc_id=john_something.doc_id)
after_update = app.db.save(john_something)
assert after_update == john_something
assert before_update != after_update
2025-09-24 22:03:30 -07:00
players = schema.Group(name="players", users=[john_something])
players = app.db.save(players)
players.users[0]["name"] = "fnord"
app.db.save(players)