Skip to content

Commit

Permalink
Use apypie for apidoc parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik committed Mar 15, 2024
1 parent ef66b07 commit 7a401b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version updates managed by dependabot

apypie==0.4.0
betelgeuse==1.11.0
# broker[docker]==0.4.1 - Temporarily disabled, see below
cryptography==42.0.5
Expand Down
15 changes: 15 additions & 0 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from urllib.parse import urljoin, urlparse, urlunsplit
import warnings

import apypie
from box import Box
from broker import Broker
from broker.hosts import Host
Expand Down Expand Up @@ -1762,6 +1763,7 @@ def __init__(self, hostname=None, **kwargs):
# create dummy classes for later population
self._api = type('api', (), {'_configured': False})
self._cli = type('cli', (), {'_configured': False})
self._apidoc = None
self.record_property = None

def _swap_nailgun(self, new_version):
Expand Down Expand Up @@ -1815,6 +1817,19 @@ class DecClass(cls):
self._api._configured = True
return self._api

@property
def apidoc(self):
"""Provide Satellite's apidoc via apypie"""
if not self._apidoc:
self._apidoc = apypie.Api(
uri=self.url,
username=settings.server.admin_username,
password=settings.server.admin_password,
api_version=2,
verify_ssl=False,
).apidoc
return self._apidoc

@property
def cli(self):
"""Import all robottelo cli entities and wrap them under self.cli"""
Expand Down
25 changes: 9 additions & 16 deletions tests/foreman/api/test_capsulecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
from datetime import datetime, timedelta
import re
from time import sleep
from urllib.parse import urlparse

from nailgun import client
from nailgun.entity_mixins import call_entity_method_with_timeout
import pytest

from robottelo.config import get_credentials, settings
from robottelo.config import settings
from robottelo.constants import (
CONTAINER_CLIENTS,
CONTAINER_REGISTRY_HUB,
Expand Down Expand Up @@ -1671,19 +1670,13 @@ def test_positive_reclaim_space(
assert 'success' in task['result'], 'Reclaim task did not succeed'

# Check the apidoc references the correct endpoint
response = client.get(
f'{target_sat.url}/apidoc/v2/capsule_content/reclaim_space.en.html',
auth=get_credentials(),
verify=False,
reclaim_doc = next(
method
for method in target_sat.apidoc['docs']['resources']['capsule_content']['methods']
if '/apidoc/v2/capsule_content/reclaim_space' in method['doc_url']
)
assert len(reclaim_doc['apis']) == 1
assert reclaim_doc['apis'][0]['http_method'] == 'POST', 'POST method was expected.'
assert (
response.status_code == 200
), f'{response.request.path} returned HTTP{response.status_code}'

ep_path = target_sat.api.Capsule(id=module_capsule_configured.nailgun_capsule.id).path(
which='content_reclaim_space'
)
ep_path = urlparse(ep_path).path
ep_path = ep_path.replace(str(module_capsule_configured.nailgun_capsule.id), ':id')

assert f'POST {ep_path}' in response.text, 'Reclaim_space endpoint path missing in apidoc'
reclaim_doc['apis'][0]['api_url'] == '/katello/api/capsules/:id/content/reclaim_space'
), 'Documented path did not meet the expectation.'

0 comments on commit 7a401b4

Please sign in to comment.