Skip to content

Commit

Permalink
add dna_sequencing tests, refactor (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 26, 2024
1 parent 7591aaa commit a33000f
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 29 deletions.
35 changes: 6 additions & 29 deletions samplesheets/assayapps/cytof/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@

from copy import deepcopy

from django.conf import settings

from samplesheets.models import Investigation
from samplesheets.rendering import SampleSheetTableBuilder, SIMPLE_LINK_TEMPLATE
from samplesheets.plugins import SampleSheetAssayPluginPoint, get_backend_api
from samplesheets.tests.test_views import (
SheetTemplateCreateMixin,
SamplesheetsViewTestBase,
)
from samplesheets.views import CUBI_TPL_DICT, MISC_FILES_COLL


table_builder = SampleSheetTableBuilder()
from samplesheets.assayapps.tests.base import AssayPluginTestBase
from samplesheets.rendering import SIMPLE_LINK_TEMPLATE
from samplesheets.views import MISC_FILES_COLL


# Local constants
PLUGIN_NAME = 'samplesheets_assay_cytof'
ASSAY_NAME = 'testassayname'
PANEL_NAME = 'testpanel'
REPORT_NAME = 'report.txt'
Expand All @@ -29,23 +18,11 @@
FILE_NAME3 = 'file3.txt'


class TestCytofPlugin(SheetTemplateCreateMixin, SamplesheetsViewTestBase):
class TestCytofAssayPlugin(AssayPluginTestBase):
"""Tests for cytof assay plugin"""

def setUp(self):
super().setUp()
self.make_sheets_from_cubi_tpl(CUBI_TPL_DICT['mass_cytometry'])
self.investigation = Investigation.objects.get(project=self.project)
self.study = self.investigation.studies.first()
self.assay = self.study.assays.first()
self.study_tables = table_builder.build_study_tables(self.study)
self.assay_table = self.study_tables['assays'][
str(self.assay.sodar_uuid)
]
self.irods_backend = get_backend_api('omics_irods')
self.assay_path = self.irods_backend.get_path(self.assay)
self.base_url = settings.IRODS_WEBDAV_URL + self.assay_path
self.plugin = SampleSheetAssayPluginPoint.get_plugin(PLUGIN_NAME)
plugin_name = 'samplesheets_assay_cytof'
template_name = 'mass_cytometry'

def test_get_row_path_filled(self):
"""Test get_row_path() with filled out assay name"""
Expand Down
Empty file.
50 changes: 50 additions & 0 deletions samplesheets/assayapps/dna_sequencing/tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Plugin tests for the the dna_sequencing assay plugin"""

import os

from copy import deepcopy

from samplesheets.assayapps.tests.base import AssayPluginTestBase


# Local constants
MATERIAL_NAME = 'alpha'
MATERIAL_NAME_UPDATE = 'alpha-material-update'


class TestDNASequencingAssayPlugin(AssayPluginTestBase):
"""Tests for dna_sequencing assay plugin"""

plugin_name = 'samplesheets_assay_dna_sequencing'
template_name = 'generic'

def test_get_row_path(self):
"""Test get_row_path()"""
row_path = self.plugin.get_row_path(
self.assay_table['table_data'][0],
self.assay_table,
self.assay,
self.assay_path,
)
expected = os.path.join(self.assay_path, MATERIAL_NAME)
self.assertEqual(row_path, expected)

def test_get_row_path_rename(self):
"""Test get_row_path() with renamed material name"""
self.assay_table['table_data'][0][-1]['value'] = MATERIAL_NAME_UPDATE
row_path = self.plugin.get_row_path(
self.assay_table['table_data'][0],
self.assay_table,
self.assay,
self.assay_path,
)
expected = os.path.join(self.assay_path, MATERIAL_NAME_UPDATE)
self.assertEqual(row_path, expected)

def test_update_row(self):
"""Test update_row()"""
row_ex = deepcopy(self.assay_table['table_data'][0])
row = self.plugin.update_row(
self.assay_table['table_data'][0], self.assay_table, self.assay, 0
)
self.assertEqual(row, row_ex)
Empty file.
38 changes: 38 additions & 0 deletions samplesheets/assayapps/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Base classes and helpers for assay plugin tests"""

from django.conf import settings

from samplesheets.models import Investigation
from samplesheets.rendering import SampleSheetTableBuilder
from samplesheets.plugins import SampleSheetAssayPluginPoint, get_backend_api
from samplesheets.tests.test_views import (
SheetTemplateCreateMixin,
SamplesheetsViewTestBase,
)
from samplesheets.views import CUBI_TPL_DICT


table_builder = SampleSheetTableBuilder()


class AssayPluginTestBase(SheetTemplateCreateMixin, SamplesheetsViewTestBase):
"""Base test class for assay plugins"""

plugin_name = None
template_name = None

def setUp(self):
super().setUp()
self.make_sheets_from_cubi_tpl(CUBI_TPL_DICT[self.template_name])
self.investigation = Investigation.objects.get(project=self.project)
# NOTE: This assumes one study and assay, extend setup() to add more
self.study = self.investigation.studies.first()
self.assay = self.study.assays.first()
self.study_tables = table_builder.build_study_tables(self.study)
self.assay_table = self.study_tables['assays'][
str(self.assay.sodar_uuid)
]
self.irods_backend = get_backend_api('omics_irods')
self.assay_path = self.irods_backend.get_path(self.assay)
self.base_url = settings.IRODS_WEBDAV_URL + self.assay_path
self.plugin = SampleSheetAssayPluginPoint.get_plugin(self.plugin_name)

0 comments on commit a33000f

Please sign in to comment.