From 5277f3aeaefe16435c55ef0f87859de4803e2ddd Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 08:46:32 -0500 Subject: [PATCH] Fix list-signing-services output format and add unit tests (#121) Co-authored-by: daviddavis --- CHANGES/+fix-list-signing-services-cmd.bugfix | 1 + .../commands/list-signing-services.py | 2 +- .../test_list_signing_services_command.py | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 CHANGES/+fix-list-signing-services-cmd.bugfix create mode 100644 pulpcore/tests/unit/test_list_signing_services_command.py diff --git a/CHANGES/+fix-list-signing-services-cmd.bugfix b/CHANGES/+fix-list-signing-services-cmd.bugfix new file mode 100644 index 00000000000..1d301cbe88a --- /dev/null +++ b/CHANGES/+fix-list-signing-services-cmd.bugfix @@ -0,0 +1 @@ +Fix an error when running `pulpcore-manager list-signing-services`. diff --git a/pulpcore/app/management/commands/list-signing-services.py b/pulpcore/app/management/commands/list-signing-services.py index 1b4cbda7e31..ef89ea414c2 100644 --- a/pulpcore/app/management/commands/list-signing-services.py +++ b/pulpcore/app/management/commands/list-signing-services.py @@ -15,4 +15,4 @@ def add_arguments(self, parser): def handle(self, *args, **options): SigningService = apps.get_model("core", "SigningService") results = list(SigningService.objects.all().values_list("name", flat=True)) - self.stdout.write(results) + self.stdout.write("\n".join(results)) diff --git a/pulpcore/tests/unit/test_list_signing_services_command.py b/pulpcore/tests/unit/test_list_signing_services_command.py new file mode 100644 index 00000000000..87421b48615 --- /dev/null +++ b/pulpcore/tests/unit/test_list_signing_services_command.py @@ -0,0 +1,44 @@ +import pytest +from io import StringIO +from unittest.mock import patch + +from django.core.management import call_command + +from pulpcore.app.models.content import AsciiArmoredDetachedSigningService + + +@pytest.mark.django_db +def test_list_signing_services_empty(): + """Test the list-signing-services command with no signing services.""" + out = StringIO() + call_command("list-signing-services", stdout=out) + assert out.getvalue().strip() == "" + + +@pytest.mark.django_db +def test_list_signing_services(tmp_path): + """Test the list-signing-services command with multiple signing services.""" + # Create a dummy script file + script_file = tmp_path / "signing_script.sh" + script_file.write_text("#!/bin/bash\necho 'test'") + + # Create multiple signing services with mocked validate() method + for name in ["service-a", "service-b", "service-c"]: + service = AsciiArmoredDetachedSigningService( + name=name, + public_key=f"key-{name[-1]}", + pubkey_fingerprint=f"fingerprint-{name[-1]}", + script=str(script_file), + ) + # Mock the validate method to bypass GPG verification + with patch.object(service, "validate", return_value=None): + service.save() + + out = StringIO() + call_command("list-signing-services", stdout=out) + output_lines = out.getvalue().strip().split("\n") + + # Check that all service names are present + assert "service-a" in output_lines + assert "service-b" in output_lines + assert "service-c" in output_lines