Skip to content

Commit

Permalink
update non-taskflow landingzones tests (#1617)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed May 2, 2023
1 parent 0e0fd47 commit 681ffad
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 105 deletions.
28 changes: 11 additions & 17 deletions landingzones/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
from datetime import timedelta
from unittest import mock

from django.conf import settings
from django.core.management import call_command
from django.utils.timezone import localtime

from test_plus.test import TestCase

# Projectroles dependency
from projectroles.constants import SODAR_CONSTANTS
from projectroles.models import Role
from projectroles.plugins import get_backend_api
from projectroles.tests.test_models import ProjectMixin, RoleAssignmentMixin
from projectroles.tests.test_models import (
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
)

from landingzones.management.commands.inactivezones import (
get_inactive_zones,
Expand All @@ -33,41 +35,34 @@
ZONE2_TITLE = '20201123_143323_test_zone'
ZONE3_TITLE = '20201218_172740_test_zone_moved'
ZONE4_TITLE = '20201218_172743_test_zone_deleted'
IRODS_BACKEND_ENABLED = (
True if 'omics_irods' in settings.ENABLED_BACKEND_PLUGINS else False
)
IRODS_BACKEND_SKIP_MSG = 'iRODS backend not enabled in settings'
LOGGER_BUSY_ZONES = 'landingzones.management.commands.busyzones'


class TestCommandBase(
ProjectMixin,
SampleSheetIOMixin,
RoleMixin,
RoleAssignmentMixin,
SampleSheetIOMixin,
LandingZoneMixin,
TestCase,
):
"""Base class for command tests"""

def setUp(self):
super().setUp()

# Init roles
self.init_roles()
# Init superuser
self.user = self.make_user('user')
self.user.is_superuser = True
self.user.is_staff = True
self.user.save()

# Init roles
self.role_owner = Role.objects.get_or_create(name=PROJECT_ROLE_OWNER)[0]
# Init project with owner
self.project = self.make_project(
'TestProject', PROJECT_TYPE_PROJECT, None
)
self.owner_as = self.make_assignment(
self.project, self.user, self.role_owner
)

self.investigation = self.import_isa_from_file(SHEET_PATH, self.project)
self.study = self.investigation.studies.first()
self.assay = self.study.assays.first()
Expand Down Expand Up @@ -130,7 +125,7 @@ def setUp(self):
self.irods_backend = get_backend_api('omics_irods')
self.irods = self.irods_backend.get_session_obj()

# Create the irods collections
# Create iRODS collections
self.irods.collections.create(self.irods_backend.get_path(self.zone))
self.irods.collections.create(self.irods_backend.get_path(self.zone2))
self.irods.collections.create(self.irods_backend.get_path(self.zone3))
Expand Down Expand Up @@ -180,8 +175,7 @@ class TestBusyZones(TestCommandBase):

def setUp(self):
super().setUp()

# Create LandingZone 1 from 3 weeks ago
# Create zones
self.zone = self.make_landing_zone(
title=ZONE1_TITLE,
project=self.project,
Expand Down
32 changes: 12 additions & 20 deletions landingzones/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
from test_plus.test import TestCase

# Projectroles dependency
from projectroles.models import Role, SODAR_CONSTANTS
from projectroles.tests.test_models import ProjectMixin, RoleAssignmentMixin
from projectroles.models import SODAR_CONSTANTS
from projectroles.tests.test_models import (
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
)

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

from landingzones.models import LandingZone, DEFAULT_STATUS_INFO


# Global constants
# SODAR constants
PROJECT_ROLE_OWNER = SODAR_CONSTANTS['PROJECT_ROLE_OWNER']
PROJECT_ROLE_DELEGATE = SODAR_CONSTANTS['PROJECT_ROLE_DELEGATE']
PROJECT_ROLE_CONTRIBUTOR = SODAR_CONSTANTS['PROJECT_ROLE_CONTRIBUTOR']
Expand Down Expand Up @@ -70,29 +74,28 @@ class TestLandingZoneBase(
LandingZoneMixin,
SampleSheetIOMixin,
ProjectMixin,
RoleMixin,
RoleAssignmentMixin,
TestCase,
):
"""Base tests for LandingZone"""

def setUp(self):
# Init roles
self.init_roles()
# Make owner user
self.user_owner = self.make_user('owner')

# Init project, role and assignment
# Init project and assignment
self.project = self.make_project(
'TestProject', PROJECT_TYPE_PROJECT, None
)
self.role_owner = Role.objects.get_or_create(name=PROJECT_ROLE_OWNER)[0]
self.assignment_owner = self.make_assignment(
self.owner_as = self.make_assignment(
self.project, self.user_owner, self.role_owner
)

# 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()

# Create LandingZone
self.landing_zone = self.make_landing_zone(
title=ZONE_TITLE,
Expand Down Expand Up @@ -128,7 +131,6 @@ def test_initialization(self):
'status_info': ZONE_STATUS_INFO_INIT,
'sodar_uuid': self.landing_zone.sodar_uuid,
}

self.assertEqual(model_to_dict(self.landing_zone), expected)

def test__str__(self):
Expand All @@ -152,31 +154,21 @@ def test_set_status(self):
"""Test set_status() with status and status_info"""
status = 'ACTIVE'
status_info = 'ok'

# Assert preconditions
self.assertNotEqual(self.landing_zone.status, status)
self.assertNotEqual(self.landing_zone.status_info, status_info)

self.landing_zone.set_status(status, status_info)
self.landing_zone.refresh_from_db()

# Assert postconditions
self.assertEqual(self.landing_zone.status, status)
self.assertEqual(self.landing_zone.status_info, status_info)

def test_set_status_no_info(self):
"""Test set_status() without status_info"""
status = 'ACTIVE'
status_info = DEFAULT_STATUS_INFO[status]

# Assert preconditions
self.assertNotEqual(self.landing_zone.status, status)
self.assertNotEqual(self.landing_zone.status_info, status_info)

self.landing_zone.set_status(status)
self.landing_zone.refresh_from_db()

# Assert postconditions
self.assertEqual(self.landing_zone.status, status)
self.assertEqual(self.landing_zone.status_info, status_info)

Expand Down
Loading

0 comments on commit 681ffad

Please sign in to comment.