From 8a4d6662489f5633e74caad281c135ee4bad0642 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 4 May 2021 23:05:14 -0700 Subject: [PATCH] Add basic database test --- tests/test_amanuensis.py | 5 ----- tests/test_db.py | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) delete mode 100644 tests/test_amanuensis.py create mode 100644 tests/test_db.py diff --git a/tests/test_amanuensis.py b/tests/test_amanuensis.py deleted file mode 100644 index 8776152..0000000 --- a/tests/test_amanuensis.py +++ /dev/null @@ -1,5 +0,0 @@ -from amanuensis import __version__ - - -def test_version(): - assert __version__ == '0.1.0' diff --git a/tests/test_db.py b/tests/test_db.py new file mode 100644 index 0000000..052956b --- /dev/null +++ b/tests/test_db.py @@ -0,0 +1,25 @@ +import pytest +from sqlalchemy import func + +from amanuensis.database import DbContext +from amanuensis.models import * + + +@pytest.fixture +def session(): + db = DbContext('sqlite:///:memory:', debug=True) + db.create_all() + return db.session + + +def test_create(session): + """Simple test that the database creates fine from scratch.""" + assert session.query(func.count(User.id)).scalar() == 0 + assert session.query(func.count(Lexicon.id)).scalar() == 0 + assert session.query(func.count(Membership.id)).scalar() == 0 + assert session.query(func.count(Character.id)).scalar() == 0 + assert session.query(func.count(Article.id)).scalar() == 0 + assert session.query(func.count(ArticleIndex.id)).scalar() == 0 + assert session.query(func.count(ArticleIndexRule.id)).scalar() == 0 + assert session.query(func.count(ArticleContentRule.id)).scalar() == 0 + assert session.query(func.count(Post.id)).scalar() == 0