Advertisement
matacoder

Untitled

Sep 8th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1.   def test_new_post(self):
  2.         """ Test fixture post in various areas """
  3.         self.check_if_post_is_displaying(self.post, self.testgroup)
  4.  
  5.     def test_logged_in_edit_show(self):
  6.         """ Logged in user can edit post """
  7.         response = self.client.post(
  8.             reverse("post_edit", args=[self.user.username, self.post.pk]),
  9.             {
  10.                 "text": "Edited post",
  11.                 "author": self.user,
  12.                 "group": self.testgroup2.id
  13.             },
  14.             follow=True
  15.         )
  16.         editedpost = Post.objects.get(pk=self.post.pk)
  17.         self.assertEqual(response.status_code, 200)
  18.         # test all pages
  19.         self.check_if_post_is_displaying(editedpost, self.testgroup2)
  20.         # test if previous group page is empty
  21.         oldgroupurl = reverse("group_url", args=[self.testgroup.slug])
  22.         response = self.client.get(oldgroupurl)
  23.         self.assertEqual(len(response.context["page"]), 0)
  24.  
  25.     def check_if_post_is_displaying(self, post_to_compare, group_object):
  26.         """ Test displaying in various areas """
  27.         # index
  28.         response = self.client.get(reverse("index"))
  29.         self.detail_multipost_comparison(response, post_to_compare)
  30.  
  31.         # profile
  32.         response = self.client.get(
  33.             reverse("profile", args=[self.user.username])
  34.         )
  35.         self.detail_multipost_comparison(response, post_to_compare)
  36.  
  37.         # post
  38.         response = self.client.get(
  39.             reverse("post_single", args=[self.user.username, self.post.pk])
  40.         )
  41.         self.detail_singlepost_comparison(response, post_to_compare)
  42.  
  43.         # group
  44.         response = self.client.get(
  45.             reverse("group_url", args=[group_object.slug])
  46.         )
  47.         self.detail_multipost_comparison(response, post_to_compare)
  48.  
  49.     def detail_multipost_comparison(self, response, post_to_compare):
  50.         """ Extract first post of array """
  51.         page = response.context["page"]
  52.         post = page[0]
  53.         self.post_comparison(response, post, post_to_compare)
  54.  
  55.     def detail_singlepost_comparison(self, response, post_to_compare):
  56.         """ Take the only post in context """
  57.         post = response.context["post"]
  58.         self.post_comparison(response, post, post_to_compare)
  59.  
  60.     def post_comparison(self, response, post, post_to_compare):
  61.         """ Actual compararing process """
  62.         self.assertEqual(response.status_code, 200)
  63.         post_one = (post.text, post.id, post.author, post.group,)
  64.         post_two = (
  65.             post_to_compare.text,
  66.             post_to_compare.id,
  67.             post_to_compare.author,
  68.             post_to_compare.group,
  69.         )
  70.         self.assertEqual(post_one, post_two)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement