Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: allow group commands to iterate on the groups multiple times #54

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion littlepay/commands/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def groups(args: Namespace = None) -> int:
groups,
)

groups = list(groups)

if command == "link":
for group in groups:
return_code += link_product(client, group.id, args.product_id)
Expand All @@ -47,7 +49,6 @@ def groups(args: Namespace = None) -> int:
for group in groups:
return_code += migrate_group(client, group.id, getattr(args, "force", False))

groups = list(groups)
if csv_output and command != "products":
print(GroupResponse.csv_header())
elif csv_output and command == "products":
Expand Down
28 changes: 15 additions & 13 deletions tests/commands/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def _input(return_value):

@pytest.fixture(autouse=True)
def mock_get_groups(mock_client):
mock_client.get_concession_groups.return_value = GROUP_RESPONSES
# return a generator comprehension to mimic how the real function returns a Generator
mock_client.get_concession_groups.return_value = (r for r in GROUP_RESPONSES)


def test_groups_default(mock_client, capfd):
Expand Down Expand Up @@ -116,7 +117,7 @@ def test_groups_group_command__create(mock_client, capfd):
assert res == RESULT_SUCCESS
assert "Creating group" in capture.out
assert "Created" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__create_HTTPError(mock_client, capfd):
Expand All @@ -131,7 +132,7 @@ def test_groups_group_command__create_HTTPError(mock_client, capfd):
assert res == RESULT_FAILURE
assert "Creating group" in capture.out
assert "Error" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__link(mock_client, capfd):
Expand Down Expand Up @@ -213,7 +214,7 @@ def test_groups_group_command__remove_confirm(capfd, mock_input, sample_input):
assert res == RESULT_SUCCESS
assert "Removing group" in capture.out
assert "Removed" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__remove_confirm_error(capfd, mock_input):
Expand All @@ -227,7 +228,7 @@ def test_groups_group_command__remove_confirm_error(capfd, mock_input):
assert res == RESULT_SUCCESS
assert "Removing group" in capture.out
assert "Canceled" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


@pytest.mark.parametrize("sample_input", ["n", "N", "no", "No", "NO"])
Expand All @@ -241,7 +242,7 @@ def test_groups_group_command__remove_decline(capfd, mock_input, sample_input):
assert res == RESULT_SUCCESS
assert "Removing group" in capture.out
assert "Canceled" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__remove_force(capfd, mock_input):
Expand All @@ -255,7 +256,7 @@ def test_groups_group_command__remove_force(capfd, mock_input):
assert _input.called is False
assert "Removing group" in capture.out
assert "Removed" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__remove_HTTPError(capfd, mock_client, mock_input):
Expand All @@ -269,7 +270,7 @@ def test_groups_group_command__remove_HTTPError(capfd, mock_client, mock_input):
assert res == RESULT_FAILURE
assert "Removing group" in capture.out
assert "Error" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__unlink(mock_client, capfd):
Expand All @@ -283,6 +284,7 @@ def test_groups_group_command__unlink(mock_client, capfd):
assert res == RESULT_SUCCESS
assert "Unlinking group <-> product" in capture.out
assert "Unlinked" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__unlink_HTTPError(mock_client, capfd):
Expand Down Expand Up @@ -312,7 +314,7 @@ def test_groups_group_command__migrate_confirm(mock_client, capfd, mock_input, s
assert res == RESULT_SUCCESS
assert "Migrating group" in capture.out
assert "Migrated" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__migrate_confirm_error(capfd, mock_input):
Expand All @@ -326,7 +328,7 @@ def test_groups_group_command__migrate_confirm_error(capfd, mock_input):
assert res == RESULT_SUCCESS
assert "Migrating group" in capture.out
assert "Canceled" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


@pytest.mark.parametrize("sample_input", ["n", "N", "no", "No", "NO"])
Expand All @@ -340,7 +342,7 @@ def test_groups_group_command__migrate_decline(capfd, mock_input, sample_input):
assert res == RESULT_SUCCESS
assert "Migrating group" in capture.out
assert "Canceled" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__migrate_force(mock_client, capfd, mock_input):
Expand All @@ -357,7 +359,7 @@ def test_groups_group_command__migrate_force(mock_client, capfd, mock_input):
assert _input.called is False
assert "Migrating group" in capture.out
assert "Migrated" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out


def test_groups_group_command__migrate_HTTPError(mock_client, capfd, mock_input):
Expand All @@ -371,4 +373,4 @@ def test_groups_group_command__migrate_HTTPError(mock_client, capfd, mock_input)
assert res == RESULT_FAILURE
assert "Migrating group" in capture.out
assert "Error" in capture.out
assert "Matching groups" in capture.out
assert "Matching groups (3)" in capture.out
Loading