diff --git a/galaxy_ng/tests/integration/api/test_auth.py b/galaxy_ng/tests/integration/api/test_auth.py index 29d0662d2c..ac1ede5dba 100644 --- a/galaxy_ng/tests/integration/api/test_auth.py +++ b/galaxy_ng/tests/integration/api/test_auth.py @@ -116,7 +116,6 @@ def test_gateway_token_auth(galaxy_client): @pytest.mark.deployment_standalone -@pytest.mark.this def test_ui_login_csrftoken(galaxy_client): if is_keycloak(): pytest.skip("This test is not valid for keycloak") diff --git a/galaxy_ng/tests/integration/api/test_groups.py b/galaxy_ng/tests/integration/api/test_groups.py index 77fdaa6ef5..ba9a9b5e08 100644 --- a/galaxy_ng/tests/integration/api/test_groups.py +++ b/galaxy_ng/tests/integration/api/test_groups.py @@ -8,6 +8,7 @@ import uuid import pytest +from requests import HTTPError from galaxykit.groups import create_group_v3, create_group, get_roles, \ delete_group_v3, get_group_v3 @@ -121,5 +122,6 @@ def test_group_role_listing(ansible_config, test_data): del_group_resp = uclient.delete(f'pulp/api/v3/groups/{group_response["id"]}/') assert del_group_resp.status_code == 204 - detail_group_response = uclient.get(f'pulp/api/v3/groups/{group_response["id"]}/') - assert detail_group_response.status_code == 404 + with pytest.raises(HTTPError) as ctx: + uclient.get(f'pulp/api/v3/groups/{group_response["id"]}/') + assert ctx.value.strerror.status_code == 404 diff --git a/galaxy_ng/tests/integration/api/test_namespace_management.py b/galaxy_ng/tests/integration/api/test_namespace_management.py index e20c794d1b..66b0101dde 100644 --- a/galaxy_ng/tests/integration/api/test_namespace_management.py +++ b/galaxy_ng/tests/integration/api/test_namespace_management.py @@ -164,6 +164,7 @@ def test_namespace_edit_logo(galaxy_client): "avatar_url": "https://avatars.githubusercontent.com/u/1869705?v=4" } gc.put(f"_ui/v1/my-namespaces/{name}/", body=payload) + sleep(60) wait_for_all_tasks_gk(gc) updated_namespace = gc.get(f'_ui/v1/my-namespaces/{name}/') assert updated_namespace["avatar_url"] != "" diff --git a/galaxy_ng/tests/integration/api/test_ui_paths.py b/galaxy_ng/tests/integration/api/test_ui_paths.py index 6a7018e4e4..1622d71f9c 100644 --- a/galaxy_ng/tests/integration/api/test_ui_paths.py +++ b/galaxy_ng/tests/integration/api/test_ui_paths.py @@ -9,6 +9,7 @@ from orionutils.generator import build_collection from ansible.galaxy.api import GalaxyError from jsonschema import validate as validate_json +from requests import HTTPError from ..constants import DEFAULT_DISTROS, USERNAME_PUBLISHER from ..schemas import ( @@ -163,8 +164,9 @@ def test_api_ui_v1_collection_versions_version_range(ansible_config, uncertified assert ds['data'][0]["version"] == c2.version # test invalid - resp = uclient.get(f'{v_path}&version_range=not_a_semver_version') - assert resp.status_code == 400 + with pytest.raises(HTTPError) as ctx: + uclient.get(f'{v_path}&version_range=not_a_semver_version') + assert ctx.value.strerror.status_code == 400 # /api/automation-hub/_ui/v1/collection-versions/{version}/ @@ -325,9 +327,9 @@ def test_api_ui_v1_execution_environments_registries(ansible_config): assert resp.status_code == 204 # make sure it's gone - resp = uclient.get(f"_ui/v1/execution-environments/registries/{id}/") - assert resp.status_code == 404 - + with pytest.raises(HTTPError) as ctx: + uclient.get(f"_ui/v1/execution-environments/registries/{id}/") + assert ctx.value.strerror.status_code == 404 # /api/automation-hub/_ui/v1/execution-environments/registries/{pulp_id}/ # ^ tested by previous function @@ -713,8 +715,9 @@ def test_api_ui_v1_remotes_by_id(ansible_config): # FIXME - there is no suitable pulp_id for a remote? pulp_ids = [x['pk'] for x in ds['data']] for pulp_id in pulp_ids: - resp = uclient.get('_ui/v1/remotes/{pulp_id}/') - assert resp.status_code == 404 + with pytest.raises(HTTPError) as ctx: + uclient.get('_ui/v1/remotes/{pulp_id}/') + assert ctx.value.strerror.status_code == 404 # /api/automation-hub/_ui/v1/repo/{distro_base_path}/ diff --git a/galaxy_ng/tests/integration/utils/client_ui.py b/galaxy_ng/tests/integration/utils/client_ui.py index 43d5a1ea7f..9e02dbb592 100644 --- a/galaxy_ng/tests/integration/utils/client_ui.py +++ b/galaxy_ng/tests/integration/utils/client_ui.py @@ -10,6 +10,13 @@ logger = logging.getLogger(__name__) +def raise_for_status(response): + if 400 <= response.status_code: + http_error_msg = f'{response.status_code} Error: {response.text}' + logging.debug(http_error_msg) + raise requests.exceptions.HTTPError(http_error_msg, response) + + class UIClient: """ An HTTP client to mimic the UI """ @@ -83,6 +90,7 @@ def galaxy_login(self): headers=pheaders, json={'username': self.username, 'password': self.password} ) + raise_for_status(resp) # assert that the login succeeded assert resp.status_code in (200, 204) @@ -95,6 +103,7 @@ def keycloak_login(self): self.baseurl.split("/api/")[0] + "/login/", allow_redirects=True, ) + raise_for_status(resp) # assert that the keycloak login page loaded correctly assert resp.status_code == 200 @@ -112,6 +121,7 @@ def keycloak_login(self): }, allow_redirects=True, ) + raise_for_status(resp) # assert that the login succeeded assert resp.status_code in (200, 204) @@ -129,6 +139,7 @@ def logout(self, expected_code=None): 'Referer': self.login_url, } res = self._rs.post(self.logout_url, json={}, headers=pheaders) + raise_for_status(res) if expected_code is not None: if res.status_code != expected_code: @@ -158,6 +169,7 @@ def get(self, relative_url: str = None, absolute_url: str = None) -> requests.mo # get the response resp = self._rs.get(this_url, headers=pheaders) + raise_for_status(resp) return resp def get_paginated(self, relative_url: str = None, absolute_url: str = None) -> list: @@ -206,12 +218,14 @@ def post(self, relative_url: str, payload: dict) -> requests.models.Response: # get the response resp = self._rs.post(self.baseurl + relative_url, json=payload, headers=pheaders) + raise_for_status(resp) return resp def put(self, relative_url: str, payload: dict) -> requests.models.Response: pheaders = { 'Accept': 'application/json', - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Referer': self.login_url } # send cookies whenever possible ... @@ -226,6 +240,7 @@ def put(self, relative_url: str, payload: dict) -> requests.models.Response: # get the response resp = self._rs.put(self.baseurl + relative_url, json=payload, headers=pheaders) + raise_for_status(resp) return resp def delete(self, relative_url: str) -> requests.models.Response: @@ -246,4 +261,5 @@ def delete(self, relative_url: str) -> requests.models.Response: # get the response resp = self._rs.delete(self.baseurl + relative_url, headers=pheaders) + raise_for_status(resp) return resp