Mercurial > public > sg101
diff comments/views.py @ 1221:d6b3f7e77f6c modernize tip
Add unit tests for comments views.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 01 Mar 2025 15:52:11 -0600 |
parents | 02181fa5ac9d |
children |
line wrap: on
line diff
--- a/comments/views.py Sun Feb 23 16:34:01 2025 -0600 +++ b/comments/views.py Sat Mar 01 15:52:11 2025 -0600 @@ -53,10 +53,10 @@ try: model = apps.get_model(*ctype.split('.', 1)) target = model.objects.get(pk=object_pk) - except TypeError: + except LookupError: return HttpResponseBadRequest( "Invalid content_type value: %r" % escape(ctype)) - except AttributeError: + except ValueError: return HttpResponseBadRequest( "The given content-type %r does not resolve to a valid model." % \ escape(ctype)) @@ -64,6 +64,8 @@ return HttpResponseBadRequest( "No object matching content-type %r and object PK %r exists." % \ (escape(ctype), escape(object_pk))) + except: + return HttpResponseBadRequest('Unexpected error') # Can we comment on the target object? if hasattr(target, 'can_comment_on'): @@ -110,7 +112,7 @@ be the target of an AJAX post. """ if not request.user.is_authenticated(): - return HttpResponse('Please login or register to flag a comment.') + return HttpResponseForbidden('Please login or register to flag a comment.') id = request.POST.get('id', None) if id is None: