2025-09-24 01:28:23 -07:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
import ttfrog.app
|
|
|
|
from ttfrog import schema
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2025-09-25 22:31:37 -07:00
|
|
|
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)
|