Skip to content

Commit 2728445

Browse files
jguerreiroJguer
authored andcommitted
fix(detail): convert error to detail
1 parent 576eca4 commit 2728445

File tree

4 files changed

+125
-25
lines changed

4 files changed

+125
-25
lines changed

Pipfile.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pygitguardian/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from datetime import date
2-
from typing import ClassVar, Dict, List, Optional
2+
from typing import Any, ClassVar, Dict, List, Optional
33

44
from marshmallow import (
55
EXCLUDE,
66
Schema,
77
ValidationError,
88
fields,
99
post_load,
10+
pre_load,
1011
validate,
1112
validates,
1213
)
@@ -91,6 +92,14 @@ def __repr__(self):
9192
class DetailSchema(Schema):
9293
detail = fields.String(required=True)
9394

95+
@pre_load
96+
def rename_errors(self, data: Dict, many: bool, **kwargs: Any) -> Dict:
97+
error = data.pop("error", None)
98+
if error is not None:
99+
data["detail"] = str(error)
100+
101+
return data
102+
94103
@post_load
95104
def make_detail_response(self, data, **kwargs):
96105
return Detail(**data)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- "*/*"
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- pygitguardian/1.1.0 (Linux;py3.8.3)
13+
method: GET
14+
uri: https://api.gitguardian.com/v1/health
15+
response:
16+
body:
17+
string: '{"error":"Configuration error."}'
18+
headers:
19+
Allow:
20+
- OPTIONS, GET
21+
Connection:
22+
- keep-alive
23+
Content-Length:
24+
- "27"
25+
Content-Type:
26+
- application/json
27+
Date:
28+
- Fri, 19 Jun 2020 13:32:39 GMT
29+
Server:
30+
- nginx
31+
Vary:
32+
- Cookie
33+
X-Content-Type-Options:
34+
- nosniff
35+
X-Frame-Options:
36+
- DENY
37+
status:
38+
code: 400
39+
message: OK
40+
- request:
41+
body: null
42+
headers:
43+
Accept:
44+
- "*/*"
45+
Accept-Encoding:
46+
- gzip, deflate
47+
Connection:
48+
- keep-alive
49+
User-Agent:
50+
- pygitguardian/1.1.0 (Linux;py3.8.3)
51+
method: GET
52+
uri: https://api.gitguardian.com/v1/health
53+
response:
54+
body:
55+
string: '{"detail":"Valid API key."}'
56+
headers:
57+
Allow:
58+
- OPTIONS, GET
59+
Connection:
60+
- keep-alive
61+
Content-Length:
62+
- "27"
63+
Content-Type:
64+
- application/json
65+
Date:
66+
- Fri, 19 Jun 2020 14:58:35 GMT
67+
Server:
68+
- nginx
69+
Vary:
70+
- Cookie
71+
X-Content-Type-Options:
72+
- nosniff
73+
X-Frame-Options:
74+
- DENY
75+
status:
76+
code: 200
77+
message: OK
78+
version: 1

tests/test_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ def test_health_check(client: GGClient):
276276
assert type(health.to_json()) == str
277277

278278

279+
@my_vcr.use_cassette
280+
def test_health_check_error(client: GGClient):
281+
health = client.health_check()
282+
assert health.status_code == 400
283+
assert health.detail == "Configuration error."
284+
assert str(health) == "400:Configuration error."
285+
assert bool(health) is False
286+
assert health.success is False
287+
288+
assert type(health.to_dict()) == dict
289+
assert type(health.to_json()) == str
290+
291+
279292
@pytest.mark.parametrize(
280293
"name, to_scan, expected, has_secrets, has_policy_breaks",
281294
[

0 commit comments

Comments
 (0)