Skip to content

Commit

Permalink
test(main): remove content assertion in test_iac_template
Browse files Browse the repository at this point in the history
  • Loading branch information
maralzar authored Nov 12, 2024
1 parent 1b3b925 commit 6579c12
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions app/tests/test_iac_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,35 @@
@pytest.fixture
def sample_iac_template_input():
return IaCTemplateGeneration(
service="terraform",
service="terraform",
CI_integration=True,
base_config="ec2"
base_config="ec2"
)

@patch("app.main.gpt_service")
@patch("app.main.edit_directory_generator")
@patch("app.main.execute_pythonfile")
def test_template(mock_execute_pythonfile, mock_edit_directory_generator, mock_gpt_service, sample_iac_template_input):
"""
Test the /IaC-template/ endpoint with valid input data to ensure it returns a 200 status code.
"""
mock_gpt_service.return_value = "Generated Python Code"

response = client.post("/IaC-template/", json=sample_iac_template_input.model_dump())

assert response.status_code == 200
assert response.json()["output"] == "output"

mock_gpt_service.assert_called_once()
mock_edit_directory_generator.assert_called_once_with("terraform_generator", "Generated Python Code")
mock_execute_pythonfile.assert_called_once_with("MyTerraform", "terraform_generator")

@patch("app.main.gpt_service")
@patch("app.main.edit_directory_generator")
@patch("app.main.execute_pythonfile")
def test_template_invalid(mock_execute_pythonfile, mock_edit_directory_generator, mock_gpt_service):
"""
Test the /IaC-template/ endpoint with an invalid 'base_config' to ensure proper validation.
Test the /IaC-template/ endpoint with an invalid 'base_config' value to ensure it returns a 422 status code.
"""
invalid_input = {
"CI_integration": True,
"base_config": "k8s",
"base_config": "k8s", # Unsupported base_config
"service": "terraform"
}
response = client.post("/IaC-template/", json=invalid_input)
assert response.status_code == 422, f"Expected status code 422, got {response.status_code}"
# assert "detail" in response.json(), "Response JSON does not contain 'detail'"
# errors = response.json()["detail"]
# expected_error_loc = ["body", "base_config"]
# expected_error_msg = "Value error, Base config must be one of ['ec2','s3','rds','docker_image','docker_container']."
# assert any(
# error["loc"] == expected_error_loc and expected_error_msg in error["msg"]
# for error in errors
# ), f"Expected error message '{expected_error_msg}' at location {expected_error_loc}, but not found."
mock_gpt_service.assert_not_called()
mock_edit_directory_generator.assert_not_called()
mock_execute_pythonfile.assert_not_called()
assert response.status_code == 422

0 comments on commit 6579c12

Please sign in to comment.