def test_comment_subscription_on_delete(self): comment = Comment.objects.create(self.user, 'text', self.article) with mock.patch('core.signal_handlers.' 'notify_user_on_comment_change') as notify_mock: response = self.client.delete(COMMENT_ID_TEMPLATE_URL.format( comment.id), format='json') self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(notify_mock.call_count, 1)
def setUp(self): super().setUp() management.call_command('createinitialrevisions') self.new_text = 'new text' self.client.patch(COMMENT_ID_TEMPLATE_URL.format(self.comment_1.id), { 'text': self.new_text, 'request_user_id': self.user.id, }, format='json') self.comment_1.refresh_from_db()
def test_comment_subscription_on_change(self): with mock.patch('core.signal_handlers.' 'notify_user_on_comment_change') as notify_mock: response = self.client.patch(COMMENT_ID_TEMPLATE_URL.format( self.comment_1.id), { 'text': 'new text', 'request_user_id': self.user.id }, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(notify_mock.call_count, 1)
def _api_update_comment(self, comment, data): return self.client.patch(COMMENT_ID_TEMPLATE_URL.format(comment.id), data, format='json')
def _api_get_comment_by_id(self, comment, data=None): return self.client.get(COMMENT_ID_TEMPLATE_URL.format(comment.id), data)
def _api_get_comment_by_id(self, comment, **kwargs): return self.client.get(COMMENT_ID_TEMPLATE_URL.format(comment.id), kwargs)
def test_delete_comment_by_id(self): response = self.client.delete( COMMENT_ID_TEMPLATE_URL.format(self.comment_4.id)) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
def test_cannot_delete_comment_with_descendants(self): response = self.client.delete( COMMENT_ID_TEMPLATE_URL.format(self.comment_3.id)) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)