|
| 1 | +import json |
| 2 | + |
1 | 3 | from scim_cli import cli |
2 | 4 |
|
3 | 5 |
|
4 | | -def test_hello_world(runner): |
5 | | - result = runner.invoke(cli) |
| 6 | +def test_help(runner): |
| 7 | + result = runner.invoke(cli, ["--help"]) |
| 8 | + assert result.exit_code == 0 |
| 9 | + assert "SCIM application development CLI.\n" in result.output |
| 10 | + |
| 11 | + |
| 12 | +def test_get_stdin(runner, echoserver): |
| 13 | + """Test that JSON stdin is passed in the GET request.""" |
| 14 | + payload = {"foo": "bar"} |
| 15 | + result = runner.invoke( |
| 16 | + cli, |
| 17 | + [echoserver.url_for("/"), "get"], |
| 18 | + input=json.dumps(payload), |
| 19 | + catch_exceptions=False, |
| 20 | + ) |
| 21 | + assert result.exit_code == 0 |
| 22 | + expected_payload = {"method": "GET", "args": payload} |
| 23 | + json_output = json.loads(result.output) |
| 24 | + assert expected_payload == json_output |
| 25 | + |
| 26 | + |
| 27 | +def test_post_stdin(runner, echoserver): |
| 28 | + """Test that JSON stdin is passed in the POST request.""" |
| 29 | + |
| 30 | + payload = {"foo": "bar"} |
| 31 | + result = runner.invoke( |
| 32 | + cli, |
| 33 | + [echoserver.url_for("/"), "post"], |
| 34 | + input=json.dumps(payload), |
| 35 | + catch_exceptions=False, |
| 36 | + ) |
| 37 | + assert result.exit_code == 0 |
| 38 | + expected_payload = {"method": "POST", "payload": payload} |
| 39 | + json_output = json.loads(result.output) |
| 40 | + assert expected_payload == json_output |
| 41 | + |
| 42 | + |
| 43 | +def test_put_stdin(runner, echoserver): |
| 44 | + """Test that JSON stdin is passed in the PUT request.""" |
| 45 | + |
| 46 | + payload = {"foo": "bar"} |
| 47 | + result = runner.invoke( |
| 48 | + cli, |
| 49 | + [echoserver.url_for("/"), "put"], |
| 50 | + input=json.dumps(payload), |
| 51 | + catch_exceptions=False, |
| 52 | + ) |
| 53 | + assert result.exit_code == 0 |
| 54 | + expected_payload = {"method": "PUT", "payload": payload} |
| 55 | + json_output = json.loads(result.output) |
| 56 | + assert expected_payload == json_output |
| 57 | + |
| 58 | + |
| 59 | +def test_patch_stdin(runner, echoserver): |
| 60 | + """Test that JSON stdin is passed in the POST request.""" |
| 61 | + |
| 62 | + payload = {"foo": "bar"} |
| 63 | + result = runner.invoke( |
| 64 | + cli, |
| 65 | + [echoserver.url_for("/"), "patch"], |
| 66 | + input=json.dumps(payload), |
| 67 | + catch_exceptions=False, |
| 68 | + ) |
| 69 | + assert result.exit_code == 0 |
| 70 | + expected_payload = {"method": "PATCH", "payload": payload} |
| 71 | + json_output = json.loads(result.output) |
| 72 | + assert expected_payload == json_output |
| 73 | + |
| 74 | + |
| 75 | +def test_delete_stdin(runner, echoserver): |
| 76 | + """Test that JSON stdin is passed in the DELETE request.""" |
| 77 | + payload = {"foo": "bar"} |
| 78 | + result = runner.invoke( |
| 79 | + cli, |
| 80 | + [echoserver.url_for("/"), "delete"], |
| 81 | + input=json.dumps(payload), |
| 82 | + catch_exceptions=False, |
| 83 | + ) |
6 | 84 | assert result.exit_code == 0 |
7 | | - assert result.output == "Hello world!\n" |
| 85 | + expected_payload = {"method": "DELETE", "payload": payload} |
| 86 | + json_output = json.loads(result.output) |
| 87 | + assert expected_payload == json_output |
0 commit comments