server/posts: report duplicate post ID and URL

This commit is contained in:
rr- 2016-09-10 10:14:53 +02:00
parent 0a19e7bbd0
commit 8674c8b50e
3 changed files with 10 additions and 3 deletions

View file

@ -20,7 +20,13 @@ class PostAlreadyFeaturedError(errors.ValidationError):
class PostAlreadyUploadedError(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): class InvalidPostIdError(errors.ValidationError):
@ -303,8 +309,7 @@ def update_post_content(post, content):
if other_post \ if other_post \
and other_post.post_id \ and other_post.post_id \
and other_post.post_id != post.post_id: and other_post.post_id != post.post_id:
raise PostAlreadyUploadedError( raise PostAlreadyUploadedError(other_post)
'Post already uploaded (%d)' % other_post.post_id)
post.file_size = len(content) post.file_size = len(content)
try: try:

View file

@ -261,6 +261,7 @@ def test_errors_not_spending_ids(
config_injector, tmpdir, context_factory, read_asset, user_factory): config_injector, tmpdir, context_factory, read_asset, user_factory):
config_injector({ config_injector({
'data_dir': str(tmpdir.mkdir('data')), 'data_dir': str(tmpdir.mkdir('data')),
'data_url': 'example.com',
'thumbnails': { 'thumbnails': {
'post_width': 300, 'post_width': 300,
'post_height': 300, 'post_height': 300,

View file

@ -329,6 +329,7 @@ def test_update_post_content_to_existing_content(
tmpdir, config_injector, post_factory, read_asset): tmpdir, config_injector, post_factory, read_asset):
config_injector({ config_injector({
'data_dir': str(tmpdir.mkdir('data')), 'data_dir': str(tmpdir.mkdir('data')),
'data_url': 'example.com',
'thumbnails': { 'thumbnails': {
'post_width': 300, 'post_width': 300,
'post_height': 300, 'post_height': 300,