Skip to content

Commit

Permalink
Fixed scan list & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abaiken committed Feb 21, 2018
1 parent 4b47f82 commit 4d22571
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 49 deletions.
13 changes: 0 additions & 13 deletions qpc/scan/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,11 @@ def __init__(self, subparsers):
metavar='TYPE',
help=_(messages.SCAN_TYPE_FILTER_HELP),
required=False)
self.parser.add_argument('--status', dest='status',
choices=[scan.SCAN_STATUS_CREATED,
scan.SCAN_STATUS_PENDING,
scan.SCAN_STATUS_RUNNING,
scan.SCAN_STATUS_PAUSED,
scan.SCAN_STATUS_CANCELED,
scan.SCAN_STATUS_COMPLETED,
scan.SCAN_STATUS_FAILED],
metavar='STATUS',
help=_(messages.SCAN_STATUS_FILTER_HELP),
required=False)

def _build_req_params(self):
"""Add filter by scan_type/state query param."""
if 'type' in self.args and self.args.type:
self.req_params = {'scan_type': self.args.type}
if 'status' in self.args and self.args.status:
self.req_params = {'status': self.args.status}

def _handle_response_success(self):
json_data = self.response.json()
Expand Down
42 changes: 6 additions & 36 deletions qpc/scan/tests_scan_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def test_list_scan_data(self, b_input):
'scan_type': 'inspect',
'source': {
'id': 1,
'name': 'scan1'},
'status': 'completed'}
'name': 'scan1'}}
results = [scan_entry]
next_link = get_server_location() + SCAN_URI + '?page=2'
data = {
Expand All @@ -128,8 +127,8 @@ def test_list_scan_data(self, b_input):
with redirect_stdout(scan_out):
slc.main(args)
expected = '[{"id":1,"scan_type":"inspect"' \
',"source":{"id":1,"name":"scan1"},'\
'"status":"completed"}]'
',"source":{"id":1,"name":"scan1"}'\
'}]'
self.assertEqual(scan_out.getvalue().replace('\n', '')
.replace(' ', '').strip(),
expected + expected)
Expand All @@ -143,8 +142,7 @@ def test_list_filter_type(self):
'scan_type': 'inspect',
'source': {
'id': 1,
'name': 'scan1'},
'status': 'completed'}
'name': 'scan1'}}
results = [scan_entry]
data = {
'count': 1,
Expand All @@ -158,35 +156,7 @@ def test_list_filter_type(self):
with redirect_stdout(scan_out):
slc.main(args)
expected = '[{"id":1,"scan_type":"inspect"' \
',"source":{"id":1,"name":"scan1"},'\
'"status":"completed"}]'
self.assertEqual(scan_out.getvalue().replace('\n', '')
.replace(' ', '').strip(), expected)

def test_list_filter_status(self):
"""Testing the list scan with filter by state."""
scan_out = StringIO()
url = get_server_location() + SCAN_URI
scan_entry = {'id': 1,
'scan_type': 'inspect',
'source': {
'id': 1,
'name': 'scan1'},
'status': 'completed'}
results = [scan_entry]
data = {
'count': 1,
'next': None,
'results': results
}
with requests_mock.Mocker() as mocker:
mocker.get(url, status_code=200, json=data)
slc = ScanListCommand(SUBPARSER)
args = Namespace(status='completed')
with redirect_stdout(scan_out):
slc.main(args)
expected = '[{"id":1,"scan_type":"inspect"' \
',"source":{"id":1,"name":"scan1"},'\
'"status":"completed"}]'
',"source":{"id":1,"name":"scan1"}'\
'}]'
self.assertEqual(scan_out.getvalue().replace('\n', '')
.replace(' ', '').strip(), expected)

0 comments on commit 4d22571

Please sign in to comment.