Compare commits

..

5 Commits

Author SHA1 Message Date
Nikolai ea5b3e3b66 merge commit 2021-05-29 18:46:27 -07:00
Nikolai 592becff2d post testing properly creates database context 2021-05-29 18:44:03 -07:00
Nikolai 4af22ad863 added unit test for post 2021-05-29 18:34:16 -07:00
Nikolai 2f568fb385 added post object 2021-05-29 18:34:15 -07:00
Nikolai 1e9405bad0 added post object 2021-05-29 17:45:03 -07:00
3 changed files with 7 additions and 7 deletions

View File

@ -48,4 +48,4 @@ def create(
) )
db.session.add(new_lexicon) db.session.add(new_lexicon)
db.session.commit() db.session.commit()
return new_lexicon return new_lexicon

View File

@ -21,7 +21,7 @@ def create(
# Verify lexicon id # Verify lexicon id
if not isinstance(lexicon_id, int): if not isinstance(lexicon_id, int):
raise ArgumentError('Lexicon id must be an integer.') raise ArgumentError('Lexicon id must be an integer.')
# Verify user_id # Verify user_id
if not (isinstance(user_id, int) or user_id is None): if not (isinstance(user_id, int) or user_id is None):
raise ArgumentError('User id must be an integer.') raise ArgumentError('User id must be an integer.')
@ -39,4 +39,4 @@ def create(
) )
db.session.add(new_post) db.session.add(new_post)
db.session.commit() db.session.commit()
return new_post return new_post

View File

@ -12,7 +12,7 @@ from .test_db import db
def test_create_post(db): def test_create_post(db):
"""Test new post creation""" """Test new post creation"""
# Make user and lexicon # Make user and lexicon
new_user = userq.create(db, 'username', 'password', 'user', 'a@b.c', False) new_user = userq.create(db, 'username', 'password', 'user', 'a@b.c', False)
assert new_user.id, 'Failed to create user' assert new_user.id, 'Failed to create user'
@ -22,7 +22,7 @@ def test_create_post(db):
# Add the user to the lexicon as an editor # Add the user to the lexicon as an editor
mem = memq.create(db, new_user.id, new_lexicon.id, True) mem = memq.create(db, new_user.id, new_lexicon.id, True)
assert mem, 'Failed to create membership' assert mem, 'Failed to create membership'
# argument dictionary for post object # argument dictionary for post object
kwargs = { kwargs = {
'lexicon_id': new_lexicon.id, 'lexicon_id': new_lexicon.id,
@ -43,7 +43,7 @@ def test_create_post(db):
postq.create(db, **{**kwargs, 'user_id': ''}) postq.create(db, **{**kwargs, 'user_id': ''})
with pytest.raises(ArgumentError): with pytest.raises(ArgumentError):
postq.create(db, **{**kwargs, 'body': ''}) postq.create(db, **{**kwargs, 'body': ''})
# post with only whitespace doesn't work # post with only whitespace doesn't work
with pytest.raises(ArgumentError): with pytest.raises(ArgumentError):
postq.create(db, **{**kwargs, 'body': ' '}) postq.create(db, **{**kwargs, 'body': ' '})
@ -58,4 +58,4 @@ def test_create_post(db):
# post creation works when user is None # post creation works when user is None
new_post = postq.create(db, **{**kwargs, 'user_id': None}) new_post = postq.create(db, **{**kwargs, 'user_id': None})
assert new_post assert new_post
assert new_post.user_id is None assert new_post.user_id is None