Guest User

Untitled

a guest
Sep 2nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. class CommunityAmenityViewTests(TestCase):
  2. fixtures = ["corporations", "communities", "users"]
  3.  
  4. def setUp(self):
  5. self.community = Community.objects.latest("id")
  6. self.cca = self._create_community_amenity()
  7. self.test_image_path = u"%s/%s" % (settings.MEDIA_ROOT,
  8. "testing/koala.jpg")
  9. self.test_image = open(self.test_image_path, "rb")
  10. self.post_data = {
  11. "community": self.community.pk,
  12. "name": "test comm amenity name",
  13. "order": 2,
  14. "image": self.test_image
  15.  
  16. }
  17. self.superuser = User.objects.get(username="developer")
  18.  
  19. def login_user(self):
  20. self.assertTrue(
  21. self.client.login(username=self.superuser.username,
  22. password="developer"))
  23.  
  24. def set_session_community(self, session):
  25. session["community"] = self.community
  26. session.save()
  27.  
  28. def _create_community_amenity(self, filename="testing/koala.jpg"):
  29. image = u"%s/%s" % (settings.MEDIA_ROOT, filename)
  30. return CommunityAmenityList.objects.create(
  31. community=self.community,
  32. name="Test com list?",
  33. image=SimpleUploadedFile("koala.jpg", open(image, "rb").read())
  34. )
  35.  
  36. def test_community_amenity_list_view(self):
  37. self.login_user()
  38. self.set_session_community(self.client.session)
  39. url = reverse("cms_communities_amenity_list")
  40. response = self.client.get(url)
  41. self.assertEqual(response.status_code, 200)
  42. self.assertTemplateUsed(response,
  43. "cms/communities/list_amenities.html")
  44. self.assertContains(response, self.cca.name)
  45.  
  46. def test_community_amenity_create_view(self):
  47. self.login_user()
  48. self.set_session_community(self.client.session)
  49. url = reverse("cms_communities_amenity_add")
  50. response = self.client.get(url)
  51. self.assertEqual(response.status_code, 200)
  52. self.assertTemplateUsed(response, "cms/communities/add_amenity.html")
  53.  
  54. response = self.client.post(url, self.post_data, follow=True)
  55. self.assertEqual(response.status_code, 200)
  56. self.assertRedirects(response, reverse("cms_communities_amenity_list"))
  57. self.assertTemplateUsed(response,
  58. "cms/communities/list_amenities.html")
  59.  
  60. def test_community_amenity_update_view(self):
  61. self.login_user()
  62. self.set_session_community(self.client.session)
  63. url = reverse("cms_communities_amenity_edit",
  64. kwargs={"pk": self.cca.pk})
  65. response = self.client.get(url)
  66. self.assertEqual(response.status_code, 200)
  67. self.assertTemplateUsed(response, "cms/communities/edit_amenity.html")
  68.  
  69. response = self.client.post(url, self.post_data, follow=True)
  70. self.assertRedirects(response, reverse("cms_communities_amenity_list"))
  71. self.assertEqual(response.status_code, 200)
  72. self.assertTemplateUsed(response,
  73. "cms/communities/list_amenities.html")
  74. self.assertContains(response, self.cca.name)
  75.  
  76. def test_community_amenity_delete_view(self):
  77. self.login_user()
  78. self.set_session_community(self.client.session)
  79. url = reverse("cms_communities_amenity_delete",
  80. kwargs={"pk": self.cca.pk})
  81. response = self.client.get(url)
  82. self.assertEqual(response.status_code, 200)
  83. self.assertTemplateUsed(response,
  84. "cms/communities/delete_amenity.html")
  85. self.assertContains(response, self.cca.name)
  86.  
  87. response = self.client.post(url, follow=True)
  88. self.assertEqual(response.status_code, 200)
  89. self.assertRedirects(response, reverse("cms_communities_amenity_list"))
  90. self.assertTemplateUsed(response,
  91. "cms/communities/list_amenities.html")
Add Comment
Please, Sign In to add comment