Migrate 10 tests to use module_import_sat instead of target_sat#21687
Migrate 10 tests to use module_import_sat instead of target_sat#21687vsedmik wants to merge 1 commit into
Conversation
Reviewer's GuideThis PR migrates ten ISS export/import tests to use a dedicated import Satellite instance ( File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
PRT Result |
|
|
PRT Result |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Several tests now directly set
subscription_connection_enabledto'No'onmodule_import_satwithout any teardown, which risks leaking state across tests; consider introducing a fixture (e.g.import_satellite_disconnected) that manages this setting and restores the previous value. - In tests like the Ansible collection and podman repo scenarios, the code relies on
Product.list(...)[0]orRepository.list(...)[0], which can be fragile if multiple items exist; it would be more robust to fetch the product/repository by name and product name instead of assuming the first element is the one just created.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Several tests now directly set `subscription_connection_enabled` to `'No'` on `module_import_sat` without any teardown, which risks leaking state across tests; consider introducing a fixture (e.g. `import_satellite_disconnected`) that manages this setting and restores the previous value.
- In tests like the Ansible collection and podman repo scenarios, the code relies on `Product.list(...)[0]` or `Repository.list(...)[0]`, which can be fragile if multiple items exist; it would be more robust to fetch the product/repository by name and product name instead of assuming the first element is the one just created.
## Individual Comments
### Comment 1
<location path="tests/foreman/cli/test_satellitesync.py" line_range="1016-1017" />
<code_context>
- target_sat.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': "No"})
- target_sat.cli.ContentImport.library(
- {'organization-id': function_import_org_with_manifest.id, 'path': import_path}
+ module_import_sat.cli.Settings.set(
+ {'name': 'subscription_connection_enabled', 'value': 'No'}
)
- importing_cvv = target_sat.cli.ContentView.info(
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid leaking `subscription_connection_enabled` setting changes across tests
These tests (e.g. `test_positive_export_import_default_org_view`, `test_positive_export_import_filtered_cvv`, `test_positive_export_import_redhat_cv`) disable `subscription_connection_enabled` on the shared `module_import_sat` but never restore it, so later tests can see the modified state and become order-dependent. Please encapsulate this in a helper (fixture/context manager) that saves and restores the original value (e.g. via `finally` or `monkeypatch`) so each test leaves `module_import_sat` in a clean state.
Suggested implementation:
```python
# Import and verify content of library
with subscription_connection_disabled(module_import_sat):
module_import_sat.cli.ContentImport.library(
{
'organization-id': function_import_org_at_isat_with_manifest.id,
'path': import_path,
}
)
```
To fully implement the suggestion across the file:
1. **Add a context manager helper** near the top of `tests/foreman/cli/test_satellitesync.py` (e.g. next to other test utilities):
```python
from contextlib import contextmanager
@contextmanager
def subscription_connection_disabled(satellite):
# Read and save the original value; adjust to actual Settings API if different
original = satellite.cli.Settings.info({'name': 'subscription_connection_enabled'})['value']
try:
satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': 'No'})
yield
finally:
satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': original})
```
If `Settings.info` is not the correct API, replace it with whatever call returns the current value of `subscription_connection_enabled`.
2. **Update all other tests** in this file that currently do:
```python
module_import_sat.cli.Settings.set(
{'name': 'subscription_connection_enabled', 'value': 'No'}
)
module_import_sat.cli.ContentImport.library(...)
```
to use the context manager instead:
```python
with subscription_connection_disabled(module_import_sat):
module_import_sat.cli.ContentImport.library(...)
```
This includes at least the tests mentioned in your comment:
- `test_positive_export_import_default_org_view`
- `test_positive_export_import_filtered_cvv`
- `test_positive_export_import_redhat_cv`
These changes ensure `subscription_connection_enabled` is always restored to its original value, avoiding leakage across tests and order-dependence.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| module_import_sat.cli.Settings.set( | ||
| {'name': 'subscription_connection_enabled', 'value': 'No'} |
There was a problem hiding this comment.
suggestion (testing): Avoid leaking subscription_connection_enabled setting changes across tests
These tests (e.g. test_positive_export_import_default_org_view, test_positive_export_import_filtered_cvv, test_positive_export_import_redhat_cv) disable subscription_connection_enabled on the shared module_import_sat but never restore it, so later tests can see the modified state and become order-dependent. Please encapsulate this in a helper (fixture/context manager) that saves and restores the original value (e.g. via finally or monkeypatch) so each test leaves module_import_sat in a clean state.
Suggested implementation:
# Import and verify content of library
with subscription_connection_disabled(module_import_sat):
module_import_sat.cli.ContentImport.library(
{
'organization-id': function_import_org_at_isat_with_manifest.id,
'path': import_path,
}
)To fully implement the suggestion across the file:
- Add a context manager helper near the top of
tests/foreman/cli/test_satellitesync.py(e.g. next to other test utilities):
from contextlib import contextmanager
@contextmanager
def subscription_connection_disabled(satellite):
# Read and save the original value; adjust to actual Settings API if different
original = satellite.cli.Settings.info({'name': 'subscription_connection_enabled'})['value']
try:
satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': 'No'})
yield
finally:
satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': original})If Settings.info is not the correct API, replace it with whatever call returns the current value of subscription_connection_enabled.
- Update all other tests in this file that currently do:
module_import_sat.cli.Settings.set(
{'name': 'subscription_connection_enabled', 'value': 'No'}
)
module_import_sat.cli.ContentImport.library(...)to use the context manager instead:
with subscription_connection_disabled(module_import_sat):
module_import_sat.cli.ContentImport.library(...)This includes at least the tests mentioned in your comment:
test_positive_export_import_default_org_viewtest_positive_export_import_filtered_cvvtest_positive_export_import_redhat_cv
These changes ensure subscription_connection_enabled is always restored to its original value, avoiding leakage across tests and order-dependence.
Problem Statement
Currently we the the vast majority of the ISS export+import tests runs against the same Satellite instance for both - export and import (just into another organization), which does not quite follow the user case and may miss some important issues.
Solution
After merge of #21600 we should be ready to migrate the tests to use a separate Satellite instance for imports. In this PR I'm migrating 10 of them where it makes sense the most. Others may follow.
PRT test Cases example
Summary by Sourcery
Migrate several content export/import CLI tests to use a dedicated import Satellite instance instead of the primary target Satellite.
Tests: