def test_post_task_scores_table_settings_allow(self, original_message, expected_message): # WHEN I am logged in as expert A and I post comment request = Mock(user=self.expertA, method='POST', POST={'score_%d-comment' % self.score.pk: original_message}) # THEN response status_code should be 302 (redirect) self.assertEqual(post_score_comment(request, self.score.pk).status_code, 302) # AND new comment should get created in db # AND this comment should contain expected message self.assertEqual(CommentExmo.objects.filter(object_pk=self.score.pk).order_by('-id')[0].comment, expected_message)
def test_forbid_post_comment_anonymous(self, status, *args): url = reverse('exmo2010:post_score_comment', args=[self.scores[status].pk]) # WHEN anonymous user post comment request = MagicMock(user=self.users['anonymous'], method='POST', POST={'score_%d-comment' % self.scores[status].pk: '123'}) request.get_full_path.return_value = url response = post_score_comment(request, self.scores[status].pk) # THEN response status_code should be 302 (redirect) self.assertEqual(response.status_code, 302) # AND response redirects to login page self.assertEqual(response['Location'], '{}?next={}'.format(settings.LOGIN_URL, url)) # AND new comments should not get created in db self.assertEqual(CommentExmo.objects.all().count(), 0) # AND no email messages should be sent. self.assertEqual(len(mail.outbox), 0)
def test_post_task_scores_table_settings_allow(self, original_message, expected_message): # WHEN I am logged in as expert A and I post comment request = Mock( user=self.expertA, method='POST', POST={'score_%d-comment' % self.score.pk: original_message}) # THEN response status_code should be 302 (redirect) self.assertEqual( post_score_comment(request, self.score.pk).status_code, 302) # AND new comment should get created in db # AND this comment should contain expected message self.assertEqual( CommentExmo.objects.filter( object_pk=self.score.pk).order_by('-id')[0].comment, expected_message)
def test_forbid_post_comment_anonymous(self, status, *args): url = reverse('exmo2010:post_score_comment', args=[self.scores[status].pk]) # WHEN anonymous user post comment request = MagicMock( user=self.users['anonymous'], method='POST', POST={'score_%d-comment' % self.scores[status].pk: '123'}) request.get_full_path.return_value = url response = post_score_comment(request, self.scores[status].pk) # THEN response status_code should be 302 (redirect) self.assertEqual(response.status_code, 302) # AND response redirects to login page self.assertEqual(response['Location'], '{}?next={}'.format(settings.LOGIN_URL, url)) # AND new comments should not get created in db self.assertEqual(CommentExmo.objects.all().count(), 0) # AND no email messages should be sent. self.assertEqual(len(mail.outbox), 0)