Compare commits
1 Commits
ea5b3e3b66
...
f9babd73b9
Author | SHA1 | Date |
---|---|---|
Nikolai | f9babd73b9 |
|
@ -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
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue