Skip to content

Commit ab3a1f0

Browse files
committed
Fix click types to call super().convert
1 parent 5c4053e commit ab3a1f0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

isic_cli/cli/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class SearchString(click.ParamType):
1313
name = "search_string"
1414

1515
def convert(self, value, param, ctx):
16+
value = super().convert(value, param, ctx)
17+
1618
r = ctx.obj.session.get("images/search/", params={"query": value, "limit": 1})
1719
if r.status_code == 400 and "detail" in r.json() and "query" in r.json()["detail"]:
1820
self.fail('Invalid search query string "%s"' % value, param, ctx)
@@ -23,6 +25,8 @@ class CommaSeparatedIdentifiers(click.ParamType):
2325
name = "comma_separated_identifiers"
2426

2527
def convert(self, value, param, ctx):
28+
value = super().convert(value, param, ctx)
29+
2630
if value != "" and not re.match(r"^(\d+)(,\d+)*$", value):
2731
self.fail('Improperly formatted value "%s".' % value, param, ctx)
2832
return value
@@ -36,6 +40,8 @@ def __init__(self, locked_okay: Optional[bool] = False) -> None:
3640
self.locked_okay = locked_okay
3741

3842
def convert(self, value: str, param, ctx) -> str:
43+
value = super().convert(value, param, ctx)
44+
3945
try:
4046
collection = get_collection(ctx.obj.session, value)
4147
except HTTPError as e:
@@ -57,6 +63,8 @@ class CohortId(IntParamType):
5763
name = "cohort_id"
5864

5965
def convert(self, value: str, param, ctx) -> str:
66+
value = super().convert(value, param, ctx)
67+
6068
try:
6169
get_cohort(ctx.obj.session, value)
6270
except HTTPError as e:

tests/test_cli_collection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ def cmd(foo):
4343
assert "locked for modification" in result.output, result.output
4444

4545

46+
def test_collection_id_type_must_be_integer(mocker):
47+
@click.command()
48+
@click.argument("foo", type=CollectionId())
49+
def cmd(foo):
50+
pass
51+
52+
# magicmock is used to mock out ctx.obj
53+
result = CliRunner().invoke(cmd, ["some-non-numeric-string"], obj=mocker.MagicMock())
54+
assert result.exit_code == 2, result.exit_code
55+
assert "is not a valid" in result.output, result.output
56+
57+
4658
def test_collection_id_type_access(mocker):
4759
@click.command()
4860
@click.argument("foo", type=CollectionId())

0 commit comments

Comments
 (0)