-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move a couple of tests to their own file, add the require_POST decora…
…tor to the delete_pet view
- Loading branch information
1 parent
45391ab
commit de23d62
Showing
3 changed files
with
48 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
|
||
from model_mommy import mommy | ||
|
||
from meupet.models import Pet | ||
from users.models import OwnerProfile | ||
|
||
|
||
class DeleteViewTest(TestCase): | ||
def setUp(self): | ||
super(DeleteViewTest, self).setUp() | ||
|
||
self.admin = OwnerProfile.objects.create_user( | ||
username='admin', | ||
password='admin', | ||
) | ||
self.pet = mommy.make(Pet, status=Pet.FOR_ADOPTION, owner=self.admin) | ||
|
||
def test_owner_can_delete_pet(self): | ||
"""Only the owner should be able to delete its own pet""" | ||
self.client.login(username='admin', password='admin') | ||
|
||
response = self.client.post(reverse('meupet:delete_pet', args=[self.pet.slug]), follow=True) | ||
|
||
self.assertTemplateUsed(response, 'meupet/index.html') | ||
self.assertNotContains(response, self.pet.name) | ||
|
||
def test_user_cant_delete_pet_from_other(self): | ||
"""Assert that an user can't delete pets from other people""" | ||
OwnerProfile.objects.create_user(username='other', password='user') | ||
self.client.login(username='other', password='user') | ||
|
||
response = self.client.post(reverse('meupet:delete_pet', args=[self.pet.slug]), follow=True) | ||
|
||
self.assertTemplateUsed(response, 'meupet/pet_detail.html') | ||
self.assertContains(response, self.pet.name) | ||
|
||
def test_only_accept_post_method(self): | ||
"""View should only accept http POST method""" | ||
response = self.client.get(reverse('meupet:delete_pet', args=[self.pet.slug])) | ||
|
||
self.assertEqual(405, response.status_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters