Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CommunityAmenityViewTests(TestCase):
- fixtures = ["corporations", "communities", "users"]
- def setUp(self):
- self.community = Community.objects.latest("id")
- self.cca = self._create_community_amenity()
- self.test_image_path = u"%s/%s" % (settings.MEDIA_ROOT,
- "testing/koala.jpg")
- self.test_image = open(self.test_image_path, "rb")
- self.post_data = {
- "community": self.community.pk,
- "name": "test comm amenity name",
- "order": 2,
- "image": self.test_image
- }
- self.superuser = User.objects.get(username="developer")
- def login_user(self):
- self.assertTrue(
- self.client.login(username=self.superuser.username,
- password="developer"))
- def set_session_community(self, session):
- session["community"] = self.community
- session.save()
- def _create_community_amenity(self, filename="testing/koala.jpg"):
- image = u"%s/%s" % (settings.MEDIA_ROOT, filename)
- return CommunityAmenityList.objects.create(
- community=self.community,
- name="Test com list?",
- image=SimpleUploadedFile("koala.jpg", open(image, "rb").read())
- )
- def test_community_amenity_list_view(self):
- self.login_user()
- self.set_session_community(self.client.session)
- url = reverse("cms_communities_amenity_list")
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response,
- "cms/communities/list_amenities.html")
- self.assertContains(response, self.cca.name)
- def test_community_amenity_create_view(self):
- self.login_user()
- self.set_session_community(self.client.session)
- url = reverse("cms_communities_amenity_add")
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response, "cms/communities/add_amenity.html")
- response = self.client.post(url, self.post_data, follow=True)
- self.assertEqual(response.status_code, 200)
- self.assertRedirects(response, reverse("cms_communities_amenity_list"))
- self.assertTemplateUsed(response,
- "cms/communities/list_amenities.html")
- def test_community_amenity_update_view(self):
- self.login_user()
- self.set_session_community(self.client.session)
- url = reverse("cms_communities_amenity_edit",
- kwargs={"pk": self.cca.pk})
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response, "cms/communities/edit_amenity.html")
- response = self.client.post(url, self.post_data, follow=True)
- self.assertRedirects(response, reverse("cms_communities_amenity_list"))
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response,
- "cms/communities/list_amenities.html")
- self.assertContains(response, self.cca.name)
- def test_community_amenity_delete_view(self):
- self.login_user()
- self.set_session_community(self.client.session)
- url = reverse("cms_communities_amenity_delete",
- kwargs={"pk": self.cca.pk})
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response,
- "cms/communities/delete_amenity.html")
- self.assertContains(response, self.cca.name)
- response = self.client.post(url, follow=True)
- self.assertEqual(response.status_code, 200)
- self.assertRedirects(response, reverse("cms_communities_amenity_list"))
- self.assertTemplateUsed(response,
- "cms/communities/list_amenities.html")
Add Comment
Please, Sign In to add comment