Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Apr 2, 2024
1 parent f975f6d commit 188f0c3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
32 changes: 16 additions & 16 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
"python.languageServer": "Pylance",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"esbonio.server.enabled": true,
"esbonio.sphinx.confDir": "",
}
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
"python.languageServer": "Pylance",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"esbonio.server.enabled": true,
"esbonio.sphinx.confDir": ""
}
51 changes: 51 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,54 @@ def test_config_passed_down_to_command_children(
"params": {"time": 5},
}
}



@pytest.mark.handler
@patch("blueapi.service.handler.Handler")
@patch("requests.request")
def test_get_env(
mock_requests: Mock,
mock_handler: Mock,
handler: Handler,
client: TestClient,
runner: CliRunner,
):
with patch("uvicorn.run", side_effect=None):
result = runner.invoke(main, [ "serve"])

assert result.exit_code == 0

mock_requests.return_value = Mock()

runner.invoke( main, ["controller", "env"])

assert mock_requests.call_args[0] == (
"GET",
"http://localhost:8000/environment",
)


@pytest.mark.handler
@patch("blueapi.service.handler.Handler")
@patch("requests.request")
def test_reset_env(
mock_requests: Mock,
mock_handler: Mock,
handler: Handler,
client: TestClient,
runner: CliRunner,
):
with patch("uvicorn.run", side_effect=None):
result = runner.invoke(main, [ "serve"])

assert result.exit_code == 0

mock_requests.return_value = Mock()

runner.invoke( main, ["controller", "env" , "-r"])

assert mock_requests.call_args[0] == (
"DELETE",
"http://localhost:8000/environment",
)

0 comments on commit 188f0c3

Please sign in to comment.