Skip to content

Commit

Permalink
refactor tests (#1991, #2001, #2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 13, 2024
1 parent 4486e60 commit 3ee4e53
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 372 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Changed
- Upgrade to django-sodar-core v1.0.2 (#1922)
- Upgrade to Postgres v16 (#1922)
- Upgrade Python and Vue app dependencies (#1922, #1959)
- Unify base test class naming (#2001)
- **Irodsinfo**
- Update REST API versioning (#1936)
- **Landingzones**
Expand All @@ -37,6 +38,8 @@ Changed
- Update REST API versioning (#1936)
- Update REST API views for OpenAPI compatibility (#1951)
- Send iRODS delete request emails to all addresses of user (#2000)
- **Taskflowbackend**
- Refactor task tests (#2002)

Removed
-------
Expand Down
6 changes: 3 additions & 3 deletions irodsinfo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
PLUGINS_DISABLE_IRODS.remove('omics_irods')


class TestIrodsinfoViewBase(TestCase):
class IrodsinfoViewTestBase(TestCase):
"""Base class for irodsinfo view tests"""

def setUp(self):
Expand All @@ -33,7 +33,7 @@ def setUp(self):
self.anonymous = None


class TestIrodsInfoView(TestIrodsinfoViewBase):
class TestIrodsInfoView(IrodsinfoViewTestBase):
"""Tests for IrodsInfoView"""

def test_render(self):
Expand All @@ -52,7 +52,7 @@ def test_render_no_backend(self):
self.assertFalse(response.context['irods_backend_enabled'])


class TestIrodsConfigView(TestIrodsinfoViewBase):
class TestIrodsConfigView(IrodsinfoViewTestBase):
"""Tests for IrodsConfigView"""

def test_serve(self):
Expand Down
4 changes: 2 additions & 2 deletions landingzones/tests/test_tasks_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import landingzones.constants as lc
from landingzones.tasks_taskflow import SetLandingZoneStatusTask
from landingzones.tests.test_views import TestViewsBase
from landingzones.tests.test_views import ViewTestBase


app_settings = AppSettingAPI()
Expand All @@ -24,7 +24,7 @@
TASK_NAME = 'set landing zone status'


class TestSetLandingZoneStatusTask(TestViewsBase):
class TestSetLandingZoneStatusTask(ViewTestBase):
"""Tests for SetLandingZoneStatusTask"""

def _get_task(self, force_fail=False):
Expand Down
14 changes: 7 additions & 7 deletions landingzones/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
ZONE_STATUS_INFO = 'Testing'


class TestViewsBase(
class ViewTestBase(
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
SampleSheetIOMixin,
LandingZoneMixin,
TestCase,
):
"""Base class for view testing"""
"""Base class for landingzones view testing"""

def setUp(self):
# Init roles
Expand Down Expand Up @@ -83,7 +83,7 @@ def setUp(self):
)


class TestProjectZonesView(TestViewsBase):
class TestProjectZonesView(ViewTestBase):
"""Tests for the project zones list view"""

def test_render_owner(self):
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_render_disable_superuser(self):
self.assertEqual(response.context['zone_access_disabled'], False)


class TestLandingZoneCreateView(TestViewsBase):
class TestLandingZoneCreateView(ViewTestBase):
"""Tests for the landing zone creation view"""

def test_render(self):
Expand All @@ -165,7 +165,7 @@ def test_render(self):
self.assertIsNotNone(form.fields['configuration'])


class TestLandingZoneUpdateView(TestViewsBase):
class TestLandingZoneUpdateView(ViewTestBase):
"""Tests for the landing zone update view"""

def test_render(self):
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_post_invalid_data(self):
self.assertEqual(landing_zone.description, 'description')


class TestLandingZoneMoveView(TestViewsBase):
class TestLandingZoneMoveView(ViewTestBase):
"""Tests for the landing zone validation and moving view"""

def test_render_invalid_status(self):
Expand All @@ -273,7 +273,7 @@ def test_render_invalid_status(self):
self.assertEqual(response.status_code, 302)


class TestLandingZoneDeleteView(TestViewsBase):
class TestLandingZoneDeleteView(ViewTestBase):
"""Tests for the landing zone deletion view"""

def test_render(self):
Expand Down
4 changes: 2 additions & 2 deletions landingzones/tests/test_views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from django.urls import reverse

from landingzones.tests.test_views import TestViewsBase
from landingzones.tests.test_views import ViewTestBase


class TestLandingZoneStatusGetAjaxView(TestViewsBase):
class TestLandingZoneStatusGetAjaxView(ViewTestBase):
"""Tests for the landing zone status getting Ajax view"""

def test_post(self):
Expand Down
8 changes: 4 additions & 4 deletions landingzones/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
INVALID_UUID = '11111111-1111-1111-1111-111111111111'


class TestLandingZoneAPIViewsBase(
class LandingZoneAPIViewTestBase(
LandingZoneMixin, SampleSheetIOMixin, APIViewTestBase
):
"""Base class for Landingzones API view testing"""
Expand Down Expand Up @@ -71,7 +71,7 @@ def setUp(self):
)


class TestLandingZoneListAPIView(TestLandingZoneAPIViewsBase):
class TestLandingZoneListAPIView(LandingZoneAPIViewTestBase):
"""Tests for LandingZoneListAPIView"""

def setUp(self):
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_get_finished_true(self):
self.assertEqual(len(response.data), 2)


class TestLandingZoneRetrieveAPIView(TestLandingZoneAPIViewsBase):
class TestLandingZoneRetrieveAPIView(LandingZoneAPIViewTestBase):
"""Tests for LandingZoneRetrieveAPIView"""

def test_get(self):
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_get_locked(self):
self.assertEqual(json.loads(response.content)['status_locked'], True)


class TestLandingZoneUpdateAPIView(TestLandingZoneAPIViewsBase):
class TestLandingZoneUpdateAPIView(LandingZoneAPIViewTestBase):
"""Tests for LandingZoneUpdateAPIView"""

def setUp(self):
Expand Down
6 changes: 3 additions & 3 deletions samplesheets/studyapps/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
INVALID_FILE_TYPE = 'INVALID_TYPE'


class TestStudyAppUtilsBase(
class StudyAppUtilsTestBase(
ProjectMixin, RoleAssignmentMixin, SampleSheetIOMixin, TestCase
):
"""Base class for samplesheets study app utils tests"""
Expand All @@ -50,7 +50,7 @@ def setUp(self):
)


class TestGetIGVOmitList(TestStudyAppUtilsBase):
class TestGetIGVOmitList(StudyAppUtilsTestBase):
"""Tests for get_igv_omit_list()"""

def test_get(self):
Expand Down Expand Up @@ -206,7 +206,7 @@ def test_path_omit_collections_middle(self):
self.assertFalse(check_igv_file_path(path, omit_list))


class TestGetIGVXML(TestStudyAppUtilsBase):
class TestGetIGVXML(StudyAppUtilsTestBase):
"""Tests for get_igv_xml()"""

def _get_all_paths(self):
Expand Down
10 changes: 5 additions & 5 deletions samplesheets/tests/test_views_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def setUp(self):
self.app_alert_model = self.app_alerts.get_model()


class TestIrodsDataRequestAPIViewBase(
class IrodsDataRequestAPIViewTestBase(
SampleSheetIOMixin, SampleSheetTaskflowMixin, TaskflowAPIViewTestBase
):
"""Base samplesheets API view test class for iRODS delete requests"""
Expand Down Expand Up @@ -734,7 +734,7 @@ def test_delete_invalid_url(self):
# NOTE: For TestIrodsDataRequestListAPIView, see test_views_api


class TestIrodsDataRequestCreateAPIView(TestIrodsDataRequestAPIViewBase):
class TestIrodsDataRequestCreateAPIView(IrodsDataRequestAPIViewTestBase):
"""Tests for IrodsDataRequestCreateAPIView"""

def test_create(self):
Expand Down Expand Up @@ -835,7 +835,7 @@ def test_create_multiple(self):


class TestIrodsDataRequestUpdateAPIView(
IrodsDataRequestMixin, TestIrodsDataRequestAPIViewBase
IrodsDataRequestMixin, IrodsDataRequestAPIViewTestBase
):
"""Tests for IrodsDataRequestUpdateAPIView"""

Expand Down Expand Up @@ -957,7 +957,7 @@ def test_patch_superuser(self):


class TestIrodsDataRequestAcceptAPIView(
IrodsDataRequestMixin, TestIrodsDataRequestAPIViewBase
IrodsDataRequestMixin, IrodsDataRequestAPIViewTestBase
):
"""Tests for IrodsDataRequestAcceptAPIView"""

Expand Down Expand Up @@ -1060,7 +1060,7 @@ def test_accept_already_accepted(self):


class TestIrodsDataRequestRejectAPIView(
IrodsDataRequestMixin, TestIrodsDataRequestAPIViewBase
IrodsDataRequestMixin, IrodsDataRequestAPIViewTestBase
):
"""Tests for IrodsDataRequestRejectAPIView"""

Expand Down
82 changes: 20 additions & 62 deletions samplesheets/tests/test_views_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,12 @@ class TestIrodsDataRequestAcceptBatchView(
):
"""Tests for IrodsDataRequestAcceptBatchView"""

@classmethod
def _get_request_uuids(cls):
return ','.join(
[str(r.sodar_uuid) for r in IrodsDataRequest.objects.all()]
)

def setUp(self):
super().setUp()
self.create_url = reverse(
Expand All @@ -1910,6 +1916,10 @@ def setUp(self):
'samplesheets:irods_request_accept_batch',
kwargs={'project': self.project.sodar_uuid},
)
self.list_url = reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
)

def test_get(self):
"""Test IrodsDataRequestAcceptBatchView GET"""
Expand All @@ -1932,27 +1942,12 @@ def test_get(self):

with self.login(self.user):
response = self.client.post(
self.accept_url,
{
'irods_requests': ','.join(
[
str(irods_request.sodar_uuid)
for irods_request in IrodsDataRequest.objects.all()
]
),
},
self.accept_url, {'irods_requests': self._get_request_uuids()}
)
self.assertEqual(response.status_code, 200)
paths = [r.path for r in IrodsDataRequest.objects.all()]
self.assertEqual(
response.context['affected_object_paths'],
sorted(
set(
[
irods_request.path
for irods_request in IrodsDataRequest.objects.all()
]
)
),
response.context['affected_object_paths'], sorted(set(paths))
)
self.assertEqual(len(response.context['request_objects']), 2)
self.assertEqual(
Expand Down Expand Up @@ -1981,14 +1976,7 @@ def test_get_coll(self):
with self.login(self.user):
response = self.client.post(
self.accept_url,
{
'irods_requests': ','.join(
[
str(irods_request.sodar_uuid)
for irods_request in IrodsDataRequest.objects.all()
]
),
},
{'irods_requests': self._get_request_uuids()},
)
self.assertEqual(response.status_code, 200)
self.assertEqual(
Expand All @@ -2007,10 +1995,7 @@ def test_post(self):
with self.login(self.user_contributor):
self.client.post(self.create_url, self.post_data)
self.client.post(
reverse(
'samplesheets:irods_request_create',
kwargs={'project': self.project.sodar_uuid},
),
self.create_url,
self.post_data2,
)

Expand All @@ -2024,23 +2009,12 @@ def test_post(self):
response = self.client.post(
self.accept_url,
{
'irods_requests': ','.join(
[
str(irods_request.sodar_uuid)
for irods_request in IrodsDataRequest.objects.all()
]
)
'irods_requests': self._get_request_uuids()
+ ',', # Add trailing comma to test for correct splitting
'confirm': True,
},
)
self.assertRedirects(
response,
reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
),
)
self.assertRedirects(response, self.list_url)
self.assertEqual(len(list(get_messages(response.wsgi_request))), 2)
self.assertEqual(
list(get_messages(response.wsgi_request))[-1].message,
Expand Down Expand Up @@ -2104,12 +2078,7 @@ def test_post_invalid_data(self):
response = self.client.post(
self.accept_url,
{
'irods_requests': ','.join(
[
str(irods_request.sodar_uuid)
for irods_request in IrodsDataRequest.objects.all()
]
)
'irods_requests': self._get_request_uuids()
+ ',', # Add trailing comma to test for correct splitting
'confirm': False,
},
Expand Down Expand Up @@ -2147,23 +2116,12 @@ def test_post_lock_failure(self):
response = self.client.post(
self.accept_url,
{
'irods_requests': ','.join(
[
str(irods_request.sodar_uuid)
for irods_request in IrodsDataRequest.objects.all()
]
)
'irods_requests': self._get_request_uuids()
+ ',', # Add trailing comma to test for correct splitting
'confirm': True,
},
)
self.assertRedirects(
response,
reverse(
'samplesheets:irods_requests',
kwargs={'project': self.project.sodar_uuid},
),
)
self.assertRedirects(response, self.list_url)
obj = IrodsDataRequest.objects.first()
obj.refresh_from_db()
self.assertEqual(obj.status, IRODS_REQUEST_STATUS_FAILED)
Expand Down
Loading

0 comments on commit 3ee4e53

Please sign in to comment.