import pytest import ttfrog.app from ttfrog import schema @pytest.fixture def app(monkeypatch): monkeypatch.setenv("TTFROG_IN_MEMORY_DB", "1") ttfrog.app.initialize() 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 players = schema.Group(name="players", users=[john_something]) players = app.db.save(players) players.users[0]["name"] = "fnord" app.db.save(players)