Skip to content

test: Added first behave integration test for productid plugin#8

Draft
jirihnidek wants to merge 3 commits intomainfrom
jhnidek/behave
Draft

test: Added first behave integration test for productid plugin#8
jirihnidek wants to merge 3 commits intomainfrom
jhnidek/behave

Conversation

@jirihnidek
Copy link
Contributor

  • Card ID: CCT-1921
  • Only one scenario is added. It tests that product certificate is installed, when RPM is installed from testing repository
  • TODO:
    • Add more tests
    • Add documentation
    • Integrate it to our CI

To test this all you need to do is:

  1. Install behave using: sudo dnf -y install python3-behave
  2. Run candlepin container https://github.com/candlepin/candlepin-container-unofficial
  3. And then run: sudo behave

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 13, 2026

Reviewer's Guide

Adds the first Behave-based integration test for the libdnf5 productid plugin, including shared step-implementation helpers for running CLI commands and a scenario that validates a product certificate is installed when an RPM is installed from a test repository.

Sequence diagram for Behave productid integration test scenario

sequenceDiagram
    actor Tester
    participant Behave
    participant Step_Productid
    participant Candlepin_Server
    participant RPM_Repository
    participant System_Filesystem

    Tester->>Behave: run behave
    Behave->>Step_Productid: execute Given system is registered against candlepin server
    Step_Productid->>Candlepin_Server: register system (CLI call)
    Candlepin_Server-->>Step_Productid: registration success

    Behave->>Step_Productid: execute Given repositories are enabled
    Step_Productid->>RPM_Repository: enable never-enabled-content-37060 (CLI call)
    RPM_Repository-->>Step_Productid: repo enabled

    Behave->>Step_Productid: execute When rpm slow-eagle is installed from RPM repository
    Step_Productid->>RPM_Repository: install slow-eagle via dnf or rpm
    RPM_Repository-->>Step_Productid: installation success

    Behave->>Step_Productid: execute Then productid certificate 37060.pem is installed
    Step_Productid->>System_Filesystem: check /etc/pki/product/37060.pem exists
    System_Filesystem-->>Step_Productid: certificate present
    Step_Productid-->>Behave: assertion passed
    Behave-->>Tester: scenario passed
Loading

Class diagram for Behave productid step implementations and helpers

classDiagram
    class Step_Productid {
        +given_system_is_registered_against_candlepin_server(context)
        +given_repositories_are_enabled(context, table)
        +when_rpm_is_installed_from_rpm_repository(context, rpm_name)
        +then_productid_certificate_is_installed(context, certificate_name, directory_path)
    }

    class CliHelper {
        +run_command(command, args, env)
        +assert_success(result)
        +get_stdout(result)
        +get_stderr(result)
    }

    class FileSystemHelper {
        +path_exists(path)
        +assert_file_exists(path)
        +read_file(path)
    }

    class BehaveContext {
        +cli_helper : CliHelper
        +fs_helper : FileSystemHelper
        +registration_data
    }

    Step_Productid --> BehaveContext : uses
    Step_Productid --> CliHelper : uses
    Step_Productid --> FileSystemHelper : uses
    BehaveContext o-- CliHelper : composition
    BehaveContext o-- FileSystemHelper : composition
Loading

Flow diagram for running the new Behave productid test

flowchart TD
    A[Developer installs python3-behave] --> B[Developer starts candlepin container]
    B --> C[Developer runs behave]
    C --> D[Behave loads productid.feature]
    D --> E[Behave parses scenario steps]
    E --> F[Behave maps steps to test_impl_productid step functions]
    F --> G[Execute registration step]
    G --> H[Execute repository enablement step]
    H --> I[Execute RPM installation step]
    I --> J[Execute certificate assertion step]
    J --> K{All assertions pass}
    K -->|Yes| L[Report scenario as passed]
    K -->|No| M[Report scenario as failed]
Loading

File-Level Changes

Change Details Files
Introduce shared Behave step helpers to run shell commands in test scenarios and capture their results in the Behave context.
  • Add generic run() wrapper around subprocess.Popen that returns exit code, stdout, and stderr.
  • Add run_in_context() helper that decorates commands with optional faketime/kernel/locale prefixes, honors scenario working_dir, and stores command results on the Behave context.
  • Implement error handling in run_in_context() that asserts on non-zero exit codes unless explicitly allowed or expected.
features/steps/test_impl_productid.py
Define Behave step implementations to register the system, enable repositories, install RPMs, and verify product certificate installation.
  • Implement step to ensure the system is registered with the candlepin server using rhc status/connect via JSON output.
  • Implement step to enable one or more repositories from a Behave data table via dnf5 config-manager.
  • Implement step to install an RPM from a repository via dnf5 install and a step to assert the expected product certificate file exists in a given directory.
features/steps/test_impl_productid.py
Add a Behave feature describing the first end-to-end scenario for the productid plugin.
  • Create productid.feature with a feature description for productid certificate management.
  • Define a scenario that registers the system, enables the never-enabled-content-37060 repo, installs the slow-eagle RPM, and expects 37060.pem to appear in /etc/pki/product.
features/productid.feature

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@m-horky m-horky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New security issues found

Comment on lines +14 to +22
proc = subprocess.Popen(
cmd,
shell=shell,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
errors="surrogateescape",
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'Popen' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

Base automatically changed from jhnidek/productid_spec to main February 16, 2026 07:13
* Card ID: CCT-1921
* Only one scenario is added. It tests that product certificate
  is installed, when RPM is installed from testing repository

Signed-off-by: Jiri Hnidek <[email protected]>
* Card ID: CCT-1921
* Added check that productid.json contains wanted repo_id
  and product_id
* Make black more happy

Signed-off-by: Jiri Hnidek <[email protected]>
* Added more tests and extend current steps

Signed-off-by: Jiri Hnidek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants