Add basic database test

This commit is contained in:
Tim Van Baak 2021-05-04 23:05:14 -07:00
parent 9f2c9d14d3
commit 8a4d666248
2 changed files with 25 additions and 5 deletions

View File

@ -1,5 +0,0 @@
from amanuensis import __version__
def test_version():
assert __version__ == '0.1.0'

25
tests/test_db.py Normal file
View File

@ -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