Skip to content

Commit 7602b22

Browse files
committed
feat: raise exceptions on invalid 'create' and 'replace' commands
1 parent a3e04fb commit 7602b22

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

scim2_cli/create.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def create_payload(client, payload, indent):
3131

3232

3333
def create_factory(model):
34+
if not model:
35+
raise ClickException("Invalid model")
36+
3437
exclude = unacceptable_fields(Context.RESOURCE_CREATION_REQUEST, model)
3538

3639
@click.command(

scim2_cli/replace.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def replace_payload(client, payload, indent):
3131

3232

3333
def replace_factory(model):
34+
if not model:
35+
raise ClickException("Invalid model")
36+
3437
exclude = unacceptable_fields(Context.RESOURCE_REPLACEMENT_REQUEST, model)
3538
exclude.remove("id")
3639

tests/test_create.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
from scim2_cli import cli
44

55

6+
def test_no_command(runner, httpserver):
7+
"""Test that no command displays the help."""
8+
result = runner.invoke(
9+
cli,
10+
["--url", httpserver.url_for("/"), "create"],
11+
catch_exceptions=False,
12+
)
13+
assert result.exit_code == 1, result.stdout
14+
assert "create user --help" in result.stdout
15+
16+
17+
def test_invalid_command(runner, httpserver):
18+
"""Test invalid command."""
19+
result = runner.invoke(
20+
cli,
21+
["--url", httpserver.url_for("/"), "create", "invalid"],
22+
catch_exceptions=False,
23+
)
24+
assert result.exit_code == 1, result.stdout
25+
assert "Error: Invalid model" in result.stdout
26+
27+
628
def test_no_command_stdin(runner, httpserver, simple_user_payload):
729
"""Test that JSON stdin is passed in the POST request."""
830
response_payload = simple_user_payload("new-user")

tests/test_replace.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
from scim2_cli import cli
44

55

6+
def test_no_command(runner, httpserver):
7+
"""Test that no command displays the help."""
8+
result = runner.invoke(
9+
cli,
10+
["--url", httpserver.url_for("/"), "replace"],
11+
catch_exceptions=False,
12+
)
13+
assert result.exit_code == 1, result.stdout
14+
assert "replace user --help" in result.stdout
15+
16+
17+
def test_invalid_command(runner, httpserver):
18+
"""Test invalid command."""
19+
result = runner.invoke(
20+
cli,
21+
["--url", httpserver.url_for("/"), "replace", "invalid"],
22+
catch_exceptions=False,
23+
)
24+
assert result.exit_code == 1, result.stdout
25+
assert "Error: Invalid model" in result.stdout
26+
27+
628
def test_no_command_stdin(runner, httpserver, simple_user_payload):
729
"""Test that JSON stdin is passed in the PUT request."""
830
response_payload = simple_user_payload("old-user")

0 commit comments

Comments
 (0)