Skip to content

Commit

Permalink
add resource tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Feb 21, 2025
1 parent f50534a commit 28072e6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion coldfront/core/allocation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_allocation_list_access_proj_nonallocationuser(self):
self.assertEqual(len(response.context['item_list']), 1)
# confirm that resource_type of allocation is Storage
self.assertEqual(
response.context['item_list'][0].resource_type.name, 'Storage')
response.context['item_list'][0].resources.first().resource_type.name, 'Storage')

def test_allocation_list_access_nonproj_nonallocationuser(self):
"""non-ProjectUser non-AllocationUser User can see no Allocations
Expand Down
66 changes: 61 additions & 5 deletions coldfront/core/resource/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,73 @@ def test_storage_allocationuser_button_visibility(self):
self, self.admin_user, self.url, 'Edit Resource Allocations')


class ResourceAttributeCreateViewTest(ResourceViewBaseTest):
class StorageResourceAttributeCreateViewTest(ResourceViewBaseTest):
"""Tests for ResourceAttributeCreateView"""

def setUp(self):
self.url = f'/{self.cluster_resource.pk}/resourceattribute/add'
self.url = f'/resource/{self.storage_resource.pk}/resourceattribute/add'

def test_resource_attribute_create_access(self):
self.resource_access_tstbase(self.url)
utils.test_user_cannot_access(self, self.resource_allowed_user, self.url)
utils.test_user_cannot_access(self, self.pi_user, self.url)

def test_resource_attribute_create_form(self):
"""Test that the form is displayed correctly"""
utils.test_form_displayed_correctly(self, self.admin_user, self.url)

class ClusterResourceAttributeCreateViewTest(ResourceViewBaseTest):
"""Tests for ResourceAttributeCreateView"""

def setUp(self):
self.url = f'/resource/{self.cluster_resource.pk}/resourceattribute/add'

def test_resource_attribute_create_access(self):
self.resource_access_tstbase(self.url)
utils.test_user_cannot_access(self, self.resource_allowed_user, self.url)
utils.test_user_cannot_access(self, self.pi_user, self.url)


class StorageResourceAttributeDeleteViewTest(ResourceViewBaseTest):
"""Tests for ResourceAttributeDeleteView"""

def setUp(self):
self.url = f'/resource/{self.storage_resource.pk}/resourceattribute/delete'

def test_resource_attribute_create_access(self):
self.resource_access_tstbase(self.url)
utils.test_user_cannot_access(self, self.resource_allowed_user, self.url)
utils.test_user_cannot_access(self, self.pi_user, self.url)

class ClusterResourceAttributeDeleteViewTest(ResourceViewBaseTest):
"""Tests for ResourceAttributeDeleteView"""

def setUp(self):
self.url = f'/resource/{self.cluster_resource.pk}/resourceattribute/delete'

def test_resource_attribute_create_access(self):
self.resource_access_tstbase(self.url)
utils.test_user_cannot_access(self, self.resource_allowed_user, self.url)
utils.test_user_cannot_access(self, self.pi_user, self.url)


class StorageResourceAllocationsEditViewTest(ResourceViewBaseTest):
"""Tests for ResourceAllocationsEditView"""

def setUp(self):
self.url = f'/resource/{self.storage_resource.pk}/resourceallocations/edit'

def test_resource_allocation_edit_access(self):
self.client.force_login(self.admin_user, backend=BACKEND)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 302)
utils.test_user_cannot_access(self, self.resource_allowed_user, self.url)


class ClusterResourceAllocationsEditViewTest(ResourceViewBaseTest):
"""Tests for ResourceAllocationsEditView"""

def setUp(self):
self.url = f'/resource/{self.cluster_resource.pk}/resourceallocations/edit'

def test_resource_allocation_edit_access(self):
self.resource_access_tstbase(self.url)
utils.test_user_can_access(self, self.resource_allowed_user, self.url)
utils.test_user_cannot_access(self, self.pi_user, self.url)

0 comments on commit 28072e6

Please sign in to comment.