housekeep(fastapi): rewrite test_accepted_term with fixtures

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-30 16:35:52 -08:00
parent d6cb3b9fac
commit 91f6591141
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -8,39 +8,48 @@ from aurweb.models.account_type import USER_ID
from aurweb.models.term import Term
from aurweb.models.user import User
user = term = accepted_term = None
@pytest.fixture(autouse=True)
def setup(db_test):
global user, term
return
@pytest.fixture
def user() -> User:
with db.begin():
user = db.create(User, Username="test", Email="test@example.org",
RealName="Test User", Passwd="testPassword",
AccountTypeID=USER_ID)
yield user
@pytest.fixture
def term() -> Term:
with db.begin():
term = db.create(Term, Description="Test term",
URL="https://test.term")
yield term
def test_accepted_term():
@pytest.fixture
def accepted_term(user: User, term: Term) -> AcceptedTerm:
with db.begin():
accepted_term = db.create(AcceptedTerm, User=user, Term=term)
yield accepted_term
def test_accepted_term(user: User, term: Term, accepted_term: AcceptedTerm):
# Make sure our AcceptedTerm relationships got initialized properly.
assert accepted_term.User == user
assert accepted_term in user.accepted_terms
assert accepted_term in term.accepted_terms
def test_accepted_term_null_user_raises_exception():
def test_accepted_term_null_user_raises_exception(term: Term):
with pytest.raises(IntegrityError):
AcceptedTerm(Term=term)
def test_accepted_term_null_term_raises_exception():
def test_accepted_term_null_term_raises_exception(user: User):
with pytest.raises(IntegrityError):
AcceptedTerm(User=user)