Skip to content

Commit

Permalink
fix: small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Aug 10, 2023
1 parent 6b6b463 commit f1369bb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 42 deletions.
63 changes: 41 additions & 22 deletions samplesheets/tests/test_permissions_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,14 @@ class TestIrodsAccessTicketAPIViewBase(

def create_ticket(self):
"""Helper function to create a ticket"""
path = self.coll.path + '/ticket1'
ticket_str = 'ticket'
label = 'label'
date_expires = (timezone.localtime() + timedelta(days=1)).isoformat()
# Create ticket in database and iRODS
ticket = self.make_irods_ticket(
study=self.study,
assay=self.assay,
path=path,
path=self.coll.path + '/ticket1',
user=self.user_owner,
ticket=ticket_str,
label=label,
date_expires=date_expires,
ticket='ticket',
label='label',
date_expires=(timezone.localtime() + timedelta(days=1)).isoformat(),
)
return ticket

Expand Down Expand Up @@ -204,6 +199,11 @@ def test_get(self):
self.assert_response_api(self.url, bad_users, 403)
self.assert_response_api(self.url, self.anonymous, 401)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_get_anon(self):
"""Test get() with anonymous access"""
self.assert_response_api(self.url, self.anonymous, 401)

def test_get_archive(self):
"""Test get() with archived project"""
self.project.set_archive()
Expand All @@ -212,11 +212,11 @@ def test_get_archive(self):
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest_cat,
self.user_finder_cat,
self.user_guest,
self.user_no_roles,
]
Expand Down Expand Up @@ -258,6 +258,11 @@ def test_get(self):
self.assert_response_api(self.url, bad_users, 403)
self.assert_response_api(self.url, self.anonymous, 401)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_get_anon(self):
"""Test get() with anonymous access"""
self.assert_response_api(self.url, self.anonymous, 401)

def test_get_archive(self):
"""Test get() with archived project"""
self.project.set_archive()
Expand All @@ -266,11 +271,11 @@ def test_get_archive(self):
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest_cat,
self.user_finder_cat,
self.user_guest,
self.user_no_roles,
]
Expand Down Expand Up @@ -305,8 +310,8 @@ def setUp(self):
def _delete_ticket(self):
"""Delete ticket created in setUp()"""
access_ticket = IrodsAccessTicket.objects.all().first()
ticket = access_ticket.ticket
self.irods_backend.delete_ticket(self.irods, ticket)
ticket_str = access_ticket.ticket
self.irods_backend.delete_ticket(self.irods, ticket_str)
access_ticket.delete()

def test_create(self):
Expand Down Expand Up @@ -341,6 +346,13 @@ def test_create(self):
self.url, self.anonymous, 401, method='post', data=self.post_data
)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_create_anon(self):
"""Test post() with anonymous access"""
self.assert_response_api(
self.url, self.anonymous, 401, method='post', data=self.post_data
)

def test_create_archive(self):
"""Test post() with archived project"""
self.project.set_archive()
Expand All @@ -349,11 +361,11 @@ def test_create_archive(self):
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest_cat,
self.user_finder_cat,
self.user_guest,
self.user_no_roles,
]
Expand Down Expand Up @@ -410,6 +422,13 @@ def test_update(self):
self.url, self.anonymous, 401, method='put', data=self.post_data
)

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_update_anon(self):
"""Test put() with anonymous access"""
self.assert_response_api(
self.url, self.anonymous, 401, method='put', data=self.post_data
)

def test_update_archive(self):
"""Test put() with archived project"""
self.project.set_archive()
Expand All @@ -418,11 +437,11 @@ def test_update_archive(self):
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest_cat,
self.user_finder_cat,
self.user_guest,
self.user_no_roles,
]
Expand All @@ -437,7 +456,7 @@ def test_update_archive(self):
)


class TestIrodsAccessTicketDeleteAPIView(TestIrodsAccessTicketAPIViewBase):
class TestIrodsAccessTicketDestroyAPIView(TestIrodsAccessTicketAPIViewBase):
"""Test permissions for IrodsAccessTicketDeleteAPIView"""

def create_irods_ticket(self):
Expand Down Expand Up @@ -548,11 +567,11 @@ def test_get_archive(self):
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest_cat,
self.user_finder_cat,
self.user_guest,
self.user_no_roles,
]
Expand Down
40 changes: 23 additions & 17 deletions samplesheets/tests/test_views_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from django.urls import reverse
from django.utils import timezone

from appalerts.models import AppAlert

# Projectroles dependency
from projectroles.models import SODAR_CONSTANTS
from projectroles.plugins import get_backend_api
Expand Down Expand Up @@ -66,6 +64,7 @@
IRODS_FILE_NAME2,
INVALID_REDIS_URL,
TICKET_STR,
TICKET_LABEL,
)

# SODAR constants
Expand Down Expand Up @@ -356,9 +355,9 @@ class TestIrodsAccessTicketListAPIView(TestIrodsAccessTicketAPIViewBase):

