From 2a77e2e7fe93953720e2df79306c50f7809103b2 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 30 Oct 2024 09:40:06 +0100 Subject: [PATCH] yum/file --- tests/conftest.py | 10 ++++++++-- tests/foreman_api_test.py | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fb43b11..b99bf54 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,7 +33,13 @@ def product(organization, foremanapi): foremanapi.delete('products', prod) @pytest.fixture -def repository(product, organization, foremanapi): - repo = foremanapi.create('repositories', {'name': str(uuid.uuid4()), 'product_id': product['id'], 'content_type': 'yum'}) +def yum_repository(product, organization, foremanapi): + repo = foremanapi.create('repositories', {'name': str(uuid.uuid4()), 'product_id': product['id'], 'content_type': 'yum', 'url': 'https://fixtures.pulpproject.org/rpm-no-comps/'}) + yield repo + foremanapi.delete('repositories', repo) + +@pytest.fixture +def file_repository(product, organization, foremanapi): + repo = foremanapi.create('repositories', {'name': str(uuid.uuid4()), 'product_id': product['id'], 'content_type': 'file', 'url': 'https://fixtures.pulpproject.org/file/'}) yield repo foremanapi.delete('repositories', repo) diff --git a/tests/foreman_api_test.py b/tests/foreman_api_test.py index 9b8e449..4472084 100644 --- a/tests/foreman_api_test.py +++ b/tests/foreman_api_test.py @@ -1,8 +1,28 @@ +import urllib.parse + +import requests + + +def _repo_url(repo, ssh_config): + return urllib.parse.urlunparse(urllib.parse.urlparse(repo['full_path'])._replace(netloc=ssh_config['hostname'])) + + def test_foreman_organization(organization): assert organization def test_foreman_product(product): assert product -def test_foreman_repository(repository): - assert repository +def test_foreman_yum_repository(yum_repository, foremanapi, ssh_config): + assert yum_repository + foremanapi.resource_action('repositories', 'sync', {'id': yum_repository['id']}) + repo_url = _repo_url(yum_repository, ssh_config) + assert requests.get(f'{repo_url}/repodata/repomd.xml', verify=False) + assert requests.get(f'{repo_url}/Packages/b/bear-4.1-1.noarch.rpm', verify=False) + + +def test_foreman_file_repository(file_repository, foremanapi, ssh_config): + assert file_repository + foremanapi.resource_action('repositories', 'sync', {'id': file_repository['id']}) + repo_url = _repo_url(file_repository, ssh_config) + assert requests.get(f'{repo_url}/1.iso', verify=False)