1- from unittest .mock import patch
1+ from unittest .mock import MagicMock , patch , mock_open
22
33
4- class TestTerraformTemplates :
4+ class TestIaCTemplates :
55 def setup_method (self ):
6- self .mock_execute_pythonfile = patch ('app.main.execute_pythonfile' ).start ()
6+ mock_client_instance = MagicMock ()
7+ mock_client_instance .chat .completions .create .return_value = MagicMock (
8+ choices = [MagicMock (message = MagicMock (content = 'Mocked OpenAI Response' ))]
9+ )
10+
11+ self .mock_execute_python_file = patch ('app.main.execute_pythonfile' ).start ()
712 self .mock_edit_directory_generator = patch ('app.main.edit_directory_generator' ).start ()
8- self .mock_gpt_service = patch ('app.main.gpt_service' ).start ()
9- self .mock_gpt_service .return_value = 'Generated Python Code'
13+ self .mock_gpt_service = patch ('app.main.gpt_service' , return_value = 'Mocked GPT Response' ).start ()
14+ self .mock_openai = patch ('app.gpt_services.OpenAI' , return_value = mock_client_instance ).start ()
15+ self .mock_builtin_open = patch ('builtins.open' , mock_open ()).start ()
1016
1117 self .iac_template_docker_url = '/IaC-template/docker'
1218 self .iac_template_ec2_url = '/IaC-template/aws/ec2'
@@ -21,7 +27,6 @@ def teardown_method(self):
2127
2228 def test_iac_template_docker (self , client , iac_template_docker_sample_input ):
2329 response = client .post (self .iac_template_docker_url , json = iac_template_docker_sample_input )
24- print (response .json ())
2530 assert response .status_code == 200
2631
2732 def test_iac_template_ec2 (self , client , iac_template_ec2_sample_input ):
0 commit comments