2021-05-31 17:52:37 +00:00
|
|
|
from amanuensis.db import DbContext
|
2021-05-30 00:38:14 +00:00
|
|
|
import amanuensis.backend.membership as memq
|
|
|
|
|
|
|
|
|
2021-05-31 17:52:37 +00:00
|
|
|
def test_create_membership(db: DbContext, make_user, make_lexicon):
|
2021-05-30 00:38:14 +00:00
|
|
|
"""Test joining a game."""
|
|
|
|
# Set up a user and a lexicon
|
2021-05-31 17:52:37 +00:00
|
|
|
new_user = make_user()
|
2021-05-30 00:38:14 +00:00
|
|
|
assert new_user.id, 'Failed to create user'
|
2021-05-31 17:52:37 +00:00
|
|
|
new_lexicon = make_lexicon()
|
2021-05-30 00:38:14 +00:00
|
|
|
assert new_lexicon.id, 'Failed to create lexicon'
|
|
|
|
|
|
|
|
# Add the user to the lexicon as an editor
|
|
|
|
mem = memq.create(db, new_user.id, new_lexicon.id, True)
|
|
|
|
assert mem, 'Failed to create membership'
|
|
|
|
|
|
|
|
# Check that the user and lexicon are mutually visible in the ORM relationships
|
|
|
|
assert new_user.memberships, 'User memberships not updated'
|
|
|
|
assert new_lexicon.memberships, 'Lexicon memberships not updated'
|
|
|
|
assert new_user.memberships[0].lexicon_id == new_lexicon.id
|
|
|
|
assert new_lexicon.memberships[0].user_id == new_user.id
|
|
|
|
|
|
|
|
# Check that the editor flag was set properly
|
|
|
|
assert new_lexicon.memberships
|