Skip to content

Commit

Permalink
refactor taskflow tests (#1718, #1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jul 21, 2023
1 parent 1903d79 commit c187888
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 375 deletions.
3 changes: 3 additions & 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 All @@ -45,6 +46,8 @@ Changed
- Hide additional internal fields from ISA-Tab templates (#1698)
- **Taskflowbackend**
- Move iRODS object helpers from ``LandingZoneTaskflowMixin`` (#1699)
- Move iRODS test cleanup to ``TaskflowTestMixin.clear_irods_test_data()`` (#1722)
- Refactor base test classes (#1722)

Fixed
-----
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
45 changes: 10 additions & 35 deletions irodsbackend/tests/test_signals_taskflow.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,37 @@
"""Signals tests for the irodsbackend app"""

from irods.exception import CollectionDoesNotExist, UserDoesNotExist
from irods.models import UserGroup
from irods.exception import UserDoesNotExist
from irods.user import iRODSUser

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.test import override_settings

from test_plus import TestCase

# Projectroles dependency
from projectroles.plugins import get_backend_api

from irodsbackend.api import IrodsAPI
# Taskflowbackend dependency
from taskflowbackend.tests.base import TaskflowViewTestBase


USER_NAME = 'test_user'


class TestCreateIrodsUser(TestCase):
"""Test the create_irods_user signal"""
class TestCreateIrodsUser(TaskflowViewTestBase):
"""Tests for create_irods_user signal"""

def setUp(self):
# Ensure TASKFLOW_TEST_MODE is True to avoid data loss
if not settings.TASKFLOW_TEST_MODE:
raise ImproperlyConfigured(
'TASKFLOW_TEST_MODE not True, testing with SODAR Taskflow '
'disabled'
)
self.taskflow = get_backend_api('taskflow', force=True)
self.user = self.make_user(USER_NAME)
self.irods_backend = IrodsAPI()
self.irods = self.irods_backend.get_session_obj()

def tearDown(self):
self.taskflow.cleanup()
with self.assertRaises(CollectionDoesNotExist):
self.irods.collections.get(self.irods_backend.get_projects_path())
for user in self.irods.query(UserGroup).all():
self.assertIn(
user[UserGroup.name], settings.TASKFLOW_TEST_PERMANENT_USERS
)
self.irods.cleanup()
super().tearDown()
super().setUp()
self.user_new = self.make_user(USER_NAME)

def test_create(self):
"""Test create_irods_user by logging in"""
with self.assertRaises(UserDoesNotExist):
self.irods.users.get(USER_NAME)
with self.login(self.user):
with self.login(self.user_new):
self.assertIsInstance(self.irods.users.get(USER_NAME), iRODSUser)

def test_create_user_exists(self):
"""Test create_irods_user with an existing user"""
self.irods.users.create(USER_NAME, 'rodsuser', settings.IRODS_ZONE)
self.assertIsInstance(self.irods.users.get(USER_NAME), iRODSUser)
with self.login(self.user):
with self.login(self.user_new):
# No crash should happen
self.assertIsInstance(self.irods.users.get(USER_NAME), iRODSUser)

Expand All @@ -65,6 +40,6 @@ def test_create_auth_disabled(self):
"""Test create_irods_user with IRODS_SODAR_AUTH disabled"""
with self.assertRaises(UserDoesNotExist):
self.irods.users.get(USER_NAME)
with self.login(self.user):
with self.login(self.user_new):
with self.assertRaises(UserDoesNotExist):
self.irods.users.get(USER_NAME)

0 comments on commit c187888

Please sign in to comment.