def test_endpoint_command(mocker, requests_mock): """Unit test Given - a hostname When - we mock the endpoint command Then - Validate that there is one result - Validate that the correct readable output is returned """ from GuardiCoreV2 import Client, endpoint_command mock_response = util_load_json('test_data/get_endpoint_response.json') requests_mock.post( 'https://api.guardicoreexample.com/api/v3.0/authenticate', json={'access_token': TEST_API_KEY}) client = Client(base_url='https://api.guardicoreexample.com/api/v3.0', verify=False, proxy=False, username='******', password='******') args = {'hostname': 'Accounting-web-1'} mocker.patch.object(client, '_http_request', return_value=mock_response) response = endpoint_command(client, args) assert len(response) == 1 assert response[0].readable_output == open( 'test_data/endpoint_command_human.md').read()
def test_endpoint_command_fails(mocker, requests_mock): """Unit test Given - no parameters When - we mock the endpoint command Then - Validate that there is a correct error """ from GuardiCoreV2 import Client, endpoint_command mock_response = util_load_json('test_data/get_endpoint_response.json') requests_mock.post( 'https://api.guardicoreexample.com/api/v3.0/authenticate', json={'access_token': TEST_API_KEY}) client = Client(base_url='https://api.guardicoreexample.com/api/v3.0', verify=False, proxy=False, username='******', password='******') args = {} mocker.patch.object(client, '_http_request', return_value=mock_response) with raises(DemistoException): endpoint_command(client, args)