-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test fix #6 and create version 0.2.0
- Loading branch information
Mauricio Collazos
committed
Aug 8, 2018
1 parent
5f0c09b
commit b86533d
Showing
4 changed files
with
123 additions
and
15 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
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,107 @@ | ||
from django.test import ( | ||
TestCase, | ||
Client | ||
) | ||
from django.core.urlresolvers import reverse_lazy | ||
from django.contrib.auth import ( | ||
get_user_model, | ||
models as auth_models | ||
) | ||
|
||
from .. import ( | ||
conf, | ||
models | ||
) | ||
|
||
|
||
class ${model_name}Permission(TestCase): | ||
|
||
@staticmethod | ||
def perform_create(): | ||
return models.${model_name}.objects.create( | ||
name="delete_me" | ||
) | ||
|
||
def args_for_reverse_lazy(self): | ||
return { | ||
"slug": self.object.slug | ||
} | ||
|
||
def setUp(self): | ||
self.unauthorized_client = Client() | ||
self.client = Client() | ||
self.user = get_user_model().objects.create_user('user', password='password') | ||
self.client.login(username='user', password='password') | ||
self.object = self.perform_create() | ||
|
||
def test_unauthenticated_users_cant_create(self): | ||
response = self.unauthorized_client.get(reverse_lazy(conf.${model_prefix}_CREATE_URL_NAME)) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_unauthenticated_users_cant_update(self): | ||
response = self.unauthorized_client.get( | ||
reverse_lazy( | ||
conf.${model_prefix}_UPDATE_URL_NAME, | ||
kwargs=self.args_for_reverse_lazy() | ||
) | ||
) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_unauthenticated_users_cant_delete(self): | ||
response = self.unauthorized_client.get( | ||
reverse_lazy( | ||
conf.${model_prefix}_DELETE_URL_NAME, | ||
kwargs=self.args_for_reverse_lazy() | ||
) | ||
) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_unauthorized_users_cant_create(self): | ||
response = self.client.get(reverse_lazy(conf.${model_prefix}_CREATE_URL_NAME)) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_unauthorized_users_cant_update(self): | ||
response = self.client.get( | ||
reverse_lazy( | ||
conf.${model_prefix}_UPDATE_URL_NAME, | ||
kwargs=self.args_for_reverse_lazy() | ||
) | ||
) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_unauthorized_users_cant_delete(self): | ||
response = self.client.get( | ||
reverse_lazy( | ||
conf.${model_prefix}_DELETE_URL_NAME, | ||
kwargs=self.args_for_reverse_lazy() | ||
) | ||
) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_authorized_users_can_create(self): | ||
create_permission = auth_models.Permission.objects.get(codename="add_${model_name_lower}") | ||
self.user.user_permissions.add(create_permission) | ||
response = self.client.get(reverse_lazy(conf.${model_prefix}_CREATE_URL_NAME)) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_authorized_users_can_update(self): | ||
change_permission = auth_models.Permission.objects.get(codename="change_${model_name_lower}") | ||
self.user.user_permissions.add(change_permission) | ||
response = self.client.get( | ||
reverse_lazy( | ||
conf.${model_prefix}_UPDATE_URL_NAME, | ||
kwargs=self.args_for_reverse_lazy() | ||
) | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_authorized_users_can_delete(self): | ||
delete_permission = auth_models.Permission.objects.get(codename="delete_${model_name_lower}") | ||
self.user.user_permissions.add(delete_permission) | ||
response = self.client.get( | ||
reverse_lazy( | ||
conf.${model_prefix}_DELETE_URL_NAME, | ||
kwargs=self.args_for_reverse_lazy() | ||
) | ||
) | ||
self.assertEqual(response.status_code, 200) |
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