def test_create_action_body_with_parameters(requests_mock): client = Client(BASE_URL, 'username', 'password', 'domain') requests_mock.get(BASE_URL + 'session/login', json={'data': { 'session': 'session-id' }}) requests_mock.get(BASE_URL + 'packages/by-name/package-name', json={'data': { 'id': 12345, 'expire_seconds': 360 }}) body = client.build_create_action_body( False, 'action-name', '$1=true;$2=value;$3=otherValue', package_name='package-name', action_group_id=1, target_group_name='target-group-name') body = json.dumps(body) res = json.dumps(CREATE_ACTION_WITH_PARAMETERS_RES) assert res == body
def test_create_action_body_by_host(requests_mock): client = Client(BASE_URL, 'username', 'password', 'domain') requests_mock.get(BASE_URL + 'session/login', json={'data': { 'session': 'session-id' }}) requests_mock.get(BASE_URL + 'packages/20', json={'data': { 'id': 12345, 'expire_seconds': 360 }}) requests_mock.post(BASE_URL + 'parse_question', json=parse_question_res) body = client.build_create_action_body(True, 'action-name', '', package_id=20, action_group_id=1, hostname='host') body = json.dumps(body) res = json.dumps(CREATE_ACTION_BY_HOST_RES) assert res == body
def test_create_action_body_by_target_group_name(requests_mock): client = Client(BASE_URL, 'username', 'password', 'domain') requests_mock.get(BASE_URL + 'session/login', json={'data': { 'session': 'SESSION-ID' }}) requests_mock.get(BASE_URL + 'packages/by-name/package-name', json={'data': { 'id': 12345, 'expire_seconds': 360 }}) body = client.build_create_action_body( False, 'action-name', '', package_name='package-name', action_group_id=1, target_group_name='target-group-name') body = json.dumps(body) res = json.dumps(CREATE_ACTION_BY_TARGET_GROUP_RES) assert res == body
def test_parse_question(requests_mock): client = Client(BASE_URL, 'username', 'password', 'domain') requests_mock.get(BASE_URL + 'session/login', json={'data': {'session': 'session-id'}}) requests_mock.post(BASE_URL + 'parse_question', json=parse_question_Folder_Contents_res) requests_mock.get(BASE_URL + 'sensors/by-name/Folder-Contents', json=sensor_res) results = client.parse_question('Get Folder-Contents[c:\] from all machines', '') assert results['selects'][0]['sensor']['name'] == 'Folder-Contents' assert results['selects'][0]['sensor']['parameters'][0]['key'] == '||folderPath||' assert results['selects'][0]['sensor']['parameters'][0]['value'] == 'c:\\'
def test_update_session(mocker): """ Tests the authentication method, based on the instance configurations. Given: - A client created using username and password - A client created using an API token When: - calling the update_session() function of the client Then: - Verify that the session was created using basic authentication - Verify that the session was created using oauth authentication """ client = Client(BASE_URL, username='******', password='******', domain='domain', api_token='') mocker.patch.object( Client, '_http_request', return_value={'data': { 'session': 'basic authentication' }}) client.update_session() assert client.session == 'basic authentication' client = Client(BASE_URL, username='', password='', domain='domain', api_token='oauth authentication') client.update_session() assert client.session == 'oauth authentication'
def test_get_question_result_invalid_input(): client = Client(BASE_URL, 'username', 'password', 'domain') data_args = {'completion-percentage': '0'} try: _, _, _ = get_question_result(client, data_args) except ValueError as e: assert str(e) == 'completion-percentage argument is invalid, Please enter number between 1 to 100'
def test_parse_action_parameters(parameters, accepted_result): """Tests parse_action_parameters function Given A string representing a key=value list separated by ';' 1. parameters = 'key1=value1' 2. parameters = 'key1=value1=value1' 3. parameters = 'key1=value1=value1;key2=value2' 4. parameters = 'key1=value1=value1;key2=valu;e2' 5. parameters = key1=value1=value1;key2=ab=;c' When When calling the "parse_action_parameters" function to extract it to a dictionary Then validate that everything is extracted properly even if there is within the value "=" or ";" 1. Ensure result = [{'key': 'key1', 'value': 'value1'}] 2. Ensure result = [{'key': 'key1', 'value': 'value1=value1'}] 3. Ensure result = [{'key': 'key1', 'value': 'value1=value1'}, {'key': 'key2', 'value': 'value2'}] 4. Ensure result = [{'key': 'key1', 'value': 'value1=value1'}, {'key': 'key2', 'value': 'valu;e2'}] 5. Ensure result = [{'key': 'key1', 'value': 'value1=value1'}, {'key': 'key2', 'value': 'ab=;c'}] """ client = Client(BASE_URL, 'username', 'password', 'domain') result = client.parse_action_parameters(parameters) assert result == accepted_result
def test_parse_question_results(): client = Client(BASE_URL, 'username', 'password', 'domain') results = client.parse_question_results(QUESTION_RESULTS_RAW, 95) assert results == QUESTION_RESULTS