Skip to content

Commit 1b3b925

Browse files
authored
test(main) remove content asset in test_iac_install
1 parent c1008ba commit 1b3b925

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

app/tests/test_iac_install.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from app.models import IaCInstallationInput
66

77
client = TestClient(app)
8-
mocked_gpt_response = "Mocked shell script for installing terraform on Ubuntu."
98

109
@pytest.fixture
1110
def valid_installation_data():
@@ -15,37 +14,29 @@ def valid_installation_data():
1514
min_tokens=100,
1615
max_tokens=500
1716
)
18-
@patch('app.main.gpt_service', return_value=mocked_gpt_response)
17+
18+
@patch('app.main.gpt_service')
1919
def test_install(mock_gpt_service, valid_installation_data):
2020
"""
21-
Test the /IaC-install/ endpoint with valid input data to ensure correct output.
21+
Test the /IaC-install/ endpoint with valid input data to ensure it returns a 200 status code.
2222
"""
23+
mock_gpt_service.return_value = "Mocked shell script for installing terraform on Ubuntu."
24+
2325
response = client.post("/IaC-install/", json=valid_installation_data.model_dump())
2426
assert response.status_code == 200
25-
assert response.json() == {"output": mocked_gpt_response}
27+
2628

2729
@patch('app.main.gpt_service')
2830
def test_install_invalid(mock_gpt_service):
2931
"""
30-
Test the /IaC-install/ endpoint with an invalid 'os' value to ensure proper validation.
32+
Test the /IaC-install/ endpoint with an invalid 'os' value to ensure it returns a 422 status code.
3133
"""
3234
invalid_input = {
33-
"os": "Kali",
34-
"service": "terraform"
35+
"os": "Kali", # Unsupported OS
36+
"service": "terraform",
37+
"min_tokens": 100,
38+
"max_tokens": 500
3539
}
3640

3741
response = client.post("/IaC-install/", json=invalid_input)
38-
39-
assert response.status_code == 422, f"Expected status code 422, got {response.status_code}"
40-
assert "detail" in response.json(), "Response JSON does not contain 'detail'"
41-
errors = response.json()["detail"]
42-
43-
expected_error_loc = ["body", "os"]
44-
expected_error_msg = "OS must be one of ['ubuntu', 'centos', 'debian']."
45-
46-
assert any(
47-
error["loc"] == expected_error_loc and error_msg in error["msg"]
48-
for error in errors
49-
for error_msg in [expected_error_msg]
50-
), f"Expected error message '{expected_error_msg}' at location {expected_error_loc}, but not found."
51-
mock_gpt_service.assert_not_called()
42+
assert response.status_code == 422

0 commit comments

Comments
 (0)