Skip to content

Commit 1280b70

Browse files
authored
Improve error handling for NeonAPI fixture
Move error handling to the common request function and add a debug log. Signed-off-by: Tristan Partin <[email protected]>
1 parent b4e00b8 commit 1280b70

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

test_runner/fixtures/neon_api.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import requests
77

8+
from fixtures.log_helper import log
9+
810
if TYPE_CHECKING:
911
from typing import Any, Literal, Optional
1012

@@ -30,7 +32,11 @@ def __request(self, method: str | bytes, endpoint: str, **kwargs: Any) -> reques
3032
kwargs["headers"] = {}
3133
kwargs["headers"]["Authorization"] = f"Bearer {self.__neon_api_key}"
3234

33-
return requests.request(method, f"{self.__neon_api_base_url}{endpoint}", **kwargs)
35+
resp = requests.request(method, f"{self.__neon_api_base_url}{endpoint}", **kwargs)
36+
log.debug("%s %s returned a %d: %s", method, endpoint, resp.status_code, resp.text)
37+
resp.raise_for_status()
38+
39+
return resp
3440

3541
def create_project(
3642
self,
@@ -66,8 +72,6 @@ def create_project(
6672
json=data,
6773
)
6874

69-
assert resp.status_code == 201
70-
7175
return cast("dict[str, Any]", resp.json())
7276

7377
def get_project_details(self, project_id: str) -> dict[str, Any]:
@@ -79,7 +83,7 @@ def get_project_details(self, project_id: str) -> dict[str, Any]:
7983
"Content-Type": "application/json",
8084
},
8185
)
82-
assert resp.status_code == 200
86+
8387
return cast("dict[str, Any]", resp.json())
8488

8589
def delete_project(
@@ -95,8 +99,6 @@ def delete_project(
9599
},
96100
)
97101

98-
assert resp.status_code == 200
99-
100102
return cast("dict[str, Any]", resp.json())
101103

102104
def start_endpoint(
@@ -112,8 +114,6 @@ def start_endpoint(
112114
},
113115
)
114116

115-
assert resp.status_code == 200
116-
117117
return cast("dict[str, Any]", resp.json())
118118

119119
def suspend_endpoint(
@@ -129,8 +129,6 @@ def suspend_endpoint(
129129
},
130130
)
131131

132-
assert resp.status_code == 200
133-
134132
return cast("dict[str, Any]", resp.json())
135133

136134
def restart_endpoint(
@@ -146,8 +144,6 @@ def restart_endpoint(
146144
},
147145
)
148146

149-
assert resp.status_code == 200
150-
151147
return cast("dict[str, Any]", resp.json())
152148

153149
def create_endpoint(
@@ -178,8 +174,6 @@ def create_endpoint(
178174
json=data,
179175
)
180176

181-
assert resp.status_code == 201
182-
183177
return cast("dict[str, Any]", resp.json())
184178

185179
def get_connection_uri(
@@ -206,8 +200,6 @@ def get_connection_uri(
206200
},
207201
)
208202

209-
assert resp.status_code == 200
210-
211203
return cast("dict[str, Any]", resp.json())
212204

213205
def get_branches(self, project_id: str) -> dict[str, Any]:
@@ -219,8 +211,6 @@ def get_branches(self, project_id: str) -> dict[str, Any]:
219211
},
220212
)
221213

222-
assert resp.status_code == 200
223-
224214
return cast("dict[str, Any]", resp.json())
225215

226216
def get_endpoints(self, project_id: str) -> dict[str, Any]:
@@ -232,8 +222,6 @@ def get_endpoints(self, project_id: str) -> dict[str, Any]:
232222
},
233223
)
234224

235-
assert resp.status_code == 200
236-
237225
return cast("dict[str, Any]", resp.json())
238226

239227
def get_operations(self, project_id: str) -> dict[str, Any]:
@@ -246,8 +234,6 @@ def get_operations(self, project_id: str) -> dict[str, Any]:
246234
},
247235
)
248236

249-
assert resp.status_code == 200
250-
251237
return cast("dict[str, Any]", resp.json())
252238

253239
def wait_for_operation_to_finish(self, project_id: str):

0 commit comments

Comments
 (0)