Skip to content

Commit d6e6423

Browse files
committed
Add stubbed CLI test case, modify delete command and settings file
1 parent b96a87c commit d6e6423

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

manifester/commands.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ def cli():
1818

1919
@cli.command()
2020
@click.option(
21-
"--manifest_category",
21+
"--manifest-category",
2222
type=str,
2323
help="Category of manifest (golden_ticket or robottelo_automation by default)",
2424
)
25-
@click.option("--allocation_name", type=str, help="Name of upstream subscription allocation")
26-
def get_manifest(manifest_category, allocation_name):
25+
@click.option("--allocation-name", type=str, help="Name of upstream subscription allocation")
26+
@click.option("--requester", type=str, default=None)
27+
def get_manifest(manifest_category, allocation_name, requester):
2728
"""Return a subscription manifester based on the settings for the provided manifest_category."""
28-
manifester = Manifester(manifest_category, allocation_name, cli=True)
29+
manifester = Manifester(manifest_category, allocation_name, requester=requester)
2930
manifester.create_subscription_allocation()
3031
for sub in manifester.subscription_data:
3132
manifester.process_subscription_pools(
3233
subscription_pools=manifester.subscription_pools,
3334
subscription_data=sub,
3435
)
35-
manifester.trigger_manifest_export()
36+
return manifester.trigger_manifest_export()
3637

3738

3839
@cli.command()
@@ -54,14 +55,14 @@ def delete(allocations, all_, remove_manifest_file):
5455
"""Delete subscription allocations in inventory and optionally delete local manifest files."""
5556
inv = helpers.load_inventory_file(Path(settings.inventory_path))
5657
for num, allocation in enumerate(inv):
57-
if remove_manifest_file:
58-
Path(
59-
f"{os.environ['MANIFESTER_DIRECTORY']}/manifests/{allocation.get('name')}_manifest.zip"
60-
).unlink()
6158
if str(num) in allocations or allocation.get("name") in allocations or all_:
6259
Manifester(minimal_init=True).delete_subscription_allocation(
6360
uuid=allocation.get("uuid")
6461
)
62+
if remove_manifest_file:
63+
Path(
64+
f"{os.environ['MANIFESTER_DIRECTORY']}/manifests/{allocation.get('name')}_manifest.zip"
65+
).unlink()
6566

6667

6768
@cli.command()

tests/test_manifester.py

+24
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,27 @@ def test_update_inventory():
305305
load_inventory_file(Path(MANIFEST_DATA["inventory_path"]))
306306
== SUB_ALLOCATIONS_RESPONSE["body"]
307307
)
308+
309+
310+
# CLI test case is currently manual
311+
312+
313+
def test_cli_end_to_end():
314+
"""Test that manifester's get-manifest cli command returns a manifest.
315+
316+
Steps to test:
317+
1. Generate a new manifest with 'manifester get-manifest --manifest-category golden_ticket`
318+
2. Generate three additional manifests using the same command as step 1
319+
3. Verify that the four manifest file are present in the `./manifests/` directory
320+
4. Verify that the manifests contain the expected subscriptions with `rct cat-manifest
321+
<manifest file>`
322+
5. Verify that all four manifests are present in the local inventory with `manifester inventory`
323+
6. Verify that a subscription allocation can be deleted by inventory index with `manifester
324+
delete 0`
325+
7. Verify that a subscription allocation can be deleted by name with `manifester delete
326+
<allocation name>`
327+
8. Verify that all remaining allocations can be deleted and that the corresponding manifest
328+
files can be deleted as well with `manifester delete --all --remove-manifest-file`
329+
9. Run `manifester inventory --sync` and verify that none of the allocations created above
330+
are present in the inventory
331+
"""

0 commit comments

Comments
 (0)