From 8674c8b50e9988162aeeb57df23ef334f2701e93 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 10 Sep 2016 10:14:53 +0200 Subject: [PATCH] server/posts: report duplicate post ID and URL --- server/szurubooru/func/posts.py | 11 ++++++++--- server/szurubooru/tests/api/test_post_creating.py | 1 + server/szurubooru/tests/func/test_posts.py | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index b7ffe2bd..3863e5bb 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -20,7 +20,13 @@ class PostAlreadyFeaturedError(errors.ValidationError): class PostAlreadyUploadedError(errors.ValidationError): - pass + def __init__(self, other_post): + super().__init__( + 'Post already uploaded (%d)' % other_post.post_id, + { + 'otherPostUrl': get_post_content_url(other_post), + 'otherPostId': other_post.post_id, + }) class InvalidPostIdError(errors.ValidationError): @@ -303,8 +309,7 @@ def update_post_content(post, content): if other_post \ and other_post.post_id \ and other_post.post_id != post.post_id: - raise PostAlreadyUploadedError( - 'Post already uploaded (%d)' % other_post.post_id) + raise PostAlreadyUploadedError(other_post) post.file_size = len(content) try: diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py index 45f0e708..341990c8 100644 --- a/server/szurubooru/tests/api/test_post_creating.py +++ b/server/szurubooru/tests/api/test_post_creating.py @@ -261,6 +261,7 @@ def test_errors_not_spending_ids( config_injector, tmpdir, context_factory, read_asset, user_factory): config_injector({ 'data_dir': str(tmpdir.mkdir('data')), + 'data_url': 'example.com', 'thumbnails': { 'post_width': 300, 'post_height': 300, diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index dc67c008..56daaee1 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -329,6 +329,7 @@ def test_update_post_content_to_existing_content( tmpdir, config_injector, post_factory, read_asset): config_injector({ 'data_dir': str(tmpdir.mkdir('data')), + 'data_url': 'example.com', 'thumbnails': { 'post_width': 300, 'post_height': 300,