def setUp(self):
super().setUp()
self.ticket_str = 'ticket'
self.ticket_str = TICKET_STR
self.path = self.coll.path
self.label = 'label'
self.label = TICKET_LABEL
self.date_expires = None
self.url = reverse(
'samplesheets:api_irods_ticket_list',
Expand Down Expand Up @@ -465,9 +464,9 @@ class TestIrodsAccessTicketRetrieveAPIView(TestIrodsAccessTicketAPIViewBase):

def setUp(self):
super().setUp()
self.ticket_str = 'ticket'
self.ticket_str = TICKET_STR
self.path = self.coll.path
self.label = 'label'
self.label = TICKET_LABEL
self.date_expires = None
self.ticket = self.make_irods_ticket(
study=self.study,
Expand Down Expand Up @@ -529,7 +528,7 @@ class TestIrodsAccessTicketCreateAPIView(TestIrodsAccessTicketAPIViewBase):
def setUp(self):
super().setUp()
self.path = self.coll.path
self.label = 'label'
self.label = TICKET_LABEL
self.date_expires = (
timezone.localtime() + timedelta(days=1)
).isoformat()
Expand Down Expand Up @@ -572,7 +571,9 @@ def test_create(self):
self.assertEqual(self.get_tl_event_count('create'), 1)
self.assertEqual(self.get_app_alert_count('create'), 1)
self.assertEqual(
AppAlert.objects.filter(alert_name='irods_ticket_create')
self.app_alert_model.objects.filter(
alert_name='irods_ticket_create'
)
.first()
.user,
self.user_delegate,
Expand Down Expand Up @@ -614,7 +615,9 @@ def test_create_contributor(self):
self.assertEqual(self.get_tl_event_count('create'), 1)
self.assertEqual(self.get_app_alert_count('create'), 2)
self.assertEqual(
AppAlert.objects.filter(alert_name='irods_ticket_create')
self.app_alert_model.objects.filter(
alert_name='irods_ticket_create'
)
.first()
.user,
self.user_delegate,
Expand Down Expand Up @@ -710,14 +713,13 @@ def test_post_existing_ticket(self):
self.assertEqual(self.get_app_alert_count('create'), 0)



class TestIrodsAccessTicketUpdateAPIView(TestIrodsAccessTicketAPIViewBase):
"""Tests for IrodsAccessTicketUpdateAPIView"""

def setUp(self):
super().setUp()
self.ticket_str = 'ticket'
self.label = 'label'
self.ticket_str = TICKET_STR
self.label = TICKET_LABEL
self.date_expires = None
self.ticket = self.make_irods_ticket(
study=self.study,
Expand Down Expand Up @@ -775,7 +777,9 @@ def test_update(self):
self.assertEqual(self.get_tl_event_count('update'), 1)
self.assertEqual(self.get_app_alert_count('update'), 2)
self.assertEqual(
AppAlert.objects.filter(alert_name='irods_ticket_update')
self.app_alert_model.objects.filter(
alert_name='irods_ticket_update'
)
.first()
.user,
self.user_delegate,
Expand Down Expand Up @@ -816,13 +820,13 @@ def test_update_invalid_date(self):
self.assertEqual(self.get_app_alert_count('update'), 0)


class TestIrodsAccessTicketDeleteAPIView(TestIrodsAccessTicketAPIViewBase):
class TestIrodsAccessTicketDestroyAPIView(TestIrodsAccessTicketAPIViewBase):
"""Tests for IrodsAccessTicketDeleteAPIView"""

def setUp(self):
super().setUp()
self.ticket_str = 'ticket'
self.label = 'label'
self.ticket_str = TICKET_STR
self.label = TICKET_LABEL
self.date_expires = (
timezone.localtime() + timedelta(days=1)
).isoformat()
Expand Down Expand Up @@ -864,7 +868,9 @@ def test_delete(self):
self.assertEqual(self.get_tl_event_count('delete'), 1)
self.assertEqual(self.get_app_alert_count('delete'), 2)
self.assertEqual(
AppAlert.objects.filter(alert_name='irods_ticket_delete')
self.app_alert_model.objects.filter(
alert_name='irods_ticket_delete'
)
.first()
.user,
self.user_delegate,
Expand Down
2 changes: 1 addition & 1 deletion samplesheets/tests/test_views_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
SOURCE_ID = '0815'
SAMPLE_ID = '0815-N1'
INVALID_REDIS_URL = 'redis://127.0.0.1:6666/0'
TICKET_LABEL = 'TestTicket'
TICKET_LABEL_UPDATED = 'TestTicketUpdated'
TICKET_STR = 'q657xxx3i2x2b8vj'
TICKET_LABEL = 'TestTicket'
IRODS_REQUEST_DESC_UPDATE = 'Updated'


Expand Down
2 changes: 1 addition & 1 deletion samplesheets/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
),
path(
route='api/irods/ticket/delete/<uuid:irodsaccessticket>',
view=views_api.IrodsAccessTicketDeleteAPIView.as_view(),
view=views_api.IrodsAccessTicketDestroyAPIView.as_view(),
name='api_irods_ticket_delete',
),
path(
Expand Down
2 changes: 1 addition & 1 deletion samplesheets/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def put(self, request, *args, **kwargs):
return Response(context, status=status.HTTP_200_OK)


class IrodsAccessTicketDeleteAPIView(
class IrodsAccessTicketDestroyAPIView(
IrodsAccessTicketModifyMixin, SODARAPIBaseProjectMixin, DestroyAPIView
):
"""
Expand Down

0 comments on commit f1369bb

Please sign in to comment.