def setUp(self): # make 3 test widgets for _ in range(6): self.user2.widgets.create(name=random_string(128)) self.url = reverse("widgets:index") self.response = self.client.get(self.url)
def setUp(self): self.comment = self.widget1.comments.create(user=self.commenter, comment=random_string(125)) self.url = reverse("widgets:comment_delete", kwargs={"pk": self.comment.pk}) self.post_client = self.authenticated_client("scrubby_mctroll", "12345")
def test_message_after_submit(self): comment = random_string(128) success_message = "The comment has been created." response = self.client.post(self.url, data={"comment": comment}, follow=True) messages = list(response.context["messages"]) # test the html self.assertIn(success_message.encode("utf-8"), response.content) # test the messages iterable for message in messages: self.assertEqual(str(message), success_message)
def setUp(self): self.test_note = self.widget1.notes.create(text=random_string(128))
def test_short_string(self): content = random_string(15) self.test_comment.comment = content self.assertEqual(content, str(self.test_comment))
def test_long_string(self): content = random_string(76) self.test_comment.comment = content self.assertEqual(content[:75] + "...", str(self.test_comment))
def test_create_comment(self): comment_text = random_string(1024) comment = self.widget1.comments.create(user=self.commenter, comment=comment_text) self.assertEqual(comment.widget.pk, self.widget1.pk) self.assertEqual(comment.comment, comment_text)
def setUp(self): self.test_comment = self.widget1.comments.create( user=self.commenter, comment=random_string(1024))
def test_create_widget(self): name = random_string(256) widget = self.user1.widgets.create(name=name) self.assertIsNotNone(widget) self.assertEqual(widget.name, name)
def test_form_submit_success(self): comment = random_string(128) count_query = self.widget1.comments.count count = count_query() self.client.post(self.url, data={"comment": comment}) self.assertEqual(count_query(), count + 1)
def test_form_submit_success_redirect(self): comment = random_string(128) response = self.client.post(self.url, data={"comment": comment}) self.assertEqual(response.status_code, 302)
def test_form_submit_failure(self): response = self.post_client.post(self.url, data={"comment": random_string(1025)}) self.assertEqual(response.status_code, 200) self.assertContains(response, "The comment is too long.")
def test_form_submit_success(self): comment = random_string(128) self.post_client.post(self.url, data={"comment": comment}) self.assertEqual( self.widget1.comments.get(pk=self.comment.pk).comment, comment)
def test_other_user_cannot_post(self): guest_client = self.authenticated_client("testuser1", "12345") response = guest_client.post(self.url, data={"comment": random_string(125)}) self.assertEqual(response.status_code, 403)
def test_anonymous_cannot_post(self): response = self.client.post(self.url, data={"comment": random_string(125)}) self.assertEqual(response.status_code, 403)