def test_status_scan(requests_mock): """Tests helloworld-scan-status command function. Configures requests_mock instance to generate the appropriate check_scan API responses based on the scan ID provided. For scan_id 100, 300 status should be COMPLETE while for scan ID 200 is RUNNING. Checks the output of the command function with the expected output. """ from HelloWorld import Client, scan_status_command mock_response = { 'scan_id': '100', 'status': 'COMPLETE' } requests_mock.get('https://test.com/api/v1/check_scan?scan_id=100', json=mock_response) mock_response = { 'scan_id': '200', 'status': 'RUNNING' } requests_mock.get('https://test.com/api/v1/check_scan?scan_id=200', json=mock_response) mock_response = { 'scan_id': '300', 'status': 'COMPLETE' } requests_mock.get('https://test.com/api/v1/check_scan?scan_id=300', json=mock_response) client = Client( base_url='https://test.com/api/v1', verify=False, headers={ 'Authentication': 'Bearer some_api_key' } ) args = { 'scan_id': ['100', '200', '300'] } response = scan_status_command(client, args) assert response.outputs_prefix == 'HelloWorld.Scan' assert response.outputs_key_field == 'scan_id' assert response.outputs == [ { 'scan_id': '100', 'status': 'COMPLETE' }, { 'scan_id': '200', 'status': 'RUNNING' }, { 'scan_id': '300', 'status': 'COMPLETE' } ]
def test_status_scan(requests_mock): from HelloWorld import Client, scan_status_command mock_response = { "scan_id": "100", "status": "COMPLETE" } requests_mock.get('https://test.com/api/v1/check_scan?scan_id=100', json=mock_response) mock_response = { "scan_id": "200", "status": "RUNNING" } requests_mock.get('https://test.com/api/v1/check_scan?scan_id=200', json=mock_response) mock_response = { "scan_id": "300", "status": "COMPLETE" } requests_mock.get('https://test.com/api/v1/check_scan?scan_id=300', json=mock_response) client = Client( base_url='https://test.com/api/v1', verify=False, headers={ 'Authentication': 'Bearer some_api_key' } ) args = { 'scan_id': ['100', '200', '300'] } _, outputs, _ = scan_status_command(client, args) assert outputs == { 'HelloWorld.Scan(val.scan_id == obj.scan_id)': [ { "scan_id": "100", "status": "COMPLETE" }, { "scan_id": "200", "status": "RUNNING" }, { "scan_id": "300", "status": "COMPLETE" } ] }
def test_status_scan(requests_mock): """Tests helloworld-scan-status command function. Configures requests_mock instance to generate the appropriate check_scan API responses based on the scan ID provided. For scan_id 100, 300 status should be COMPLETE while for scan ID 200 is RUNNING. Checks the output of the command function with the expected output. """ from HelloWorld import Client, scan_status_command mock_response = {"scan_id": "100", "status": "COMPLETE"} requests_mock.get('https://test.com/api/v1/check_scan?scan_id=100', json=mock_response) mock_response = {"scan_id": "200", "status": "RUNNING"} requests_mock.get('https://test.com/api/v1/check_scan?scan_id=200', json=mock_response) mock_response = {"scan_id": "300", "status": "COMPLETE"} requests_mock.get('https://test.com/api/v1/check_scan?scan_id=300', json=mock_response) client = Client(base_url='https://test.com/api/v1', verify=False, headers={'Authentication': 'Bearer some_api_key'}) args = {'scan_id': ['100', '200', '300']} _, outputs, _ = scan_status_command(client, args) assert outputs == { 'HelloWorld.Scan(val.scan_id == obj.scan_id)': [{ "scan_id": "100", "status": "COMPLETE" }, { "scan_id": "200", "status": "RUNNING" }, { "scan_id": "300", "status": "COMPLETE" }] }