Skip to content

Commit

Permalink
apply make format
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBarberini committed Nov 13, 2024
1 parent 4be60a6 commit fc4de13
Showing 1 changed file with 62 additions and 18 deletions.
80 changes: 62 additions & 18 deletions tests/test_routes/test_environment_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,27 @@ def test_create_env():
}
mock_create_env.assert_called_once_with(Env(latitude=0, longitude=0))


def test_create_env_invalid_input():
response = client.post("/environments/", json={"latitude": "foo", "longitude": "bar"})
response = client.post(
"/environments/", json={"latitude": "foo", "longitude": "bar"}
)
assert response.status_code == 422


def test_create_env_server_error():
with patch.object(
EnvController, "create_env", side_effect=Exception("error")
) as mock_create_env:
):
with pytest.raises(Exception):
response = client.post(
"/environments/", json={"latitude": 0, "longitude": 0}
)
assert response.status_code == 500
assert response.json() == {"detail": "Failed to create environment: error"}
assert response.json() == {
"detail": "Failed to create environment: error"
}


def test_read_env(stub_env):
with patch.object(
Expand All @@ -65,23 +72,32 @@ def test_read_env(stub_env):
assert response.json() == expected_content
mock_read_env.assert_called_once_with("123")


def test_read_env_not_found():
with patch.object(
EnvController, "get_env_by_id", side_effect=HTTPException(status_code=404, detail="Environment not found")
EnvController,
"get_env_by_id",
side_effect=HTTPException(
status_code=404, detail="Environment not found"
),
) as mock_read_env:
response = client.get("/environments/123")
assert response.status_code == 404
assert response.json() == {"detail": "Environment not found"}
mock_read_env.assert_called_once_with("123")


def test_read_env_server_error():
with patch.object(
EnvController, "get_env_by_id", side_effect=Exception("error")
) as mock_read_env:
):
with pytest.raises(Exception):
response = client.get("/environments/123")
assert response.status_code == 500
assert response.json() == {"detail": "Failed to read environment: error"}
assert response.json() == {
"detail": "Failed to read environment: error"
}


def test_update_env():
with patch.object(
Expand All @@ -101,15 +117,21 @@ def test_update_env():
"123", Env(latitude=1, longitude=1)
)


def test_update_env_invalid_input():
response = client.put("/environments/123", json={"latitude": "foo", "longitude": "bar"})
response = client.put(
"/environments/123", json={"latitude": "foo", "longitude": "bar"}
)
assert response.status_code == 422


def test_update_env_not_found():
with patch.object(
EnvController,
"update_env_by_id",
side_effect=HTTPException(status_code=404, detail="Environment not found"),
side_effect=HTTPException(
status_code=404, detail="Environment not found"
),
) as mock_update_env:
response = client.put(
"/environments/123", json={"longitude": 1, "latitude": 1}
Expand All @@ -120,18 +142,22 @@ def test_update_env_not_found():
"123", Env(latitude=1, longitude=1)
)


def test_update_env_server_error():
with patch.object(
EnvController,
"update_env_by_id",
side_effect=Exception("error"),
) as mock_update_env:
):
with pytest.raises(Exception):
response = client.put(
"/environments/123", json={"longitude": 1, "latitude": 1}
)
assert response.status_code == 500
assert response.json() == {"detail": "Failed to update environment: error"}
assert response.json() == {
"detail": "Failed to update environment: error"
}


def test_delete_env():
with patch.object(
Expand All @@ -147,6 +173,7 @@ def test_delete_env():
}
mock_delete_env.assert_called_once_with("123")


def test_delete_env_not_found():
with patch.object(
EnvController,
Expand All @@ -161,16 +188,20 @@ def test_delete_env_not_found():
}
mock_delete_env.assert_called_once_with("123")


def test_delete_env_server_error():
with patch.object(
EnvController,
"delete_env_by_id",
side_effect=Exception("error"),
) as mock_delete_env:
):
with pytest.raises(Exception):
response = client.delete("/environments/123")
assert response.status_code == 500
assert response.json() == {"detail": "Failed to delete environment: error"}
assert response.json() == {
"detail": "Failed to delete environment: error"
}


def test_simulate_env(stub_env_summary):
with patch.object(
Expand All @@ -189,27 +220,34 @@ def test_simulate_env(stub_env_summary):
assert response.json() == expected_content
mock_simulate_env.assert_called_once_with("123")


def test_simulate_env_not_found():
with patch.object(
EnvController,
"simulate_env",
side_effect=HTTPException(status_code=404, detail="Environment not found"),
side_effect=HTTPException(
status_code=404, detail="Environment not found"
),
) as mock_simulate_env:
response = client.get("/environments/123/summary")
assert response.status_code == 404
assert response.json() == {"detail": "Environment not found"}
mock_simulate_env.assert_called_once_with("123")


def test_simulate_env_server_error():
with patch.object(
EnvController,
"simulate_env",
side_effect=Exception("error"),
) as mock_simulate_env:
):
with pytest.raises(Exception):
response = client.get("/environments/123/summary")
assert response.status_code == 500
assert response.json() == {"detail": "Failed to simulate environment: error"}
assert response.json() == {
"detail": "Failed to simulate environment: error"
}


def test_read_rocketpy_env():
with patch.object(
Expand All @@ -221,24 +259,30 @@ def test_read_rocketpy_env():
assert response.headers["content-type"] == "application/octet-stream"
mock_read_rocketpy_env.assert_called_once_with("123")


def test_read_rocketpy_env_not_found():
with patch.object(
EnvController,
"get_rocketpy_env_binary",
side_effect=HTTPException(status_code=404, detail="Environment not found"),
side_effect=HTTPException(
status_code=404, detail="Environment not found"
),
) as mock_read_rocketpy_env:
response = client.get("/environments/123/rocketpy")
assert response.status_code == 404
assert response.json() == {"detail": "Environment not found"}
mock_read_rocketpy_env.assert_called_once_with("123")


def test_read_rocketpy_env_server_error():
with patch.object(
EnvController,
"get_rocketpy_env_binary",
side_effect=Exception("error"),
) as mock_read_rocketpy_env:
):
with pytest.raises(Exception):
response = client.get("/environments/123/rocketpy")
assert response.status_code == 500
assert response.json() == {"detail": "Failed to read rocketpy environment: error"}
assert response.json() == {
"detail": "Failed to read rocketpy environment: error"
}

0 comments on commit fc4de13

Please sign in to comment.