Skip to content

Commit

Permalink
finalize refactoring, update tests (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jul 21, 2023
1 parent b10d576 commit 551cd35
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 196 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Added
- ``BatchCalculateChecksumTask`` iRODS task (#1634)
- Automated generation of missing checksums in ``zone_move`` flow (#1634)
- Cleanup of trash collections in testing (#1658)
- ``TaskflowPermissionTestBase`` base test class (#1718)

Changed
-------
Expand Down
4 changes: 2 additions & 2 deletions irodsbackend/tests/test_api_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 SampleSheetTaskflowMixin

# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowbackendTestBase
from taskflowbackend.tests.base import TaskflowViewTestBase


# SODAR constants
Expand Down Expand Up @@ -48,7 +48,7 @@ class TestIrodsBackendAPITaskflow(
SampleSheetIOMixin,
LandingZoneMixin,
SampleSheetTaskflowMixin,
TaskflowbackendTestBase,
TaskflowViewTestBase,
):
"""Tests for the API in the irodsbackend app with Taskflow and iRODS"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

# Projectroles dependency
from projectroles.models import SODAR_CONSTANTS
from projectroles.tests.test_permissions import TestPermissionMixin

# Samplesheets dependency
from samplesheets.tests.test_io import (
SampleSheetIOMixin,
SHEET_DIR,
)
from samplesheets.tests.test_io import SampleSheetIOMixin, SHEET_DIR
from samplesheets.tests.test_views_taskflow import SampleSheetTaskflowMixin

# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowbackendTestBase
from taskflowbackend.tests.base import TaskflowPermissionTestBase


# SODAR constants
Expand All @@ -29,49 +25,18 @@


class TestIrodsbackendPermissions(
TestPermissionMixin,
SampleSheetIOMixin,
SampleSheetTaskflowMixin,
TaskflowbackendTestBase,
TaskflowPermissionTestBase,
):
"""Tests for irodsbackend API view permissions"""

def setUp(self):
super().setUp()
# Init users
self.superuser = self.user # HACK
self.anonymous = None
self.user_owner = self.make_user('user_owner')
self.user_delegate = self.make_user('user_delegate')
self.user_contributor = self.make_user('user_contributor')
self.user_guest = self.make_user('user_guest')
self.user_no_roles = self.make_user('user_no_roles')

# Set up project with taskflow
self.project, self.owner_as = self.make_project_taskflow(
title='TestProject',
type=PROJECT_TYPE_PROJECT,
parent=self.category,
owner=self.user_owner,
description='description',
)

# Set up assignments with taskflow
self.delegate_as = self.make_assignment_taskflow(
self.project, self.user_delegate, self.role_delegate
)
self.contributor_as = self.make_assignment_taskflow(
self.project, self.user_contributor, self.role_contributor
)
self.guest_as = self.make_assignment_taskflow(
self.project, self.user_guest, self.role_guest
)

# Set up investigation
self.investigation = self.import_isa_from_file(SHEET_PATH, self.project)
# Create iRODS collections
self.make_irods_colls(self.investigation)

# Set up test paths
self.project_path = self.irods_backend.get_path(self.project)
self.sample_path = self.irods_backend.get_sample_path(self.project)
Expand All @@ -83,13 +48,16 @@ def test_stats_get(self):
)
good_users = [
self.superuser,
self.user_owner_cat, # Inherited owner
self.user_owner_cat, # Inherited
self.user_delegate_cat, # Inherited
self.user_contributor_cat, # Inherited
self.user_guest_cat, # Inherited
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest,
]
bad_users = [self.user_no_roles, self.anonymous]
bad_users = [self.user_finder_cat, self.user_no_roles, self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 403)
self.project.set_public()
Expand All @@ -98,7 +66,7 @@ def test_stats_get(self):

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_stats_get_anon(self):
"""Test stats API view with anonymous access"""
"""Test stats Ajax view with anonymous access"""
self.project.set_public()
url = self.irods_backend.get_url(
view='stats', project=self.project, path=self.sample_path
Expand All @@ -107,21 +75,25 @@ def test_stats_get_anon(self):

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_stats_get_anon_no_perms(self):
"""Test stats API view with anonymous access and no perms to collection"""
"""Test stats Ajax view with anonymous access and no collection perms"""
self.project.set_public()
url = self.irods_backend.get_url(
view='stats', project=self.project, path=self.project_path
)
self.assert_response(url, self.anonymous, 403)

def test_stats_get_not_in_project(self):
"""Test stats API view GET with path not in project"""
"""Test stats Ajax view GET with path not in project"""
url = self.irods_backend.get_url(
view='stats', project=self.project, path=NON_PROJECT_PATH
)
bad_users = [
self.superuser,
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,
Expand All @@ -132,7 +104,7 @@ def test_stats_get_not_in_project(self):
self.assert_response(url, bad_users, 400)

def test_stats_get_no_perms(self):
"""Test stats API view GET without collection perms"""
"""Test stats Ajax view GET without collection perms"""
test_path = self.project_path + '/' + TEST_COLL_NAME
self.irods.collections.create(test_path) # NOTE: No perms given

Expand All @@ -142,10 +114,14 @@ def test_stats_get_no_perms(self):
good_users = [
self.superuser,
self.user_owner_cat,
self.user_delegate_cat,
self.user_owner,
self.user_delegate,
]
bad_users = [
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_contributor,
self.user_guest,
self.user_no_roles,
Expand All @@ -155,7 +131,7 @@ def test_stats_get_no_perms(self):
self.assert_response(url, bad_users, 403)

def test_stats_post(self):
"""Test stats API view POST"""
"""Test stats Ajax view POST"""
url = self.irods_backend.get_url(
view='stats',
project=self.project,
Expand All @@ -167,31 +143,37 @@ def test_stats_post(self):
good_users = [
self.superuser,
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest,
]
bad_users = [self.user_no_roles, self.anonymous]
bad_users = [self.user_finder_cat, self.user_no_roles, self.anonymous]
self.assert_response(
url, good_users, 200, method='POST', data=post_data
)
self.assert_response(url, bad_users, 403, method='POST', data=post_data)

def test_list_get(self):
"""Test object list API view GET"""
"""Test object list GET"""
url = self.irods_backend.get_url(
view='list', project=self.project, path=self.sample_path, md5=0
)
good_users = [
self.superuser,
self.user_owner_cat,
self.user_delegate_cat,
self.user_contributor_cat,
self.user_guest_cat,
self.user_owner,
self.user_delegate,
self.user_contributor,
self.user_guest,
]
bad_users = [self.user_no_roles, self.anonymous]
bad_users = [self.user_finder_cat, self.user_no_roles, self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 403)
self.project.set_public()
Expand All @@ -200,7 +182,7 @@ def test_list_get(self):

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_list_get_anon(self):
"""Test object list API view GET with anonymous access"""
"""Test object list GET with anonymous access"""
url = self.irods_backend.get_url(
view='list', project=self.project, path=self.sample_path, md5=0
)
Expand All @@ -209,7 +191,7 @@ def test_list_get_anon(self):

@override_settings(PROJECTROLES_ALLOW_ANONYMOUS=True)
def test_list_get_anon_no_perms(self):
"""Test object list API view GET with anonymous access and no permission"""
"""Test object list GET with anon access and no permission"""
url = self.irods_backend.get_url(
view='list', project=self.project, path=self.project_path, md5=0
)
Expand All @@ -224,6 +206,10 @@ def test_list_get_not_in_project(self):
bad_users = [
self.superuser,
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,
Expand All @@ -244,10 +230,14 @@ def test_list_get_no_perms(self):
good_users = [
self.superuser,
self.user_owner_cat,
self.user_delegate_cat,
self.user_owner,
self.user_delegate,
]
bad_users = [
self.user_contributor_cat,
self.user_guest_cat,
self.user_finder_cat,
self.user_contributor,
self.user_guest,
self.user_no_roles,
Expand Down
4 changes: 2 additions & 2 deletions irodsbackend/tests/test_plugins_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from projectroles.plugins import BackendPluginPoint

# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowbackendTestBase
from taskflowbackend.tests.base import TaskflowViewTestBase


# SODAR constants
Expand All @@ -20,7 +20,7 @@
TEST_FILE = 'test.txt'


class TestGetStatistics(TaskflowbackendTestBase):
class TestGetStatistics(TaskflowViewTestBase):
"""Tests for get_statistics()"""

def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions irodsbackend/tests/test_signals_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from django.test import override_settings

# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowbackendTestBase
from taskflowbackend.tests.base import TaskflowViewTestBase


USER_NAME = 'test_user'


class TestCreateIrodsUser(TaskflowbackendTestBase):
class TestCreateIrodsUser(TaskflowViewTestBase):
"""Tests for create_irods_user signal"""

def setUp(self):
Expand Down
6 changes: 2 additions & 4 deletions landingzones/tests/test_permissions_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

# Projectroles dependency
from projectroles.models import SODAR_CONSTANTS
from projectroles.tests.test_permissions import TestPermissionMixin

# Samplesheets dependency
from samplesheets.tests.test_io import SampleSheetIOMixin, SHEET_DIR

from taskflowbackend.tests.base import TaskflowAPIPermissionTestBase
from taskflowbackend.tests.base import TaskflowPermissionTestBase
from landingzones.tests.test_models import (
LandingZoneMixin,
ZONE_TITLE,
Expand All @@ -36,8 +35,7 @@ class TestLandingZonePermissionTaskflowBase(
LandingZoneMixin,
LandingZoneTaskflowMixin,
SampleSheetIOMixin,
TestPermissionMixin,
TaskflowAPIPermissionTestBase,
TaskflowPermissionTestBase,
):
"""Base view for landingzones permissions tests"""

Expand Down
4 changes: 2 additions & 2 deletions landingzones/tests/test_plugins_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowbackendTestBase
from taskflowbackend.tests.base import TaskflowViewTestBase

from landingzones.tests.test_models import LandingZoneMixin
from landingzones.tests.test_views_taskflow import LandingZoneTaskflowMixin
Expand Down Expand Up @@ -44,7 +44,7 @@ class TestPerformProjectSync(
SampleSheetIOMixin,
SampleSheetPublicAccessMixin,
SampleSheetTaskflowMixin,
TaskflowbackendTestBase,
TaskflowViewTestBase,
):
"""Tests for perform_project_modify()"""

Expand Down
4 changes: 2 additions & 2 deletions landingzones/tests/test_tasks_celery_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from samplesheets.tests.test_views_taskflow import SampleSheetTaskflowMixin

# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowbackendTestBase
from taskflowbackend.tests.base import TaskflowViewTestBase

from landingzones.tasks_celery import TriggerZoneMoveTask
from landingzones.tests.test_models import LandingZoneMixin
Expand Down Expand Up @@ -45,7 +45,7 @@ class TestTriggerZoneMoveTask(
LandingZoneMixin,
LandingZoneTaskflowMixin,
SampleSheetTaskflowMixin,
TaskflowbackendTestBase,
TaskflowViewTestBase,
):
"""Tests for the automated zone move triggering task"""

Expand Down
2 changes: 1 addition & 1 deletion landingzones/tests/test_views_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def setUp(self):
self.irods = self.irods_backend.get_session_obj()

# Make project with owner in Taskflow and Django
self.project, self.owner_as = self.make_project_api_taskflow(
self.project, self.owner_as = self.make_project_taskflow(
title='TestProject',
type=PROJECT_TYPE_PROJECT,
parent=self.category,
Expand Down
Loading

0 comments on commit 551cd35

Please sign in to comment.