-
Notifications
You must be signed in to change notification settings - Fork 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
ErrataConnection Filter helper method - WIP #195
Open
yazug
wants to merge
5
commits into
red-hat-storage:master
Choose a base branch
from
yazug:filter_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
acc1b83
add ErrataConnector::get_filter() helper method
yazug 5d6de44
Expand release to use filter method
yazug 48e843b
update errata to use filter method
yazug 36449b7
WIP: add several helpers to connector for query
yazug d7dd19b
WIP: search by batch using filter
yazug 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 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 |
---|---|---|
|
@@ -310,3 +310,96 @@ def get_paginated_data(self, api_url): | |
if page_number >= PAGE_LIMIT: | ||
raise RuntimeError('hit pagination timeout: %d' % page_number) | ||
return data | ||
|
||
def get_filter(self, endpoint, filter_arg, **kwargs): | ||
"""format and generate filter get request | ||
|
||
expose a general filter helper method to format kwargs up | ||
as parameters for ET filter request. Then return generated | ||
json object | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably include the syntax for how the url is generated |
||
|
||
if endpoint is None or filter_arg is None: | ||
return None | ||
|
||
url = endpoint + "?" | ||
param_list = [] | ||
keys = list(kwargs) | ||
keys.sort() | ||
for k in keys: | ||
v = kwargs[k] | ||
if k in ('paginated'): | ||
continue | ||
if k in ('release', 'product'): | ||
param_list.append("{0}[{1}][]={2}".format(filter_arg, k, v)) | ||
else: | ||
param_list.append("{0}[{1}]={2}".format(filter_arg, k, v)) | ||
if self.debug: | ||
print(param_list) | ||
url = url + "&".join(param_list) | ||
if endpoint == '/errata': | ||
url = url + '&format=json' | ||
if self.debug: | ||
print(url) | ||
|
||
if 'paginated' in kwargs and kwargs['paginated']: | ||
return {'data': self.get_paginated_data(url)} | ||
|
||
return self._get(url) | ||
|
||
def get_releases_for_product(self, product_name_or_id, | ||
return_ids_only=True): | ||
"""search for and return list of releases by name or id of product""" | ||
args = {'is_active': 'true', 'enabled': 'true'} | ||
|
||
try: | ||
args['id'] = int(product_name_or_id) | ||
except ValueError: | ||
args['name'] = product_name_or_id | ||
|
||
data = self.get_filter('/api/v1/releases', 'filter', **args) | ||
if return_ids_only: | ||
return [i['id'] for i in data['data']] | ||
|
||
return data | ||
|
||
def get_open_advisories_for_release(self, release_id): | ||
data = self._get('/errata/errata_for_release/' + | ||
'{0}.json'.format(release_id)) | ||
|
||
ADVISORY_STATES = ('NEW_FILES', 'QE', 'REL_PREP', 'PUSH_READY') | ||
advisory_ids = set() | ||
|
||
for advisory_result in data: | ||
if advisory_result['status'] in ADVISORY_STATES: | ||
advisory_ids.add(advisory_result['id']) | ||
return list(advisory_ids) | ||
|
||
def get_open_advisories_for_release_filter(self, release_id, | ||
return_ids_only=True): | ||
"""Return list of open advisories for a release either id's or json""" | ||
|
||
data = self.get_filter( | ||
'/errata', 'errata_filter[filter_params]', | ||
show_type_RHBA=1, show_type_RHEA=1, show_type_RHSA=1, | ||
show_state_NEW_FILES=1, show_state_QE=1, show_state_REL_PREP=1, | ||
show_state_PUSH_READY=1, open_closed_option='exclude', | ||
release=release_id) | ||
|
||
if return_ids_only: | ||
return [i['id'] for i in data] | ||
|
||
return data | ||
|
||
def get_errata_by_batch(self, batch_name_or_id): | ||
"""search for and return list of errata by name or id of batch""" | ||
args = {} | ||
|
||
try: | ||
args['id'] = int(batch_name_or_id) | ||
except ValueError: | ||
args['name'] = batch_name_or_id | ||
|
||
data = self.get_filter('/api/v1/batches', 'filter', **args) | ||
|
||
return data |
This file contains 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 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 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
1 change: 1 addition & 0 deletions
1
...i/v1/external_tests?filter[active]=true&filter[errata_id]=33840&filter[test_type]=rpmdiff
This file contains 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 @@ | ||
external_tests/?filter[active]=true&filter[errata_id]=33840&filter[test_type]=rpmdiff&page[number]=1 |
1 change: 1 addition & 0 deletions
1
...ests?filter[active]=true&filter[errata_id]=33840&filter[test_type]=rpmdiff&page[number]=1
This file contains 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 @@ | ||
external_tests/?filter[active]=true&filter[errata_id]=33840&filter[test_type]=rpmdiff&page[number]=1 |
1 change: 1 addition & 0 deletions
1
...ests?filter[active]=true&filter[errata_id]=33840&filter[test_type]=rpmdiff&page[number]=2
This file contains 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 @@ | ||
external_tests/?filter[active]=true&filter[errata_id]=33840&filter[test_type]=rpmdiff&page[number]=2 |
This file contains 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 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,33 @@ | ||
import requests | ||
|
||
|
||
class TestFilter(object): | ||
|
||
def test_filter_none(self, sample_connector): | ||
assert sample_connector.get_filter(None, None) is None | ||
|
||
def test_filter_sample(self, sample_connector): | ||
assert sample_connector.get_filter( | ||
'/api/v1/releases', 'filter', name='rhceph-3.1') | ||
|
||
def test_filter_sample_check_url(self, monkeypatch, mock_get, | ||
sample_connector): | ||
monkeypatch.setattr(requests, 'get', mock_get) | ||
assert sample_connector.get_filter( | ||
'/api/v1/releases', 'filter', name='rhceph-3.1') | ||
assert 'page' not in mock_get.response.url | ||
|
||
def test_filter_url_paginated_false(self, monkeypatch, | ||
mock_get, sample_connector): | ||
monkeypatch.setattr(requests, 'get', mock_get) | ||
assert sample_connector.get_filter( | ||
'/api/v1/releases', 'filter', name='rhceph-3.1', paginated=False) | ||
assert 'page' not in mock_get.response.url | ||
|
||
def test_filter_sample_check_url_paginated(self, monkeypatch, mock_get, | ||
sample_connector): | ||
monkeypatch.setattr(requests, 'get', mock_get) | ||
assert sample_connector.get_filter( | ||
'/api/v1/external_tests', 'filter', errata_id='33840', | ||
test_type='rpmdiff', active='true', paginated=True) | ||
assert 'page' in mock_get.response.url | ||
yazug marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
I think "filter_arg" is always going to be the string "filter", right? Do we need this variable here?
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.
no it is not see '/errata' ... filter_args == 'errata_filter[filter_params]'
yazug@3a2bbad#diff-1a50735487483ddcd06dc38f02e580ebR379-R384
for a couple of examples, I used, extracted from various places where searching was done.