From 9bcf70ddab84ce28172b91526a132e752baba1fc Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 5 Nov 2024 14:32:39 +0100 Subject: [PATCH] lce/cv --- tests/conftest.py | 13 +++++++++++++ tests/foreman_api_test.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 19e7d7d..365e15d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -49,3 +49,16 @@ def container_repository(product, organization, foremanapi): repo = foremanapi.create('repositories', {'name': str(uuid.uuid4()), 'product_id': product['id'], 'content_type': 'docker', 'url': 'https://quay.io/', 'docker_upstream_name': 'foreman/busybox-test'}) yield repo foremanapi.delete('repositories', repo) + +@pytest.fixture +def lifecycle_environment(organization, foremanapi): + library = foremanapi.list('lifecycle_environments', 'name=Library', {'organization_id': organization['id']})[0] + lce = foremanapi.create('lifecycle_environments', {'name': str(uuid.uuid4()), 'organization_id': organization['id'], 'prior_id': library['id']}) + yield lce + foremanapi.delete('lifecycle_environments', lce) + +@pytest.fixture +def content_view(organization, foremanapi): + cv = foremanapi.create('content_views', {'name': str(uuid.uuid4()), 'organization_id': organization['id']}) + yield cv + foremanapi.delete('content_views', cv) diff --git a/tests/foreman_api_test.py b/tests/foreman_api_test.py index 816f1ad..f9b8ef0 100644 --- a/tests/foreman_api_test.py +++ b/tests/foreman_api_test.py @@ -31,3 +31,20 @@ def test_foreman_file_repository(file_repository, foremanapi, ssh_config): def test_foreman_container_repository(container_repository, foremanapi, ssh_config): assert container_repository foremanapi.resource_action('repositories', 'sync', {'id': container_repository['id']}) + + +def test_foreman_lifecycle_environment(lifecycle_environment): + assert lifecycle_environment + + +def test_foreman_content_view(content_view, yum_repository, foremanapi): + assert content_view + foremanapi.update('content_views', {'id': content_view['id'], 'repository_ids': [yum_repository['id']]}) + foremanapi.resource_action('content_views', 'publish', {'id': content_view['id']}) + # do something with the published view + versions = foremanapi.list('content_view_versions', params={'content_view_id': content_view['id']}) + for version in versions: + current_environment_ids = {environment['id'] for environment in version['environments']} + for environment_id in current_environment_ids: + foremanapi.resource_action('content_views', 'remove_from_environment', params={'id': content_view['id'], 'environment_id': environment_id}) + foremanapi.delete('content_view_versions', version)