-
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.
feat(groups): command lists existing groups
optionally filter by a term matching group ID or label support subcommands with additional args
- Loading branch information
1 parent
7f7b482
commit e6525b3
Showing
5 changed files
with
163 additions
and
17 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,27 @@ | ||
from littlepay.api.client import Client | ||
from littlepay.commands import RESULT_SUCCESS | ||
from littlepay.config import Config | ||
|
||
|
||
def groups(group_term: str = None, group_command: str = None, **kwargs) -> int: | ||
config = Config() | ||
client = Client.from_active_config(config) | ||
client.oauth.ensure_active_token(client.token) | ||
config.active_token = client.token | ||
|
||
groups = client.get_concession_groups() | ||
|
||
if group_term is not None: | ||
term = group_term.lower() | ||
groups = filter( | ||
lambda g: term in g.id.lower() or term in g.label.lower(), | ||
groups, | ||
) | ||
|
||
groups = list(groups) | ||
print(f"👥 Matching groups ({len(groups)})") | ||
|
||
for group in groups: | ||
print(group) | ||
|
||
return RESULT_SUCCESS |
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
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,74 @@ | ||
from argparse import Namespace | ||
import pytest | ||
|
||
from littlepay.api.groups import GroupResponse | ||
from littlepay.commands import RESULT_SUCCESS | ||
from littlepay.commands.groups import groups | ||
|
||
GROUP_RESPONSES = [ | ||
GroupResponse("id0", "zero", "participant123"), | ||
GroupResponse("id1", "one", "participant123"), | ||
GroupResponse("id2", "two", "participant123"), | ||
] | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_config(mocker): | ||
mocker.patch("littlepay.commands.groups.config") | ||
|
||
|
||
@pytest.fixture | ||
def mock_client(mocker): | ||
client = mocker.Mock() | ||
mocker.patch("littlepay.commands.groups.Client.from_active_config", return_value=client) | ||
return client | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_get_groups(mock_client): | ||
mock_client.get_concession_groups.return_value = GROUP_RESPONSES | ||
|
||
|
||
def test_groups_default(mock_client, capfd): | ||
res = groups() | ||
capture = capfd.readouterr() | ||
|
||
assert res == RESULT_SUCCESS | ||
|
||
mock_client.oauth.ensure_active_token.assert_called_once() | ||
|
||
assert "Matching groups (3)" in capture.out | ||
for response in GROUP_RESPONSES: | ||
assert str(response) in capture.out | ||
|
||
|
||
@pytest.mark.parametrize("group_response", GROUP_RESPONSES) | ||
def test_groups_group_term__group_id(group_response, capfd): | ||
args = Namespace(group_term=group_response.id) | ||
res = groups(args) | ||
capture = capfd.readouterr() | ||
|
||
assert res == RESULT_SUCCESS | ||
|
||
assert "Matching groups (1)" in capture.out | ||
for response in GROUP_RESPONSES: | ||
if response == group_response: | ||
assert str(response) in capture.out | ||
else: | ||
assert str(response) not in capture.out | ||
|
||
|
||
@pytest.mark.parametrize("group_response", GROUP_RESPONSES) | ||
def test_groups_group_term__group_label(group_response, capfd): | ||
args = Namespace(group_term=group_response.label) | ||
res = groups(args) | ||
capture = capfd.readouterr() | ||
|
||
assert res == RESULT_SUCCESS | ||
|
||
assert "Matching groups (1)" in capture.out | ||
for response in GROUP_RESPONSES: | ||
if response == group_response: | ||
assert str(response) in capture.out | ||
else: | ||
assert str(response) not in capture.out |
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
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