Skip to content

Commit

Permalink
Made api quirks idempotent
Browse files Browse the repository at this point in the history
fixes #752
  • Loading branch information
mdellweg committed Jul 28, 2023
1 parent 82d0493 commit a0c1fe4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/752.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made api-quirks idempotent to prevent them from failing once the original api is fixed.
4 changes: 2 additions & 2 deletions pulp-glue/pulp_glue/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ def _patch_api_spec(self) -> None:
parameter["schema"] = {"type": "array", "items": {"type": "string"}}
if self.has_plugin(PluginRequirement("core", specifier=">=3.23,<3.30.0")):
operation = api_spec["paths"]["{upstream_pulp_href}replicate/"]["post"]
operation.pop("requestBody")
operation.pop("requestBody", None)
if self.has_plugin(PluginRequirement("file", specifier=">=1.10.0,<1.11.0")):
operation = api_spec["paths"]["{file_file_alternate_content_source_href}refresh/"][
"post"
]
operation.pop("requestBody")
operation.pop("requestBody", None)
if self.has_plugin(PluginRequirement("python", specifier="<99.99.0.dev")):
# TODO Add version bounds
python_remote_serializer = api_spec["components"]["schemas"]["python.PythonRemote"]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ skip = ["pulp-glue"]

[tool.pytest.ini_options]
markers = [
"glue: tests for pulp-glue in isolation",
"script: tests provided as shell scripts",
"help_page: tests that render help pages",
"pulpcore: pulpcore tests",
Expand All @@ -76,7 +77,7 @@ markers = [
[tool.mypy]
strict = true
show_error_codes = true
files = "pulpcore/**/*.py, pulp_cli/**/*.py"
files = "pulpcore/**/*.py, pulp_cli/**/*.py, tests/*.py"
namespace_packages = true
explicit_package_bases = true

Expand Down
2 changes: 2 additions & 0 deletions pytest_pulp_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# type: ignore

import os
import pathlib
import subprocess
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing as t
from urllib.parse import urljoin

import pytest
Expand All @@ -6,7 +7,7 @@


@pytest.fixture
def pulp_cli_vars(pulp_cli_vars):
def pulp_cli_vars(pulp_cli_vars: t.Dict[str, str]) -> t.Dict[str, str]:
PULP_FIXTURES_URL = pulp_cli_vars["PULP_FIXTURES_URL"]
result = {}
result.update(pulp_cli_vars)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_api_quirks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import typing as t
from copy import deepcopy

import pytest
from pulp_glue.common.context import PulpContext


@pytest.mark.glue
def test_api_quirks_idempotent(
pulp_cli_settings: t.Tuple[t.Any, t.Dict[str, t.Dict[str, t.Any]]]
) -> None:
"""
Test, that the applied api quirks can be applied twice without failing.
This can let us hope they will not fail once the api is fixed upstream.
"""
settings = pulp_cli_settings[1]["cli"]
pulp_ctx = PulpContext(
api_kwargs={"base_url": settings["base_url"]},
api_root=settings.get("api_root", "pulp/"),
background_tasks=False,
timeout=settings.get("timeout", 120),
)
patched_once_api = deepcopy(pulp_ctx.api.api_spec)
# Patch a second time
pulp_ctx._patch_api_spec()
assert pulp_ctx.api.api_spec == patched_once_api

0 comments on commit a0c1fe4

Please sign in to comment.