Skip to content

Commit

Permalink
Add unit test coverage for DUOS bundles (#5935, PR #5946)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsotirho-ucsc committed Mar 7, 2024
2 parents 845e59e + fc40926 commit a90a494
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 60 additions & 15 deletions test/indexer/test_anvil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from abc import (
ABC,
)
from collections import (
defaultdict,
)
import json
from operator import (
itemgetter,
)
Expand All @@ -9,16 +13,22 @@
cast,
)
from unittest.mock import (
Mock,
PropertyMock,
patch,
)

from furl import (
furl,
)
from more_itertools import (
one,
)
from urllib3 import (
HTTPResponse,
)

from azul import (
CatalogName,
config,
)
from azul.indexer.document import (
Expand All @@ -36,6 +46,12 @@
TDRAnvilBundle,
TDRAnvilBundleFQID,
)
from azul.terra import (
TDRClient,
)
from azul_test_case import (
TDRTestCase,
)
from indexer import (
AnvilCannedBundleTestCase,
IndexerTestCase,
Expand All @@ -50,6 +66,38 @@ def setUpModule():
configure_test_logging()


class DUOSTestCase(TDRTestCase, ABC):

@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
cls._patch_duos()

mock_duos_url = furl('https:://mock_duos.lan')

duos_id = 'foo'
duos_description = 'Study description from DUOS'

@classmethod
def _patch_duos(cls) -> None:
cls.addClassPatch(patch.object(type(config),
'duos_service_url',
new=PropertyMock(return_value=cls.mock_duos_url)))
cls.addClassPatch(patch.object(TDRClient,
'_request',
side_effect=[
Mock(spec=HTTPResponse, status=200, data=json.dumps({
'name': cls.source.spec.name,
'duosFirecloudGroup': {
'duosId': cls.duos_id
}
})),
Mock(spec=HTTPResponse, status=200, data=json.dumps({
'studyDescription': cls.duos_description
}))
]))


class AnvilIndexerTestCase(AnvilCannedBundleTestCase, IndexerTestCase):

@classmethod
Expand Down Expand Up @@ -78,19 +126,10 @@ def duos_bundle(cls) -> TDRAnvilBundleFQID:
return cls.bundle_fqid(uuid='2370f948-2783-aeb6-afea-e022897f4dcf',
entity_type=BundleEntityType.duos)

@classmethod
def catalog_config(cls) -> dict[CatalogName, config.Catalog]:
return {
cls.catalog: config.Catalog(name=cls.catalog,
atlas='anvil',
internal=False,
plugins=dict(metadata=config.Catalog.Plugin(name='anvil'),
repository=config.Catalog.Plugin(name='tdr_anvil')),
sources={str(cls.source.spec)})
}


class TestAnvilIndexer(AnvilIndexerTestCase, TDRPluginTestCase[tdr_anvil.Plugin]):
class TestAnvilIndexer(AnvilIndexerTestCase,
TDRPluginTestCase[tdr_anvil.Plugin],
DUOSTestCase):

@classmethod
def _plugin_cls(cls) -> Type[tdr_anvil.Plugin]:
Expand Down Expand Up @@ -123,10 +162,13 @@ def test_indexing(self):
finally:
self.index_service.delete_indices(self.catalog)

def _test_fetch_bundle(self, bundle_fqid: TDRAnvilBundleFQID):
def _test_fetch_bundle(self,
bundle_fqid: TDRAnvilBundleFQID,
load_tables: bool = True):
canned_bundle = self._load_canned_bundle(bundle_fqid)
assert isinstance(canned_bundle, TDRAnvilBundle)
self._make_mock_tdr_tables(bundle_fqid)
if load_tables:
self._make_mock_tdr_tables(bundle_fqid)
plugin = self.plugin_for_source_spec(canned_bundle.fqid.source.spec)
bundle = plugin.fetch_bundle(bundle_fqid)
assert isinstance(bundle, TDRAnvilBundle)
Expand All @@ -140,6 +182,9 @@ def test_fetch_primary_bundle(self):
def test_fetch_supplementary_bundle(self):
self._test_fetch_bundle(self.supplementary_bundle())

def test_fetch_duos_bundle(self):
self._test_fetch_bundle(self.duos_bundle(), load_tables=False)


class TestAnvilIndexerWithIndexesSetUp(AnvilIndexerTestCase):
"""
Expand Down

0 comments on commit a90a494

Please sign in to comment.