def test_comment_length_render_on_profile(self): """Test comment length render on profile post.""" this_user = self.users[0] self.client.force_login(this_user) this_post = Post() this_post.author = this_user this_post.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() response = self.client.get('/profile/') self.assertContains(response, 'Comments: (2)')
def test_post_comment_200(self): """Test post comment view returns status code 200.""" this_user = self.users[0] self.client.force_login(this_user) this_post = Post() this_post.author = this_user this_post.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() response = self.client.post('/posts/' + str(this_post.id)) self.assertTrue(response.status_code == 200)
def test_comment_length_render_on_other_user_profile(self): """Test comment length render on profile post.""" this_user = self.users[0] this_post = Post() this_post.author = this_user this_post.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() self.client.force_login(self.users[1]) response = self.client.get( '/profile/' + str(this_user.username), follow=True) self.assertContains(response, 'Comments: (3)')
def test_comment_when_not_logged_in(self): """Should return Forbidden Status Code.""" this_user = self.users[0] this_post = Post() this_post.author = this_user this_post.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.save() response = self.client.post( '/posts/' + str(this_post.id), follow=True, comment='yo') self.assertTrue(response.status_code == 403)
def test_comment_content_renders_on_posts_view(self): """Test comment comntent is in post request.""" this_user = self.users[0] self.client.force_login(this_user) this_post = Post() this_post.author = this_user this_post.content = 'tornado fire crocodile' this_post.title = 'marc ben benny built this site' this_post.save() this_comment = Comment() this_comment.by_user = this_user this_comment.on_post = this_post this_comment.comment = 'this comment' this_comment.save() response = self.client.post( '/posts/' + str(this_post.id), follow=True) self.assertContains(response, 'this comment')