Skip to content

Commit

Permalink
Fix pipeline (#2101)
Browse files Browse the repository at this point in the history
* remove debug pytest maker
* implement raise_for_status
* add referer ui client
* add sleep namespace test
  • Loading branch information
chr-stian authored Mar 27, 2024
1 parent 59f21ec commit 8326785
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
1 change: 0 additions & 1 deletion galaxy_ng/tests/integration/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions galaxy_ng/tests/integration/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"] != ""
Expand Down
17 changes: 10 additions & 7 deletions galaxy_ng/tests/integration/api/test_ui_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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}/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}/
Expand Down
18 changes: 17 additions & 1 deletion galaxy_ng/tests/integration/utils/client_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 ...
Expand All @@ -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:
Expand All @@ -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

0 comments on commit 8326785

Please sign in to comment.