mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep(fastapi): rewrite test_accepted_term with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
d6cb3b9fac
commit
91f6591141
1 changed files with 16 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue