diff --git a/tests/test_service_catalog/test_forms/test_instance_form.py b/tests/test_service_catalog/test_forms/test_instance_form.py
new file mode 100644
index 000000000..d28f2367c
--- /dev/null
+++ b/tests/test_service_catalog/test_forms/test_instance_form.py
@@ -0,0 +1,46 @@
+from profiles.models import Permission
+from service_catalog.forms import InstanceFormRestricted
+from tests.test_service_catalog.base_test_request import BaseTestRequest
+
+
+class TestInstanceForm(BaseTestRequest):
+
+ def setUp(self):
+ super(TestInstanceForm, self).setUp()
+
+ def test_instance_form_restricted_with_admin(self):
+ parameters = {
+ 'instance': self.test_instance,
+ 'user': self.standard_user
+ }
+ data = {
+ 'name': 'test_instance_updated',
+ 'requester': self.standard_user_2,
+ }
+ form = InstanceFormRestricted(data, **parameters)
+ self.assertTrue(form.is_valid())
+ self.assertFalse('name' in form.fields)
+ self.assertFalse('requester' in form.fields)
+ self.team_member_role.permissions.add(
+ Permission.objects.get_by_natural_key(codename="rename_instance",
+ app_label="service_catalog",
+ model="instance"))
+ form = InstanceFormRestricted(data, **parameters)
+ self.assertTrue(form.is_valid())
+ self.assertTrue('name' in form.fields)
+ self.assertFalse('requester' in form.fields)
+ self.team_member_role.permissions.add(
+ Permission.objects.get_by_natural_key(codename="change_requester_on_instance",
+ app_label="service_catalog",
+ model="instance"))
+ form = InstanceFormRestricted(data, **parameters)
+ self.assertTrue('name' in form.fields)
+ self.assertTrue('requester' in form.fields)
+ # standard user 2 not part of the team yet so not a valid choice
+ self.assertFalse(form.is_valid())
+ # add standard user 2 to the team
+ self.test_quota_scope.add_user_in_role(self.standard_user_2, self.team_member_role)
+ self.test_quota_scope_team.add_user_in_role(self.standard_user_2, self.team_member_role)
+ form = InstanceFormRestricted(data, **parameters)
+ self.assertIn(self.standard_user_2, list(form.fields["requester"].queryset))
+ self.assertTrue(form.is_valid())
diff --git a/tests/test_service_catalog/test_views/test_admin/test_instance/test_instance_view.py b/tests/test_service_catalog/test_views/test_admin/test_instance/test_instance_view.py
index eb8310016..4c8c11acf 100644
--- a/tests/test_service_catalog/test_views/test_admin/test_instance/test_instance_view.py
+++ b/tests/test_service_catalog/test_views/test_admin/test_instance/test_instance_view.py
@@ -3,6 +3,7 @@
from django.urls import reverse
+from profiles.models import Permission
from service_catalog.models import Support, Instance, Request, InstanceState
from tests.test_service_catalog.base_test_request import BaseTestRequest
@@ -67,6 +68,30 @@ def test_instance_edit(self):
self.test_instance.refresh_from_db()
self.assertEqual(self.test_instance.name, "new_instance_name")
+ def test_instance_edit_standard_user(self):
+ self.client.login(username=self.standard_user, password=self.common_password)
+ url = reverse('service_catalog:instance_edit', kwargs=self.args)
+ response = self.client.post(url, data=self.edit_instance_data)
+ # by default is not allowed
+ self.assertEqual(403, response.status_code)
+ # give permission to the team
+ self.team_member_role.permissions.add(
+ Permission.objects.get_by_natural_key(codename="rename_instance",
+ app_label="service_catalog",
+ model="instance"),
+ Permission.objects.get_by_natural_key(codename="change_requester_on_instance",
+ app_label="service_catalog",
+ model="instance")
+ )
+ self.test_quota_scope.add_user_in_role(self.standard_user_2, self.team_member_role)
+ self.test_quota_scope_team.add_user_in_role(self.standard_user_2, self.team_member_role)
+ response = self.client.post(url, data=self.edit_instance_data)
+ # by default is not allowed
+ self.assertEqual(302, response.status_code)
+ self.test_instance.refresh_from_db()
+ self.assertEqual(self.test_instance.name, "new_instance_name")
+ self.assertEqual(self.test_instance.requester, self.standard_user_2)
+
def test_instance_edit_with_empty_spec(self):
old_spec = copy(self.test_instance.spec)
url = reverse('service_catalog:instance_edit', kwargs=self.args)