Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test_new_post(self):
- """ Test fixture post in various areas """
- self.check_if_post_is_displaying(self.post, self.testgroup)
- def test_logged_in_edit_show(self):
- """ Logged in user can edit post """
- response = self.client.post(
- reverse("post_edit", args=[self.user.username, self.post.pk]),
- {
- "text": "Edited post",
- "author": self.user,
- "group": self.testgroup2.id
- },
- follow=True
- )
- editedpost = Post.objects.get(pk=self.post.pk)
- self.assertEqual(response.status_code, 200)
- # test all pages
- self.check_if_post_is_displaying(editedpost, self.testgroup2)
- # test if previous group page is empty
- oldgroupurl = reverse("group_url", args=[self.testgroup.slug])
- response = self.client.get(oldgroupurl)
- self.assertEqual(len(response.context["page"]), 0)
- def check_if_post_is_displaying(self, post_to_compare, group_object):
- """ Test displaying in various areas """
- # index
- response = self.client.get(reverse("index"))
- self.detail_multipost_comparison(response, post_to_compare)
- # profile
- response = self.client.get(
- reverse("profile", args=[self.user.username])
- )
- self.detail_multipost_comparison(response, post_to_compare)
- # post
- response = self.client.get(
- reverse("post_single", args=[self.user.username, self.post.pk])
- )
- self.detail_singlepost_comparison(response, post_to_compare)
- # group
- response = self.client.get(
- reverse("group_url", args=[group_object.slug])
- )
- self.detail_multipost_comparison(response, post_to_compare)
- def detail_multipost_comparison(self, response, post_to_compare):
- """ Extract first post of array """
- page = response.context["page"]
- post = page[0]
- self.post_comparison(response, post, post_to_compare)
- def detail_singlepost_comparison(self, response, post_to_compare):
- """ Take the only post in context """
- post = response.context["post"]
- self.post_comparison(response, post, post_to_compare)
- def post_comparison(self, response, post, post_to_compare):
- """ Actual compararing process """
- self.assertEqual(response.status_code, 200)
- post_one = (post.text, post.id, post.author, post.group,)
- post_two = (
- post_to_compare.text,
- post_to_compare.id,
- post_to_compare.author,
- post_to_compare.group,
- )
- self.assertEqual(post_one, post_two)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement