Skip to content

Commit

Permalink
Add tests for no empty comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bimalkant-lauhny committed Oct 31, 2018
1 parent 9249b8d commit 4b74a73
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions critiquebrainz/frontend/views/test/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ def setUp(self):

def test_create(self):
self.temporary_login(self.commenter)

# empty comment should be rejected
payload = {
'review_id': self.review['id'],
'text': '',
'state': 'publish',
}
response = self.client.post(
'/comments/create',
data=payload,
)

self.assertRedirects(response, '/review/%s' % self.review['id'])
count = db_comment.count_comments(review_id=self.review['id'])
self.assertEqual(count, 0)

response = self.client.get('/review/%s' % self.review['id'])
self.assert200(response)
# Test that the rendered html should contain error message
self.assertIn('Comment must not be empty!', str(response.data))
# Test that the rendered html should contain commenter's display name only once (just above comment form)
self.assertEqual(str(response.data).count(self.commenter.display_name), 1)

# comment with some text should be accepted
payload = {
'review_id': self.review['id'],
'text': 'Test Comment.',
Expand All @@ -76,5 +100,7 @@ def test_create(self):

response = self.client.get('/review/%s' % self.review['id'])
self.assert200(response)
# Test if the rendered html contains commenter's display name
self.assertIn(self.commenter.display_name, str(response.data))
# Test that the rendered html should contain error message
self.assertIn('Comment has been saved!', str(response.data))
# Test that the rendered html should contain commenter's display name twice (above posted comment and comment form)
self.assertEqual(str(response.data).count(self.commenter.display_name), 2)

0 comments on commit 4b74a73

Please sign in to comment.