def test_url_multiple_arg(url, multiple, expected_data): '''Scenario: Submit a URL with commas in it Given - A URL with commas in it When - case A: 'multiple' argument is set to "true" (the default) - case B: 'multiple' argument is set to "false" Then - case A: Ensure the URL is interpreted as multiple values to be sent in the subsequent API call - case B: Ensure the URL is interpreted as a single value to be sent in the subsequent API call Args: url (str): The URL to submit. multiple (str): "true" or "false" - whether to interpret the 'url' argument as multiple comma separated values. expected_data (list): The data expected to be sent in the API call. ''' import Zscaler with requests_mock.mock() as m: # 'fake_resp_content' doesn't really matter here since we are checking the data being sent in the call, # not what it is that we expect to get in response fake_resp_content = '[{"url": "blah", "urlClassifications": [], "urlClassificationsWithSecurityAlert": []}]' m.post(Zscaler.BASE_URL + '/urlLookup', content=fake_resp_content) args = {'url': url, 'multiple': multiple} Zscaler.url_lookup(args) assert m.called assert m.call_count == 1 request_data = m.last_request.json() assert len(request_data) == len(expected_data) assert request_data == expected_data
def test_url_fails_unknown_error_code(mocker, requests_mock): """url""" import Zscaler Zscaler.BASE_URL = 'http://cloud/api/v1' requests_mock.post(urljoin(Zscaler.BASE_URL, 'urlLookup'), status_code=501) args = { 'url': 'https://www.demisto-news.com,https://www.demisto-search.com' } try: Zscaler.url_lookup(args) except Exception as ex: assert 'following error: 501' in str(ex)