Skip to content

Commit

Permalink
feat: add POST support to RestClient and Candlepin
Browse files Browse the repository at this point in the history
Add the possibility to perform POST calls to Candlepin,
wiring the support to RestClient.

Signed-off-by: J.C. Molet <[email protected]>
  • Loading branch information
Lorquas committed Jul 15, 2024
1 parent 51ef24c commit f5a433f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pytest_client_tools/candlepin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Candlepin:
This class represents a Candlepin server.
"""

def __init__(self, host, port, prefix, insecure):
def __init__(self, host, port, prefix, insecure, verify=False):
self._host = host
self._port = port
self._prefix = prefix
self._insecure = insecure
self._rest_client = RestClient(
base_url=f"https://{self._host}:{self._port}{self._prefix}",
verify=False,
verify=verify,
)

@property
Expand Down Expand Up @@ -58,6 +58,12 @@ def get(self, path, **kwargs):
"""
return self._rest_client.get(path, **kwargs)

def post(self, path, data, **kwargs):
"""
Perform a POST REST call.
"""
return self._rest_client.post(path, data, **kwargs)

def status(self):
"""
Get the status of the Candlepin server.
Expand Down
20 changes: 19 additions & 1 deletion pytest_client_tools/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import shutil
import subprocess
import tempfile

import pytest

Expand Down Expand Up @@ -91,15 +92,32 @@ def candlepin(request):
"--candlepin-container-is-running"
)
initial_wait = 0
verify = False
if start_container:
stack.enter_context(_create_candlepin_container())
container = _create_candlepin_container()
stack.enter_context(container)
# candlepin takes a while to start
initial_wait = 5
temp_cert = tempfile.NamedTemporaryFile()
stack.enter_context(temp_cert)
subprocess.run(
[
"podman",
"cp",
f"{container.running_id}:/etc/candlepin/certs/candlepin-ca.crt",
temp_cert.name,
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
verify = temp_cert.name
candlepin = Candlepin(
host="localhost",
port=8443,
prefix="/candlepin",
insecure=True,
verify=verify,
)
ping_candlepin(candlepin, initial_wait=initial_wait)
yield candlepin
Expand Down
6 changes: 6 additions & 0 deletions pytest_client_tools/restclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ def get(self, path, **kwargs):
Perform a GET REST call.
"""
return self._request("GET", path, **kwargs)

def post(self, path, data, **kwargs):
"""
Perform a POST REST call.
"""
return self._request("POST", path, json=data, **kwargs)

0 comments on commit f5a433f

Please sign in to comment.