|
@@ -379,16 +379,15 @@ class ProjectCreateViewTest(TestCase):
|
|
|
self.user["fullperms"].user_permissions.add(Permission.objects.get(codename="add_project"))
|
|
|
self.user["noperms"] = User.objects.create_user("noperms", "noperms@example.com", "noperms")
|
|
|
|
|
|
|
|
|
def test_permission_denied(self):
|
|
|
"""
|
|
|
Tests if permission will be denied for client without sufficient privileges.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="noperms", password="noperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_add"))
|
|
|
|
|
|
|
|
|
response = self.client.get(reverse("project_create"))
|
|
|
|
|
|
self.assertContains(response, "You have insufficient privileges to access this resource. Please contact your local system administrator if you believe you should have been granted access.", status_code=403)
|
|
|
|
|
|
def test_permission_granted(self):
|
|
@@ -398,7 +397,58 @@ class ProjectCreateViewTest(TestCase):
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_add"))
|
|
|
response = self.client.get(reverse("project_create"))
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
def test_form_styling(self):
|
|
|
"""
|
|
|
Tests if proper form styling is being applied.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_create"))
|
|
|
|
|
|
self.assertContains(response, 'class="span6 textinput')
|
|
|
self.assertContains(response, 'class="span6 textarea')
|
|
|
self.assertContains(response, 'placeholder="New Project"')
|
|
|
self.assertContains(response, 'placeholder="Description for new project."')
|
|
|
|
|
|
|
|
|
class ProjectUpdateViewTest(TestCase):
|
|
|
|
|
|
fixtures = ['test-data.json']
|
|
|
|
|
|
def setUp(self):
|
|
|
# Set-up web client.
|
|
|
self.client = Client()
|
|
|
|
|
|
# Set-up users with different view permissions.
|
|
|
self.user = {}
|
|
|
self.user["fullperms"] = User.objects.create_user("fullperms", "fullperms@example.com", "fullperms")
|
|
|
self.user["fullperms"].user_permissions.add(Permission.objects.get(codename="change_project"))
|
|
|
self.user["noperms"] = User.objects.create_user("noperms", "noperms@example.com", "noperms")
|
|
|
|
|
|
def test_permission_denied(self):
|
|
|
"""
|
|
|
Tests if permission will be denied for client without sufficient privileges.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="noperms", password="noperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_update", args=(1,)))
|
|
|
|
|
|
self.assertContains(response, "You have insufficient privileges to access this resource. Please contact your local system administrator if you believe you should have been granted access.", status_code=403)
|
|
|
|
|
|
def test_permission_granted(self):
|
|
|
"""
|
|
|
Tests if permission will be granted for user with correct privileges.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_update", args=(1,)))
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
@@ -409,10 +459,87 @@ class ProjectCreateViewTest(TestCase):
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_add"))
|
|
|
response = self.client.get(reverse("project_update", args=(1,)))
|
|
|
|
|
|
self.assertContains(response, 'class="span6 textinput')
|
|
|
self.assertContains(response, 'class="span6 textarea')
|
|
|
self.assertContains(response, 'placeholder="New Project"')
|
|
|
self.assertContains(response, 'placeholder="Description for new project."')
|
|
|
self.assertContains(response, 'placeholder="Project name"')
|
|
|
self.assertContains(response, 'placeholder="Description for project."')
|
|
|
|
|
|
def test_content(self):
|
|
|
"""
|
|
|
Tests if the form comes pre-populated with proper content.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_update", args=(1,)))
|
|
|
|
|
|
self.assertContains(response, ">Edit project Test Project 1<")
|
|
|
self.assertContains(response, 'value="Test Project 1"')
|
|
|
self.assertContains(response, "This is a test project 1.")
|
|
|
|
|
|
|
|
|
class ProjectDeleteViewTest(TestCase):
|
|
|
|
|
|
fixtures = ['test-data.json']
|
|
|
|
|
|
def setUp(self):
|
|
|
# Set-up web client.
|
|
|
self.client = Client()
|
|
|
|
|
|
# Set-up users with different view permissions.
|
|
|
self.user = {}
|
|
|
self.user["fullperms"] = User.objects.create_user("fullperms", "fullperms@example.com", "fullperms")
|
|
|
self.user["fullperms"].user_permissions.add(Permission.objects.get(codename="delete_project"))
|
|
|
self.user["fullperms"].user_permissions.add(Permission.objects.get(codename="view"))
|
|
|
self.user["noperms"] = User.objects.create_user("noperms", "noperms@example.com", "noperms")
|
|
|
|
|
|
def test_permission_denied(self):
|
|
|
"""
|
|
|
Tests if permission will be denied for client without sufficient privileges.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="noperms", password="noperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_delete", args=(1,)))
|
|
|
|
|
|
self.assertContains(response, "You have insufficient privileges to access this resource. Please contact your local system administrator if you believe you should have been granted access.", status_code=403)
|
|
|
|
|
|
def test_permission_granted(self):
|
|
|
"""
|
|
|
Tests if permission will be granted for user with correct privileges.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_delete", args=(1,)))
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
def test_content(self):
|
|
|
"""
|
|
|
Tests if the form comes pre-populated with proper content.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_delete", args=(1,)))
|
|
|
|
|
|
self.assertContains(response, ">Remove project Test Project 1<")
|
|
|
self.assertContains(response, "Are you sure you want to remove this project?")
|
|
|
|
|
|
def test_message(self):
|
|
|
"""
|
|
|
Tests if the message gets added when the project is deleted.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("project_delete", args=(1,)))
|
|
|
|
|
|
response = self.client.post(reverse("project_delete", args=(1,)),
|
|
|
{'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
|
|
|
follow=True)
|
|
|
|
|
|
self.assertContains(response, "Project Test Project 1 has been removed.")
|