3
3
import pytest
4
4
from fastapi .testclient import TestClient
5
5
from fastapi import HTTPException , status
6
- from lib .models .environment import Env
7
- from lib .controllers .environment import EnvController
6
+ from lib .models .environment import EnvironmentModel
7
+ from lib .controllers .environment import EnvironmentController
8
8
from lib .views .environment import (
9
- EnvCreated ,
10
- EnvUpdated ,
11
- EnvDeleted ,
9
+ EnvironmentCreated ,
10
+ EnvironmentUpdated ,
11
+ EnvironmentDeleted ,
12
12
EnvironmentSummary ,
13
13
)
14
14
from lib import app
@@ -25,15 +25,15 @@ def stub_env_summary():
25
25
26
26
def test_create_env (stub_env ):
27
27
with patch .object (
28
- EnvController , 'create_env' , return_value = EnvCreated (env_id = '123' )
28
+ EnvironmentController , 'create_env' , return_value = EnvironmentCreated (env_id = '123' )
29
29
) as mock_create_env :
30
30
response = client .post ('/environments/' , json = stub_env )
31
31
assert response .status_code == 200
32
32
assert response .json () == {
33
33
'env_id' : '123' ,
34
34
'message' : 'Environment successfully created' ,
35
35
}
36
- mock_create_env .assert_called_once_with (Env (** stub_env ))
36
+ mock_create_env .assert_called_once_with (EnvironmentModel (** stub_env ))
37
37
38
38
39
39
def test_create_env_optional_params ():
@@ -46,15 +46,15 @@ def test_create_env_optional_params():
46
46
'date' : '2021-01-01T00:00:00' ,
47
47
}
48
48
with patch .object (
49
- EnvController , 'create_env' , return_value = EnvCreated (env_id = '123' )
49
+ EnvironmentController , 'create_env' , return_value = EnvironmentCreated (env_id = '123' )
50
50
) as mock_create_env :
51
51
response = client .post ('/environments/' , json = test_object )
52
52
assert response .status_code == 200
53
53
assert response .json () == {
54
54
'env_id' : '123' ,
55
55
'message' : 'Environment successfully created' ,
56
56
}
57
- mock_create_env .assert_called_once_with (Env (** test_object ))
57
+ mock_create_env .assert_called_once_with (EnvironmentModel (** test_object ))
58
58
59
59
60
60
def test_create_env_invalid_input ():
@@ -66,7 +66,7 @@ def test_create_env_invalid_input():
66
66
67
67
def test_create_env_server_error (stub_env ):
68
68
with patch .object (
69
- EnvController ,
69
+ EnvironmentController ,
70
70
'create_env' ,
71
71
side_effect = HTTPException (
72
72
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
@@ -79,7 +79,7 @@ def test_create_env_server_error(stub_env):
79
79
80
80
def test_read_env (stub_env ):
81
81
with patch .object (
82
- EnvController , 'get_env_by_id' , return_value = Env (** stub_env )
82
+ EnvironmentController , 'get_env_by_id' , return_value = EnvironmentModel (** stub_env )
83
83
) as mock_read_env :
84
84
response = client .get ('/environments/123' )
85
85
assert response .status_code == 200
@@ -89,7 +89,7 @@ def test_read_env(stub_env):
89
89
90
90
def test_read_env_not_found ():
91
91
with patch .object (
92
- EnvController ,
92
+ EnvironmentController ,
93
93
'get_env_by_id' ,
94
94
side_effect = HTTPException (status_code = status .HTTP_404_NOT_FOUND ),
95
95
) as mock_read_env :
@@ -101,7 +101,7 @@ def test_read_env_not_found():
101
101
102
102
def test_read_env_server_error ():
103
103
with patch .object (
104
- EnvController ,
104
+ EnvironmentController ,
105
105
'get_env_by_id' ,
106
106
side_effect = HTTPException (
107
107
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
@@ -114,17 +114,17 @@ def test_read_env_server_error():
114
114
115
115
def test_update_env (stub_env ):
116
116
with patch .object (
117
- EnvController ,
117
+ EnvironmentController ,
118
118
'update_env_by_id' ,
119
- return_value = EnvUpdated (env_id = '123' ),
119
+ return_value = EnvironmentUpdated (env_id = '123' ),
120
120
) as mock_update_env :
121
121
response = client .put ('/environments/123' , json = stub_env )
122
122
assert response .status_code == 200
123
123
assert response .json () == {
124
124
'env_id' : '123' ,
125
125
'message' : 'Environment successfully updated' ,
126
126
}
127
- mock_update_env .assert_called_once_with ('123' , Env (** stub_env ))
127
+ mock_update_env .assert_called_once_with ('123' , EnvironmentModel (** stub_env ))
128
128
129
129
130
130
def test_update_env_invalid_input ():
@@ -136,7 +136,7 @@ def test_update_env_invalid_input():
136
136
137
137
def test_update_env_not_found (stub_env ):
138
138
with patch .object (
139
- EnvController ,
139
+ EnvironmentController ,
140
140
'update_env_by_id' ,
141
141
side_effect = HTTPException (status_code = status .HTTP_404_NOT_FOUND ),
142
142
):
@@ -147,7 +147,7 @@ def test_update_env_not_found(stub_env):
147
147
148
148
def test_update_env_server_error (stub_env ):
149
149
with patch .object (
150
- EnvController ,
150
+ EnvironmentController ,
151
151
'update_env_by_id' ,
152
152
side_effect = HTTPException (
153
153
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
@@ -160,9 +160,9 @@ def test_update_env_server_error(stub_env):
160
160
161
161
def test_delete_env ():
162
162
with patch .object (
163
- EnvController ,
163
+ EnvironmentController ,
164
164
'delete_env_by_id' ,
165
- return_value = EnvDeleted (env_id = '123' ),
165
+ return_value = EnvironmentDeleted (env_id = '123' ),
166
166
) as mock_delete_env :
167
167
response = client .delete ('/environments/123' )
168
168
assert response .status_code == 200
@@ -175,7 +175,7 @@ def test_delete_env():
175
175
176
176
def test_delete_env_server_error ():
177
177
with patch .object (
178
- EnvController ,
178
+ EnvironmentController ,
179
179
'delete_env_by_id' ,
180
180
side_effect = HTTPException (
181
181
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
@@ -188,7 +188,7 @@ def test_delete_env_server_error():
188
188
189
189
def test_simulate_env (stub_env_summary ):
190
190
with patch .object (
191
- EnvController ,
191
+ EnvironmentController ,
192
192
'simulate_env' ,
193
193
return_value = EnvironmentSummary (** stub_env_summary ),
194
194
) as mock_simulate_env :
@@ -200,7 +200,7 @@ def test_simulate_env(stub_env_summary):
200
200
201
201
def test_simulate_env_not_found ():
202
202
with patch .object (
203
- EnvController ,
203
+ EnvironmentController ,
204
204
'simulate_env' ,
205
205
side_effect = HTTPException (status_code = status .HTTP_404_NOT_FOUND ),
206
206
) as mock_simulate_env :
@@ -212,7 +212,7 @@ def test_simulate_env_not_found():
212
212
213
213
def test_simulate_env_server_error ():
214
214
with patch .object (
215
- EnvController ,
215
+ EnvironmentController ,
216
216
'simulate_env' ,
217
217
side_effect = HTTPException (
218
218
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
@@ -225,7 +225,7 @@ def test_simulate_env_server_error():
225
225
226
226
def test_read_rocketpy_env ():
227
227
with patch .object (
228
- EnvController , 'get_rocketpy_env_binary' , return_value = b'rocketpy'
228
+ EnvironmentController , 'get_rocketpy_env_binary' , return_value = b'rocketpy'
229
229
) as mock_read_rocketpy_env :
230
230
response = client .get ('/environments/123/rocketpy' )
231
231
assert response .status_code == 203
@@ -236,7 +236,7 @@ def test_read_rocketpy_env():
236
236
237
237
def test_read_rocketpy_env_not_found ():
238
238
with patch .object (
239
- EnvController ,
239
+ EnvironmentController ,
240
240
'get_rocketpy_env_binary' ,
241
241
side_effect = HTTPException (status_code = status .HTTP_404_NOT_FOUND ),
242
242
) as mock_read_rocketpy_env :
@@ -248,7 +248,7 @@ def test_read_rocketpy_env_not_found():
248
248
249
249
def test_read_rocketpy_env_server_error ():
250
250
with patch .object (
251
- EnvController ,
251
+ EnvironmentController ,
252
252
'get_rocketpy_env_binary' ,
253
253
side_effect = HTTPException (
254
254
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
0 commit comments