Skip to content

Commit fd7ebbf

Browse files
committed
fix(tests): rework test checking conversion of Detail error field
Tests should not rely on manually modified VCR cassettes. Those do not represent a real situation.
1 parent 451c462 commit fd7ebbf

File tree

4 files changed

+16
-103
lines changed

4 files changed

+16
-103
lines changed

pygitguardian/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class Detail(Base):
115115
api output is a simple string.
116116
117117
Attributes:
118-
status_code (int): response status code
119118
detail (str): response string
120119
"""
121120

tests/cassettes/test_health_check_error.yaml

Lines changed: 0 additions & 86 deletions
This file was deleted.

tests/test_client.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,6 @@ def test_health_check(client: GGClient):
275275
assert type(health.to_json()) == str
276276

277277

278-
@my_vcr.use_cassette
279-
def test_health_check_error(client: GGClient):
280-
health = client.health_check()
281-
assert health.status_code == 400
282-
assert health.detail == "Configuration error."
283-
assert str(health) == (
284-
"detail:Configuration error., status_code:400, "
285-
"app version:1.26.0-rc.4, secrets engine version:2.43.0"
286-
)
287-
assert bool(health) is False
288-
assert health.success is False
289-
290-
assert type(health.to_dict()) == OrderedDict
291-
assert type(health.to_json()) == str
292-
293-
294278
@pytest.mark.parametrize(
295279
"name, to_scan, expected, has_secrets, has_policy_breaks",
296280
[

tests/test_models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import pytest
44

55
from pygitguardian.models import (
6+
Detail,
7+
DetailSchema,
68
Document,
79
DocumentSchema,
810
HealthCheckResponseSchema,
@@ -110,6 +112,11 @@ def test_document_handle_0_bytes(self):
110112
ScanResult,
111113
{"policy_break_count": 1, "policy_breaks": [], "policies": []},
112114
),
115+
(
116+
DetailSchema,
117+
Detail,
118+
{"detail": "Fail"},
119+
),
113120
],
114121
)
115122
def test_schema_loads(self, schema_klass, expected_klass, instance_data):
@@ -125,3 +132,12 @@ def test_schema_loads(self, schema_klass, expected_klass, instance_data):
125132

126133
obj = schema.load(data)
127134
assert isinstance(obj, expected_klass)
135+
136+
def test_detail_renames_error_field(self):
137+
"""
138+
GIVEN a Detail JSON dict with an `error` field instead of a `detail` field
139+
WHEN loading using the schema
140+
THEN the created Detail instance contains a `detail` field with the right value
141+
"""
142+
detail = Detail.SCHEMA.load({"error": "An error message"})
143+
assert detail.detail == "An error message"

0 commit comments

Comments
 (0)