-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d8c3ed
commit e7d4f04
Showing
11 changed files
with
644 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from click.testing import CliRunner | ||
import json | ||
from click.core import BaseCommand | ||
from .utils import assert_valid_output_file | ||
|
||
|
||
def _test_cleanup_entity(test_data: list[dict], cli: BaseCommand): | ||
runner = CliRunner() | ||
|
||
# we might receive a list of policies or a single policy | ||
if isinstance(test_data, list): | ||
first_entity = test_data[0] | ||
else: | ||
first_entity = test_data | ||
|
||
# check that the test data has id, createdDateTime and modifiedDateTime | ||
assert "id" in first_entity | ||
assert "createdDateTime" in first_entity | ||
assert "modifiedDateTime" in first_entity | ||
|
||
with runner.isolated_filesystem(): | ||
# write the test data to a file | ||
test_data_file = "test_data.json" | ||
with open(test_data_file, "w") as f: | ||
# convert the test data to a string | ||
f.write(json.dumps(test_data, indent=4)) | ||
|
||
assert_valid_output_file(test_data_file) | ||
|
||
result = runner.invoke( | ||
cli, | ||
[ | ||
"--input_file", | ||
test_data_file, | ||
"--output_file", | ||
test_data_file, | ||
], | ||
) | ||
assert result is not None | ||
assert result.exit_code == 0 | ||
assert_valid_output_file(test_data_file) | ||
|
||
# check if the file was cleaned up, by checking if the id, createdDateTime and modifiedDateTime are gone | ||
with open(test_data_file) as f: | ||
data = json.load(f) | ||
|
||
# check if the expected node is present | ||
assert "id" not in data[0] | ||
assert "createdDateTime" not in data[0] | ||
assert "modifiedDateTime" not in data[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from src.ca_pwt.commands import ( | ||
cleanup_groups_cmd, | ||
) | ||
from .utils import VALID_GROUPS | ||
from .cleanup_entity_cmd_test_utils import _test_cleanup_entity | ||
|
||
|
||
def test_cleanup_groups(): | ||
"""Tests if the cleanup-groups command works as expected""" | ||
_test_cleanup_entity(VALID_GROUPS, cleanup_groups_cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from src.ca_pwt.commands import ( | ||
cleanup_policies_cmd, | ||
) | ||
from .utils import VALID_POLICIES | ||
from .cleanup_entity_cmd_test_utils import _test_cleanup_entity | ||
|
||
|
||
def test_cleanup_policies(): | ||
"""Tests if the cleanup-policies command works as expected""" | ||
_test_cleanup_entity(VALID_POLICIES, cleanup_policies_cmd) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.