Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIP-49 - Fix appinfo tests #97

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/NarrativeService/NarrativeServiceImpl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#BEGIN_HEADER
from installed_clients.CatalogClient import Catalog
from installed_clients.NarrativeMethodStoreClient import NarrativeMethodStore
from installed_clients.WorkspaceClient import Workspace
from NarrativeService.apps.appinfo import get_all_app_info, get_ignore_categories
from NarrativeService.data.fetcher import DataFetcher
Expand Down Expand Up @@ -658,8 +660,9 @@ def get_all_app_info(self, ctx, input):
# ctx is the context object
# return variables are: output
#BEGIN get_all_app_info
output = get_all_app_info(input["tag"], input["user"],
self.narrativeMethodStoreURL, self.catalogURL)
catalog = Catalog(self.catalogURL)
nms = NarrativeMethodStore(self.narrativeMethodStoreURL)
output = get_all_app_info(input["tag"], input["user"], nms, catalog)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified this to pass along the clients instead of a URL, which makes test mocking easier.

#END get_all_app_info

# At some point might do deeper type checking...
Expand Down
23 changes: 11 additions & 12 deletions lib/NarrativeService/apps/appinfo.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import contextlib

from installed_clients.CatalogClient import Catalog
from installed_clients.NarrativeMethodStoreClient import NarrativeMethodStore

IGNORE_CATEGORIES = {"inactive", "importers", "viewers"}
IGNORE_CATEGORIES: set = {"inactive", "importers", "viewers"}
APP_TAGS: set = {"release", "beta", "dev"}


