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

Conversation

briehl
Copy link
Collaborator

@briehl briehl commented Jun 11, 2024

This gives the cleanup / linting / test tidying treatment to the appinfo module.

Minimal changes to the module (other than typing), and tweaks to pytestify the integration tests.

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.

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!

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.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not deleted, moved to test/integration/test_appinfo.py. Which is unfortunate for comparison. I'll do this differently in later PRs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some basic app data for the mocks to load. We could use VCR here, but I think this works well enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a fragment of the return value from NMS.list_methods

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One possible version of a return from Catalog.list_favorites.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reworked from the original to use pytest idioms and fixtures.
NMS and Catalog client fixtures might get moved to conftest.py in a later PR. I forget if they're used in other modules or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The unit version's much simpler and uses the included mock data. It also doesn't validate server results like the integration test does.

@briehl briehl requested a review from ialarmedalien June 11, 2024 02:34
Comment on lines 7 to 8
IGNORE_CATEGORIES = {"inactive", "importers", "viewers"}
APP_TAGS = ["release", "beta", "dev"]

Choose a reason for hiding this comment

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

import from appinfo so they will always be guaranteed to be in sync?

for a in info["app_infos"]:
app = info["app_infos"][a]["info"]
for str_key in app_str_keys:
assert str_key in app

Choose a reason for hiding this comment

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

add in a check that the value is a str?

validate_app_info(info)


@pytest.mark.parametrize("bad_tag", [None, [], {}, "foo", 5, -3])

Choose a reason for hiding this comment

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

Could add in an empty string and a bool, just for fun!

) -> None:
# this is all public info, so just use my username, and i'll keep at least one favorite
favorite_user = "wjriehl"
cat_favorites = catalog_client.list_favorites(favorite_user)

Choose a reason for hiding this comment

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

this sounds way more fun than it actually is!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😹

Comment on lines 8 to 9
IGNORE_CATEGORIES = {"inactive", "importers", "viewers"}
APP_TAGS = ["release", "beta", "dev"]

Choose a reason for hiding this comment

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

import from appinfo?

@briehl
Copy link
Collaborator Author

briehl commented Jun 11, 2024

I added the requested changes. Thanks for the review!

@briehl briehl requested a review from ialarmedalien June 11, 2024 15:44
@briehl briehl merged commit 5e7ed4a into fix-report-fetch-test Jun 11, 2024
1 check failed
@briehl briehl deleted the fix-appinfo-test branch June 11, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants