Skip to content

Commit

Permalink
refactor api views (wip) (#1706, #1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jul 25, 2023
1 parent 652ec79 commit 4af6d61
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 233 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Added
- Enable ``tumor_normal_dna`` ISA-Tab template (#1697)
- General iRODS access ticket management for assay collections (#804, #1717)
- Disabled row delete button tooltips (#1731)
- ``IrodsDataRequest`` REST API views (#1588, #1706)
- ``IrodsDataRequest`` REST API views (#1588, #1706, #1734)
- Davrods links in iRODS delete request list (#1339)
- Batch accepting and rejecting for iRODS delete requests (#1340)
- **Taskflowbackend**
Expand Down
6 changes: 3 additions & 3 deletions samplesheets/tests/test_permissions_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from samplesheets.tests.test_views_taskflow import (
SampleSheetTaskflowMixin,
TEST_FILE_NAME,
IRODS_FILE_NAME,
)


Expand Down Expand Up @@ -111,8 +111,8 @@ def setUp(self):
# Set up iRODS data
self.make_irods_colls(self.investigation)
self.assay_path = self.irods_backend.get_path(self.assay)
self.path = os.path.join(self.assay_path, TEST_FILE_NAME)
self.path_md5 = os.path.join(self.assay_path, f'{TEST_FILE_NAME}.md5')
self.path = os.path.join(self.assay_path, IRODS_FILE_NAME)
self.path_md5 = os.path.join(self.assay_path, f'{IRODS_FILE_NAME}.md5')
# Create objects
self.file_obj = self.irods.data_objects.create(self.path)
self.md5_obj = self.irods.data_objects.create(self.path_md5)
Expand Down
10 changes: 5 additions & 5 deletions samplesheets/tests/test_views_ajax_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from samplesheets.tests.test_views_taskflow import (
TestIrodsDataRequestViewsBase,
SampleSheetTaskflowMixin,
TEST_FILE_NAME2,
IRODS_FILE_NAME2,
)
from samplesheets.views import IRODS_REQ_CREATE_ALERT as CREATE_ALERT
from samplesheets.views_ajax import ALERT_LIB_FILES_EXIST
Expand Down Expand Up @@ -330,8 +330,8 @@ def test_create_exists_as_contributor_by_contributor2(self):

def test_create_multiple(self):
"""Test creating multiple delete requests"""
path2 = os.path.join(self.assay_path, TEST_FILE_NAME2)
path2_md5 = os.path.join(self.assay_path, TEST_FILE_NAME2 + '.md5')
path2 = os.path.join(self.assay_path, IRODS_FILE_NAME2)
path2_md5 = os.path.join(self.assay_path, IRODS_FILE_NAME2 + '.md5')
self.irods.data_objects.create(path2)
self.irods.data_objects.create(path2_md5)

Expand Down Expand Up @@ -473,8 +473,8 @@ def test_delete_no_request(self):

def test_delete_one_of_multiple(self):
"""Test deleting one of multiple requests"""
path2 = os.path.join(self.assay_path, TEST_FILE_NAME2)
path2_md5 = os.path.join(self.assay_path, TEST_FILE_NAME2 + '.md5')
path2 = os.path.join(self.assay_path, IRODS_FILE_NAME2)
path2_md5 = os.path.join(self.assay_path, IRODS_FILE_NAME2 + '.md5')
self.irods.data_objects.create(path2)
self.irods.data_objects.create(path2_md5)

Expand Down
64 changes: 63 additions & 1 deletion samplesheets/tests/test_views_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for REST API views in the samplesheets app"""

import json
import os

from django.test import override_settings
from django.urls import reverse
Expand All @@ -15,12 +16,23 @@
# Sodarcache dependency
from sodarcache.models import JSONCacheItem

# Timeline dependency
from timeline.models import ProjectEvent

# Landingzones dependency
from landingzones.models import LandingZone
from landingzones.tests.test_models import LandingZoneMixin

from samplesheets.io import SampleSheetIO
from samplesheets.models import Investigation, Assay, GenericMaterial, ISATab
from samplesheets.models import (
Investigation,
Assay,
GenericMaterial,
ISATab,
IrodsDataRequest,
IRODS_REQUEST_ACTION_DELETE,
IRODS_REQUEST_STATUS_ACTIVE,
)
from samplesheets.rendering import (
SampleSheetTableBuilder,
STUDY_TABLE_CACHE_ITEM,
Expand All @@ -31,6 +43,7 @@
SHEET_DIR,
SHEET_DIR_SPECIAL,
)
from samplesheets.tests.test_models import IrodsDataRequestMixin
from samplesheets.tests.test_sheet_config import SheetConfigMixin
from samplesheets.tests.test_views import (
TestViewsBase,
Expand Down Expand Up @@ -58,6 +71,7 @@
SHEET_NAME_ALT = 'i_small.zip'
SHEET_PATH_ALT = SHEET_DIR + 'i_small2_alt.zip'
SHEET_PATH_NO_PLUGIN_ASSAY = SHEET_DIR_SPECIAL + 'i_small_assay_no_plugin.zip'
IRODS_FILE_NAME = 'test1.txt'
IRODS_FILE_MD5 = '0b26e313ed4a7ca6904b0e9369e5b957'


Expand Down Expand Up @@ -609,6 +623,54 @@ def test_get_json(self):
self.assertEqual(response.data, expected)


class TestIrodsDataRequestDestroyAPIView(
IrodsDataRequestMixin, TestSampleSheetAPIBase
):
"""Tests for IrodsDataRequestDestroyAPIView"""

def _assert_tl_count(self, count):
"""Assert timeline ProjectEvent count"""
self.assertEqual(
ProjectEvent.objects.filter(
event_name='irods_request_delete'
).count(),
count,
)

def setUp(self):
super().setUp()
# Import investigation
self.investigation = self.import_isa_from_file(SHEET_PATH, self.project)
self.study = self.investigation.studies.first()
self.assay = self.study.assays.first()
# Set up iRODS backend and paths
self.irods_backend = get_backend_api('omics_irods')
self.assay_path = self.irods_backend.get_path(self.assay)
self.obj_path = os.path.join(self.assay_path, IRODS_FILE_NAME)

def test_delete(self):
"""Test deleting a request"""
self._assert_tl_count(0)
obj = self.make_irods_request(
project=self.project,
action=IRODS_REQUEST_ACTION_DELETE,
path=self.obj_path,
status=IRODS_REQUEST_STATUS_ACTIVE,
user=self.user,
)
self.assertEqual(IrodsDataRequest.objects.count(), 1)
with self.login(self.user):
response = self.client.delete(
reverse(
'samplesheets:api_irods_request_delete',
kwargs={'irodsdatarequest': obj.sodar_uuid},
)
)
self.assertEqual(response.status_code, 204)
self.assertEqual(IrodsDataRequest.objects.count(), 0)
self._assert_tl_count(1)


class TestSampleDataFileExistsAPIView(TestSampleSheetAPIBase):
"""Tests for SampleDataFileExistsAPIView"""

Expand Down
Loading

0 comments on commit 4af6d61

Please sign in to comment.