-
Notifications
You must be signed in to change notification settings - Fork 25
Allow searching on model fields rather than (only) raw Pulp fields #36
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
Merged
rohanpm
merged 2 commits into
release-engineering:master
from
rohanpm:search-model-fields
Aug 15, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,3 +46,4 @@ def fields_dict(cls): | |
| Factory = attr.Factory | ||
| fields = attr.fields | ||
| evolve = attr.evolve | ||
| has = attr.has | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import pytest | ||
|
|
||
| from pubtools.pulplib import Criteria, Matcher, Repository | ||
|
|
||
| from pubtools.pulplib._impl.client.search import filters_for_criteria | ||
|
|
||
|
|
||
| def test_eng_product_in(): | ||
| """eng_product is mapped correctly""" | ||
| crit = Criteria.with_field_in("eng_product_id", [12, 34, 56]) | ||
| assert filters_for_criteria(crit, Repository) == { | ||
| "notes.eng_product": {"$in": ["12", "34", "56"]} | ||
| } | ||
|
|
||
|
|
||
| def test_is_temporary(): | ||
| """is_temporary is mapped correctly""" | ||
| crit = Criteria.with_field("is_temporary", True) | ||
| assert filters_for_criteria(crit, Repository) == { | ||
| "notes.pub_temp_repo": {"$eq": True} | ||
| } | ||
|
|
||
|
|
||
| def test_type(): | ||
| """type is mapped correctly""" | ||
| crit = Criteria.with_field("type", Matcher.regex("foobar")) | ||
| assert filters_for_criteria(crit, Repository) == { | ||
| "notes._repo-type": {"$regex": "foobar"} | ||
| } | ||
|
|
||
|
|
||
| def test_signing_keys(): | ||
| """signing_keys are mapped correctly""" | ||
| crit = Criteria.with_field("signing_keys", ["abc", "def", "123"]) | ||
| assert filters_for_criteria(crit, Repository) == { | ||
| "notes.signatures": {"$eq": "abc,def,123"} | ||
| } | ||
|
|
||
|
|
||
| def test_created(): | ||
| """created is mapped correctly""" | ||
| # TODO: there is no datetime => string implicit conversion right now. | ||
| # | ||
| # Should we do that? Right now, it doesn't seem all that useful because | ||
| # there's probably no usecase to search for an exact datetime anyway. | ||
| # | ||
| # In practice, searching by datetime probably is useful only with $lt | ||
| # or $gt, which is not supported by this library at all, at the time | ||
| # of writing. | ||
| crit = Criteria.with_field("created", "20190814T15:16Z") | ||
| assert filters_for_criteria(crit, Repository) == { | ||
| "notes.created": {"$eq": "20190814T15:16Z"} | ||
| } | ||
|
|
||
|
|
||
| def test_unsearchable(): | ||
| """passing a field which can't be mapped directly to Pulp raises an error""" | ||
| crit = Criteria.with_field("relative_url", "foobar") | ||
| with pytest.raises(NotImplementedError) as exc: | ||
| filters_for_criteria(crit, Repository) | ||
| assert "Searching on field relative_url is not supported" in str(exc.value) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: 'test_eng_product_id'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I did mean "in" because the test is doing a search with "in" operator, though I see how it's ambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. It's called eng_product_id, so looked like a typo.