def test_request_error(patch_session): cli = BaseCliApi(TEST_HOST, TEST_APIKEY, username=TEST_USER, password=TEST_PASS) patch_session().request.side_effect = Exception with pytest.raises(CliArrError): cli.request_get(TEST_PATH) assert patch_session().headers == {"X-Api-Key": TEST_APIKEY} patch_session().request.assert_called_with("GET", f"{TEST_HOST}{TEST_PATH}", params=None, json=None)
def test_server_error(patch_session): cli = BaseCliApi(TEST_HOST, TEST_APIKEY, username=TEST_USER, password=TEST_PASS) patch_session().request.return_value = mock_response(400, Exception) with pytest.raises(CliServerError): cli.request_get(TEST_PATH) assert patch_session().headers == {"X-Api-Key": TEST_APIKEY} patch_session().request.assert_called_with("GET", f"{TEST_HOST}{TEST_PATH}", params=None, json=None)
def test_get_with_auth(patch_session): cli = BaseCliApi(TEST_HOST, TEST_APIKEY, username=TEST_USER, password=TEST_PASS) patch_session().request.return_value = mock_response(200, [TEST_JSON]) rep = cli.request_get(TEST_PATH, {'param': 'value'}) cli.close() assert patch_session().headers == {"X-Api-Key": TEST_APIKEY} patch_session().request.assert_called_with("GET", f"{TEST_HOST}{TEST_PATH}", params={'param': 'value'}, json=None) patch_session().close.assert_called() assert rep == TEST_JSON