server/posts: fix post relations
Trying to relate post to itself resulted in 500 ISE.
This commit is contained in:
parent
627574a9c2
commit
9edaaffec2
|
@ -377,6 +377,8 @@ def update_post_relations(post, new_post_ids):
|
||||||
.all()
|
.all()
|
||||||
if len(new_posts) != len(new_post_ids):
|
if len(new_posts) != len(new_post_ids):
|
||||||
raise InvalidPostRelationError('One of relations does not exist.')
|
raise InvalidPostRelationError('One of relations does not exist.')
|
||||||
|
if post.post_id in new_post_ids:
|
||||||
|
raise InvalidPostRelationError('Post cannot relate to itself.')
|
||||||
|
|
||||||
relations_to_del = [p for p in old_posts if p.post_id not in new_post_ids]
|
relations_to_del = [p for p in old_posts if p.post_id not in new_post_ids]
|
||||||
relations_to_add = [p for p in new_posts if p.post_id not in old_post_ids]
|
relations_to_add = [p for p in new_posts if p.post_id not in old_post_ids]
|
||||||
|
|
|
@ -541,6 +541,14 @@ def test_update_post_relations_with_nonexisting_posts():
|
||||||
posts.update_post_relations(post, [100])
|
posts.update_post_relations(post, [100])
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_post_relations_with_itself(post_factory):
|
||||||
|
post = post_factory()
|
||||||
|
db.session.add(post)
|
||||||
|
db.session.flush()
|
||||||
|
with pytest.raises(posts.InvalidPostRelationError):
|
||||||
|
posts.update_post_relations(post, [post.post_id])
|
||||||
|
|
||||||
|
|
||||||
def test_update_post_notes():
|
def test_update_post_notes():
|
||||||
post = db.Post()
|
post = db.Post()
|
||||||
posts.update_post_notes(
|
posts.update_post_notes(
|
||||||
|
|
Loading…
Reference in New Issue