def get_ignore_categories():
return {x: 1 for x in IGNORE_CATEGORIES}
def get_ignore_categories() -> dict[str, int]:
return dict.fromkeys(IGNORE_CATEGORIES, 1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested by ruff. I think it's fine. Really, I think that API call is kinda goofy in expecting a dictionary instead of a list, but 🤷

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty exciting shorthand - I don't think I've seen it before.

Not sure why the API couldn't just return IGNORE_CATEGORIES as that would ensure it was deduped and there's no need to do anything else to it... but ours is not to question why!



def _shorten_types(type_list):
def _shorten_types(type_list: list[str]) -> list[str]:
"""
convert ['KBaseMatrices.AmpliconMatrix'] to ['AmpliconMatrix']
"""
shorten_types = list()
shorten_types = []
for t in type_list:
try:
with contextlib.suppress(IndexError):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another piece of ruffage since we're ignoring errors anyway.

shorten_types.append(t.split(".")[1])
except IndexError:
pass

return shorten_types


def get_all_app_info(tag, user, nms_url, catalog_url):
if tag not in ["release", "beta", "dev"]:
def get_all_app_info(tag: str, user: str, nms: NarrativeMethodStore, catalog: Catalog):
if not isinstance(tag, str) or tag not in APP_TAGS:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruff suggested converting to a set which makes sense, then tests failed if non-hashable things were passed in as the app tag.

raise ValueError("tag must be one of 'release', 'beta', or 'dev'")
nms = NarrativeMethodStore(nms_url)
catalog = Catalog(catalog_url)
apps = nms.list_methods({"tag": tag})
app_infos = {}
module_versions = {}
Expand Down
122 changes: 0 additions & 122 deletions test/AppInfo_test.py

This file was deleted.

17 changes: 16 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import os
from collections.abc import Generator
from configparser import ConfigParser
from pathlib import Path
from time import time

import pytest
Expand All @@ -11,7 +13,6 @@
from lib.installed_clients.FakeObjectsForTestsClient import FakeObjectsForTests
from lib.installed_clients.WorkspaceClient import Workspace


@pytest.fixture(scope="session")
def config() -> Generator[dict[str, str | int], None, None]:
"""Load and return the test config as a dictionary."""
Expand Down Expand Up @@ -106,3 +107,17 @@ def mock_token():
@pytest.fixture
def mock_user():
return MOCK_USER_ID

@pytest.fixture
def json_data():
"""
Loads test data relative to the test/data directory.
I.e. for loading the "test/data/test_app_data.json" file, use the fixture like this:
def test_stuff(json_data):
app_data = test_data("test_app_data.json")
"""
data_root = Path(__file__).parent / "data"
def load_json_data(file_path: str | Path):
with open(data_root / file_path) as infile:
return json.load(infile)
return load_json_data
98 changes: 98 additions & 0 deletions test/data/test_app_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[
{
"id": "CompoundSetUtils/compound_set_from_file",
"module_name": "CompoundSetUtils",
"git_commit_hash": "092bc8d86874fd83ee7d8b67a40b6a4339fe4289",
"name": "Import CompoundSet from File",
"ver": "2.1.3",
"subtitle": "This method imports a file from the staging area as a CompoundSet",
"tooltip": "This method imports a file from the staging area as a CompoundSet",
"icon": {
"url": "img?method_id=CompoundSetUtils/compound_set_from_file&image_name=data-blue.png&tag=release"
},
"categories": [
"active",
"upload"
],
"authors": [
"jjeffryes"
],
"input_types": [],
"output_types": [
"KBaseBiochem.CompoundSet"
],
"app_type": "app",
"namespace": "CompoundSetUtils"
},
{
"id": "CompoundSetUtils/compound_set_from_model",
"module_name": "CompoundSetUtils",
"git_commit_hash": "092bc8d86874fd83ee7d8b67a40b6a4339fe4289",
"name": "Make CompoundSet from Metabolic Model",
"ver": "2.1.3",
"subtitle": "This method genrerate a CompoundSet from compounds in a Metabolic Model",
"tooltip": "This method genrerate a CompoundSet from compounds in a Metabolic Model",
"icon": {
"url": "img?method_id=CompoundSetUtils/compound_set_from_model&image_name=data-blue.png&tag=release"
},
"categories": [
"active",
"util"
],
"authors": [
"jjeffryes"
],
"input_types": [
"KBaseFBA.FBAModel"
],
"output_types": [
"KBaseBiochem.CompoundSet"
],
"app_type": "app",
"namespace": "CompoundSetUtils"
},
{
"id": "CompoundSetUtils/fetch_mol2_files_from_zinc",
"module_name": "CompoundSetUtils",
"git_commit_hash": "092bc8d86874fd83ee7d8b67a40b6a4339fe4289",
"name": "Fetch And Import Mol2 from ZINC Database To CompoundSet",
"ver": "2.1.3",
"subtitle": "This method fetches Mol2 file from ZINC by searching inchikey associated with compound and then save the Mol2 file to the compound object",
"tooltip": "This method fetches Mol2 file from ZINC by searching inchikey associated with compound and then save the Mol2 file to the compound object",
"icon": {
"url": "img?method_id=CompoundSetUtils/fetch_mol2_files_from_zinc&image_name=zinc15_72pt-aqua.png&tag=release"
},
"categories": [
"active",
"upload"
],
"authors": [
"tgu2"
],
"input_types": [
"KBaseBiochem.CompoundSet"
],
"output_types": [],
"app_type": "app",
"namespace": "CompoundSetUtils"
},
{
"id": "KBaseRNASeq/view_rnaseq_analysis",
"module_name": "KBaseRNASeq",
"git_commit_hash": "07a2978aea7cabf4decec09c2dc51be81e26f02d",
"name": "View RNASeqAnalysis",
"ver": "1.0.5",
"subtitle": "View RNASeqAnalysis",
"tooltip": "View RNASeqAnalysis",
"categories": [
"viewers"
],
"authors": [],
"input_types": [
"KBaseRNASeq.RNASeqAnalysis"
],
"output_types": [],
"app_type": "app",
"namespace": "KBaseRNASeq"
}
]
7 changes: 7 additions & 0 deletions test/data/test_app_favorites.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"module_name_lc": "compoundsetutils",
"id": "compound_set_from_model",
"timestamp": 1585695012878
}
]
Loading
Loading