From 6d1786fe0c6f5e25e11b908015e692b92c8c85c4 Mon Sep 17 00:00:00 2001 From: Cole Higgins Date: Thu, 12 Oct 2023 08:49:25 -0400 Subject: [PATCH] [Repository Rewrite] Added test for publishing invalid repository (#12322) * Adding test for invalid repository publish * fixed flake 8 issues with too many chars --- tests/foreman/cli/test_repositories.py | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/foreman/cli/test_repositories.py b/tests/foreman/cli/test_repositories.py index f35a93603ab..2a98e9dbd58 100644 --- a/tests/foreman/cli/test_repositories.py +++ b/tests/foreman/cli/test_repositories.py @@ -17,6 +17,7 @@ :Upstream: No """ import pytest +from requests.exceptions import HTTPError @pytest.mark.rhel_ver_match('[^6]') @@ -47,3 +48,40 @@ def test_positive_custom_products_disabled_by_default( assert rhel_contenthost.subscribed product_details = rhel_contenthost.run('subscription-manager repos --list') assert 'Enabled: 0' in product_details.stdout + + +def test_negative_invalid_repo_fails_publish( + module_repository, + module_org, + target_sat, +): + """Verify that an invalid repository fails when trying to publish in a content view + + :id: 64e03f28-8213-467a-a229-44c8cbfaaef1 + + :steps: + 1. Create custom product and upload repository + 2. Run Katello commands to make repository invalid + 3. Create content view and add repository + 4. Verify Publish fails + + :expectedresults: Publishing a content view with an invalid repository fails + + :customerscenario: true + + :BZ: 2032040 + """ + repo = module_repository + target_sat.execute( + 'echo "root = ::Katello::RootRepository.last; ::Katello::Resources::Candlepin::Product.' + 'remove_content(root.product.organization.label, root.product.cp_id, root.content_id); ' + '::Katello::Resources::Candlepin::Content.destroy(root.product.organization.label, ' + 'root.content_id)" | foreman-rake console' + ) + cv = target_sat.api.ContentView( + organization=module_org.name, + repository=[repo.id], + ).create() + with pytest.raises(HTTPError) as context: + cv.publish() + assert 'Remove the invalid repository before publishing again' in context.value.response.text