Skip to content

Commit

Permalink
update view tests, cleanup (#1706)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Aug 1, 2023
1 parent cbf108d commit 811a271
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 534 deletions.
97 changes: 94 additions & 3 deletions samplesheets/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@

from samplesheets.forms import TPL_DIR_FIELD
from samplesheets.io import SampleSheetIO
from samplesheets.models import Investigation, Assay, ISATab
from samplesheets.models import (
Investigation,
Assay,
ISATab,
IrodsDataRequest,
IRODS_REQUEST_ACTION_DELETE,
IRODS_REQUEST_STATUS_ACTIVE,
)
from samplesheets.rendering import (
SampleSheetTableBuilder,
STUDY_TABLE_CACHE_ITEM,
Expand All @@ -47,7 +54,10 @@
SHEET_DIR,
SHEET_DIR_SPECIAL,
)
from samplesheets.tests.test_models import SampleSheetModelMixin
from samplesheets.tests.test_models import (
SampleSheetModelMixin,
IrodsDataRequestMixin,
)
from samplesheets.tests.test_sheet_config import CONFIG_PATH_DEFAULT

# TODO: This should not be required (see issue #1578)
Expand Down Expand Up @@ -109,12 +119,13 @@
REMOTE_SITE_SECRET = build_secret()
EDIT_NEW_VALUE_STR = 'edited value'
DUMMY_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
IRODS_BACKEND_SKIP_MSG = 'iRODS backend not enabled in settings'
IRODS_FILE_PATH = '/sodarZone/path/test1.txt'
with open(CONFIG_PATH_DEFAULT) as fp:
CONFIG_DATA_DEFAULT = json.load(fp)
IRODS_BACKEND_ENABLED = (
True if 'omics_irods' in settings.ENABLED_BACKEND_PLUGINS else False
)
IRODS_BACKEND_SKIP_MSG = 'iRODS backend not enabled in settings'


# TODO: Add testing for study table cache updates
Expand Down Expand Up @@ -1555,6 +1566,86 @@ def test_render_no_permission(self):
self.assertRedirects(response, reverse('home'))


class TestIrodsDataRequestListView(IrodsDataRequestMixin, TestViewsBase):
"""Tests for IrodsDataRequestListView"""

def test_list(self):
"""Test GET request for listing delete requests"""
self.assertEqual(IrodsDataRequest.objects.count(), 0)
request = self.make_irods_request(
project=self.project,
action=IRODS_REQUEST_ACTION_DELETE,
path=IRODS_FILE_PATH,
status=IRODS_REQUEST_STATUS_ACTIVE,
user=self.user,
)
with self.login(self.user):
response = self.client.get(
reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
),
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 1)
self.assertEqual(response.context['object_list'][0], request)

def test_list_as_contributor_by_superuser(self):
"""Test GET as contibutor with request created by superuser"""
self.make_irods_request(
project=self.project,
action=IRODS_REQUEST_ACTION_DELETE,
path=IRODS_FILE_PATH,
status=IRODS_REQUEST_STATUS_ACTIVE,
user=self.user,
)
with self.login(self.user_contributor):
response = self.client.get(
reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
),
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 0)

def test_list_as_contributor2_by_contributor(self):
"""Test GET as contributor2 with request created by contributor"""
user_contributor2 = self.make_user('user_contributor2')
self.make_assignment(
self.project, user_contributor2, self.role_contributor
)
self.make_irods_request(
project=self.project,
action=IRODS_REQUEST_ACTION_DELETE,
path=IRODS_FILE_PATH,
status=IRODS_REQUEST_STATUS_ACTIVE,
user=self.user_contributor,
)
with self.login(user_contributor2):
response = self.client.get(
reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
),
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 0)

def test_list_empty(self):
"""Test GET request for empty list of delete requests"""
self.assertEqual(IrodsDataRequest.objects.count(), 0)
with self.login(self.user):
response = self.client.get(
reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
),
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 0)


class TestSheetRemoteSyncBase(
ProjectMixin,
RoleMixin,
Expand Down
14 changes: 11 additions & 3 deletions samplesheets/tests/test_views_ajax_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
IRODS_FILE_NAME,
IRODS_FILE_NAME2,
)
from samplesheets.views import IRODS_REQ_CREATE_ALERT as CREATE_ALERT
from samplesheets.views import IRODS_REQUEST_EVENT_CREATE as CREATE_ALERT
from samplesheets.views_ajax import ALERT_LIB_FILES_EXIST


Expand Down Expand Up @@ -304,6 +304,10 @@ def test_create_exists_as_admin_by_contributor(self):

def test_create_exists_as_contributor_by_contributor2(self):
"""Test creating as contributor if request by contributor2 exists"""
user_contributor2 = self.make_user('user_contributor2')
self.make_assignment_taskflow(
self.project, user_contributor2, self.role_contributor
)
with self.login(self.user_contrib):
self.client.post(
reverse(
Expand All @@ -315,7 +319,7 @@ def test_create_exists_as_contributor_by_contributor2(self):

self.assertEqual(IrodsDataRequest.objects.count(), 1)

with self.login(self.user_contrib2):
with self.login(user_contributor2):
response = self.client.post(
reverse(
'samplesheets:ajax_irods_request_create',
Expand Down Expand Up @@ -429,6 +433,10 @@ def test_delete_request_as_admin_by_contributor(self):

def test_delete_request_as_contributor_by_contributor2(self):
"""Test GET request for deleting an existing delete request"""
user_contributor2 = self.make_user('user_contributor2')
self.make_assignment_taskflow(
self.project, user_contributor2, self.role_contributor
)
with self.login(self.user_contrib):
self.client.post(
reverse(
Expand All @@ -441,7 +449,7 @@ def test_delete_request_as_contributor_by_contributor2(self):
self.assertEqual(IrodsDataRequest.objects.count(), 1)

# Delete request
with self.login(self.user_contrib2):
with self.login(user_contributor2):
response = self.client.post(
reverse(
'samplesheets:ajax_irods_request_delete',
Expand Down
11 changes: 3 additions & 8 deletions samplesheets/tests/test_views_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
IRODS_REQUEST_ACTION_DELETE,
)
from samplesheets.views import (
IRODS_REQ_CREATE_ALERT as CREATE_ALERT,
IRODS_REQ_ACCEPT_ALERT as ACCEPT_ALERT,
IRODS_REQ_REJECT_ALERT as REJECT_ALERT,
IRODS_REQUEST_EVENT_CREATE as CREATE_ALERT,
IRODS_REQUEST_EVENT_ACCEPT as ACCEPT_ALERT,
IRODS_REQUEST_EVENT_REJECT as REJECT_ALERT,
)
from samplesheets.views_api import IRODS_QUERY_ERROR_MSG

Expand Down Expand Up @@ -127,18 +127,13 @@ def setUp(self):
# Init users (owner = user_cat, superuser = user)
self.user_delegate = self.make_user('user_delegate')
self.user_contrib = self.make_user('user_contrib')
# TODO: Remove this
self.user_contrib2 = self.make_user('user_contrib2')
self.user_guest = self.make_user('user_guest')
self.make_assignment_taskflow(
self.project, self.user_delegate, self.role_delegate
)
self.make_assignment_taskflow(
self.project, self.user_contrib, self.role_contributor
)
self.make_assignment_taskflow(
self.project, self.user_contrib2, self.role_contributor
)
self.make_assignment_taskflow(
self.project, self.user_guest, self.role_guest
)
Expand Down
Loading

0 comments on commit 811a271

Please sign in to comment.