def test_bad_signature(self): key = self.key + 'invalid' response = get_comment_from_key(key) self.assertEqual(response.is_valid, False) self.assertEqual(response.why_invalid, CommentFailReason.BAD) self.assertIsNone(response.obj)
def test_success(self): response = get_comment_from_key(self.key) self.assertEqual(response.is_valid, True) self.assertEqual(response.why_invalid, None) self.assertIsInstance(response.obj, Comment) # comment is saved self.assertIsNotNone(response.obj.id) self.assertEqual(response.obj.posted, self.time_posted)
def test_value_error(self): comment_dict = self.comment_obj.to_dict().copy() comment_dict['user'] = 1 key = signing.dumps(comment_dict) response = get_comment_from_key(key) self.assertEqual(response.is_valid, False) self.assertEqual(response.why_invalid, CommentFailReason.BAD) self.assertIsNone(response.obj)
def get(self, request, *args, **kwargs): key = kwargs.get('key', None) comment = get_comment_from_key(key) if comment.why_invalid == CommentFailReason.BAD: return Response({'error': _('Bad Signature, Comment discarded')}, status=status.HTTP_400_BAD_REQUEST) if comment.why_invalid == CommentFailReason.EXISTS: return Response({'error': _('Comment already verified')}, status=status.HTTP_200_OK) return Response(CommentSerializer(comment.obj).data, status=status.HTTP_201_CREATED)
def get(request, *args, **kwargs): key = kwargs.get('key', None) comment = get_comment_from_key(key) if comment.why_invalid == CommentFailReason.BAD: return Response({'detail': EmailError.BROKEN_VERIFICATION_LINK}, status=status.HTTP_400_BAD_REQUEST) if comment.why_invalid == CommentFailReason.EXISTS: return Response({'detail': EmailError.USED_VERIFICATION_LINK}, status=status.HTTP_200_OK) return Response(CommentSerializer(comment.obj).data, status=status.HTTP_201_CREATED)
def get(self, request, *args, **kwargs): key = kwargs.get('key', None) temp_comment = get_comment_from_key(key) self._handle_invalid_comment(temp_comment, request) if not temp_comment.is_valid: return render(request, template_name='comment/anonymous/discarded.html') comment = self.perform_save(temp_comment.obj, request) return redirect(comment.get_url(request))
def test_comment_exists(self): comment_dict = self.comment_obj.to_dict().copy() comment = self.create_anonymous_comment(posted=timezone.now(), email='*****@*****.**') comment_dict.update({ 'posted': str(comment.posted), 'email': comment.email }) key = signing.dumps(comment_dict) response = get_comment_from_key(key) self.assertEqual(response.is_valid, False) self.assertEqual(response.why_invalid, CommentFailReason.EXISTS) self.assertIsNone(response.obj)
def get(request, *args, **kwargs): key = kwargs.get('key', None) comment = get_comment_from_key(key) if comment.why_invalid == CommentFailReason.BAD: messages.error(request, EmailError.BROKEN_VERIFICATION_LINK) elif comment.why_invalid == CommentFailReason.EXISTS: messages.warning(request, EmailError.USED_VERIFICATION_LINK) if not comment.is_valid: return render(request, template_name='comment/anonymous/discarded.html') return redirect(comment.obj.get_url(request))
def get(self, request, *args, **kwargs): key = kwargs.get('key', None) comment = get_comment_from_key(key) if comment.why_invalid == CommentFailReason.BAD: messages.error(request, _('The link seems to be broken.')) elif comment.why_invalid == CommentFailReason.EXISTS: messages.warning(request, _('The comment has already been verified.')) if not comment.is_valid: return render(request, template_name='comment/anonymous/discarded.html') return redirect(comment.obj.get_url(request))
def test_success(self): response = get_comment_from_key(self.key) self.assertEqual(response.is_valid, True) self.assertEqual(response.why_invalid, None) self.assertIsInstance(response.obj, Comment)