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

Improve test coverage and more intuitive Tags #191

Merged
merged 3 commits into from
Jan 30, 2019
Merged

Improve test coverage and more intuitive Tags #191

merged 3 commits into from
Jan 30, 2019

Conversation

polyatail
Copy link
Contributor

This PR addresses the following issues:

@polyatail polyatail added the needs review need code review before merging label Jan 24, 2019
@polyatail polyatail added this to the Sprint Lava milestone Jan 24, 2019
@polyatail polyatail self-assigned this Jan 24, 2019
Copy link
Contributor

@boydgreenfield boydgreenfield left a comment

Choose a reason for hiding this comment

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

Test coverage and __contains__ stuff generally looks good (didn't look that closely at the latter though). For adding support to query Samples by Tag, we should implement this using the API and do the filtering on the backend vs. the frontend. Example query in my comments inline below.

@@ -24,6 +24,11 @@ def where(cls, *filters, **keyword_filters):
public = keyword_filters.get('public', False)
instances_route = 'instances' if not public else 'instances_public'
limit = keyword_filters.get('limit', None if not public else 1000)
tag = keyword_filters.pop('tag', None)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, we actually support this in the API and shouldn't need to get all samples and filter in memory. Here's an example public URL:

https://app.onecodex.com/api/v1/samples?where={"tags": {"$contains": {"$ref": "/api/v1/tags/dbcf5b98bca54a16"}}}

Consequently, I think the best way to implement this is to fetch the tag by name if we have a non-UUID (and maybe have some kind of is_uuid() function to skip this check) and then include it in the .where query directly.

Note we also implement a custom $containsany and $containsall selector in our backend that allows passing an array of tags and doing more complex intersects. We should look at the performance of that query code before leaning on it too heavily, but those may be useful too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, this was a lot simpler. Changed as requested.

if len(samples_to_keep) == limit:
break

samples = samples_to_keep
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment above re: removing and simplifying this logic (plus shipping less data!).

@@ -81,6 +89,13 @@ def test_resourcelist(ocx, api_data):
tags1.append(sample)
assert 'object of type' in str(e.value)

if sys.version_info.major < 3:
with pytest.raises(AttributeError):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, why does this raise? Probably worth a comment for future us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently lists in Python 2 do not have a clear() method

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, who knew. OK!

@polyatail polyatail added in progress not yet ready for review and removed needs review need code review before merging labels Jan 28, 2019
@coveralls
Copy link

Coverage Status

Coverage increased (+2.2%) to 85.898% when pulling 43a9150 on roo-lava1 into 737fd56 on master.

@polyatail polyatail added done ready to be merged and removed in progress not yet ready for review labels Jan 29, 2019
new_tags.append(t)
else:
# is it a uuid?
if len(t) == 16:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's write an is_ocx_id helper function that does this plus and alphabet check. Something like:

assert set(x for x in name).issubset(string.hexdigits)

@polyatail polyatail merged commit c0d5d34 into master Jan 30, 2019
@polyatail polyatail deleted the roo-lava1 branch February 5, 2019 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants