Skip to content

Commit 546a81d

Browse files
committed
chore: make test_multi_content_scan() more readable
- Remove VCR decorator: the code uses a VCR `with` block. - Do not wrap the wall test in the VCR `with` block: only wrap the call to `client.multi_content_scan()` - Early return if `expected` is None - Load `expected` into `example_dict` only once
1 parent 445f190 commit 546a81d

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

tests/test_client.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ def test_health_check(client: GGClient):
341341
),
342342
],
343343
)
344-
@my_vcr.use_cassette
345344
def test_multi_content_scan(
346345
client: GGClient,
347346
name: str,
@@ -353,28 +352,23 @@ def test_multi_content_scan(
353352
with my_vcr.use_cassette(name + ".yaml"):
354353
multiscan = client.multi_content_scan(to_scan)
355354

356-
assert multiscan.status_code == 200
357-
if not isinstance(multiscan, MultiScanResult):
358-
pytest.fail("multiscan is not a MultiScanResult")
359-
return
360-
361-
assert type(multiscan.to_dict()) == OrderedDict
362-
assert type(multiscan.to_json()) == str
363-
assert type(repr(multiscan)) == str
364-
assert type(str(multiscan)) == str
365-
assert multiscan.has_secrets == has_secrets
366-
assert multiscan.has_policy_breaks == has_policy_breaks
367-
368-
for i, scan_result in enumerate(multiscan.scan_results):
369-
if expected:
370-
example_dict = json.loads(expected)
371-
assert all(
372-
elem in example_dict[i]["policies"] for elem in scan_result.policies
373-
)
374-
assert (
375-
scan_result.policy_break_count
376-
== example_dict[i]["policy_break_count"]
377-
)
355+
assert multiscan.status_code == 200
356+
assert isinstance(multiscan, MultiScanResult)
357+
358+
assert type(multiscan.to_dict()) == OrderedDict
359+
assert type(multiscan.to_json()) == str
360+
assert type(repr(multiscan)) == str
361+
assert type(str(multiscan)) == str
362+
assert multiscan.has_secrets == has_secrets
363+
assert multiscan.has_policy_breaks == has_policy_breaks
364+
365+
if not expected:
366+
return
367+
368+
example_dict = json.loads(expected)
369+
for i, scan_result in enumerate(multiscan.scan_results):
370+
assert all(elem in example_dict[i]["policies"] for elem in scan_result.policies)
371+
assert scan_result.policy_break_count == example_dict[i]["policy_break_count"]
378372

379373

380374
@patch("pygitguardian.config.DOCUMENT_SIZE_THRESHOLD_BYTES", 20)

0 commit comments

Comments
 (0)