Example #1
0
def test_search_code(requests_mock, mocker):
    raw_response = load_test_data('./test_data/search_code_response.json')
    requests_mock.get(f'{BASE_URL}/search/code?q=create_artifacts%2borg%3ademisto&page=0&per_page=10', json=raw_response)

    mocker.patch.object(demisto, 'params', return_value=MOCK_PARAMS)
    mocker.patch.object(demisto, 'args', return_value={
        'query': 'create_artifacts+org:demisto',
        'limit': '10'
    })
    mocker.patch.object(demisto, 'command', return_value='GitHub-search-code')
    mocker.patch.object(demisto, 'results')

    main()

    results = demisto.results.call_args[0][0]
    assert results['Contents'] == raw_response
    assert len(results['EntryContext']['GitHub.CodeSearchResults(val.html_url == obj.html_url)']) == 7
    assert 'Repository Name' in results['HumanReadable']
Example #2
0
def test_missing_params(mocker, params, expected_result):
    """
    Given:
      - Case 1: credentials with no sshkey.
    When:
      - all the required parameters are missing.
    Then:
      - Ensure the exception message as expected.
      - Case 1: Should return "Insert api token or private key" error message.
    """

    mocker.patch.object(demisto, 'params', return_value=params)
    return_error_mock = mocker.patch(RETURN_ERROR_TARGET)
    main()
    assert return_error_mock.call_count == 1
    # call_args last call with a tuple of args list and kwargs
    err_msg = return_error_mock.call_args[0][0]
    assert expected_result in err_msg
Example #3
0
def test_url_parameter_value(mocker, mock_params, expected_url):
    mocker.patch.object(demisto, 'params', return_value=mock_params)

    main()

    assert GitHub.BASE_URL == expected_url