|
@@ -849,3 +849,83 @@ class EntityCreateViewTest(TestCase):
|
|
|
initial = view.get_initial()
|
|
|
|
|
|
self.assertDictContainsSubset({"location": "1"}, initial)
|
|
|
|
|
|
|
|
|
class EntityDeleteViewTest(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_entity"))
|
|
|
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("entity_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("entity_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("entity_delete", args=(1,)))
|
|
|
|
|
|
self.assertContains(response, ">Remove entity Test Entity 1<")
|
|
|
self.assertContains(response, "Are you sure you want to remove this entity?")
|
|
|
|
|
|
def test_message(self):
|
|
|
"""
|
|
|
Tests if the message gets added when the entity is deleted.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("entity_delete", args=(1,)))
|
|
|
|
|
|
response = self.client.post(reverse("entity_delete", args=(1,)),
|
|
|
{'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
|
|
|
follow=True)
|
|
|
|
|
|
self.assertContains(response, "Entity Test Entity 1 has been removed.")
|
|
|
|
|
|
def test_success_url(self):
|
|
|
"""
|
|
|
Validate that the success URL is set properly after delete.
|
|
|
"""
|
|
|
|
|
|
self.client.login(username="fullperms", password="fullperms")
|
|
|
|
|
|
response = self.client.get(reverse("entity_delete", args=(1,)))
|
|
|
|
|
|
response = self.client.post(reverse("entity_delete", args=(1,)),
|
|
|
{'csrfmiddlewaretoken': response.context['request'].META['CSRF_COOKIE']},
|
|
|
follow=True)
|
|
|
|
|
|
self.assertEqual(response.context["request"].META["PATH_INFO"], reverse("project", args=(1,)))
|