11import json
2- from typing import Dict , List
2+ from typing import Dict , List , Type
33from unittest .mock import patch
44
55import pytest
66from marshmallow import ValidationError
77
88from pygitguardian import GGClient
9+ from pygitguardian .client import is_ok , load_detail
910from pygitguardian .config import (
1011 DEFAULT_BASE_URI ,
1112 DOCUMENT_SIZE_THRESHOLD_BYTES ,
183184 ],
184185)
185186def test_client_creation (
186- api_key : str , uri : str , user_agent : str , timeout : float , exception : Exception
187+ api_key : str , uri : str , user_agent : str , timeout : float , exception : Type [ Exception ]
187188):
188189 if exception is not None :
189190 with pytest .raises (exception ):
@@ -299,7 +300,7 @@ def test_multi_content_scan(
299300 ],
300301)
301302def test_content_scan_exceptions (
302- client : GGClient , to_scan : str , exception : Exception , regex : str
303+ client : GGClient , to_scan : str , exception : Type [ Exception ] , regex : str
303304):
304305 with pytest .raises (exception , match = regex ):
305306 client .content_scan (to_scan )
@@ -313,7 +314,7 @@ def test_content_scan_exceptions(
313314 ],
314315)
315316def test_multi_content_exceptions (
316- client : GGClient , to_scan : List , exception : Exception
317+ client : GGClient , to_scan : List , exception : Type [ Exception ]
317318):
318319 with pytest .raises (exception ):
319320 client .multi_content_scan (to_scan )
@@ -326,7 +327,7 @@ def test_multi_content_not_ok():
326327
327328 obj = client .multi_content_scan (req )
328329
329- assert obj .status_code , 401
330+ assert obj .status_code == 401
330331 assert isinstance (obj , Detail )
331332 assert obj .detail == "Invalid API key."
332333
@@ -338,7 +339,7 @@ def test_content_not_ok():
338339
339340 obj = client .content_scan (** req )
340341
341- assert obj .status_code , 401
342+ assert obj .status_code == 401
342343 assert isinstance (obj , Detail )
343344 assert obj .detail == "Invalid API key."
344345
@@ -401,5 +402,17 @@ def test_content_scan(
401402
402403@my_vcr .use_cassette
403404def test_assert_content_type (client : GGClient ):
404- with pytest .raises (TypeError ):
405- client .get (endpoint = "/docs/static/logo.png" , version = None )
405+ """
406+ GIVEN a response that's 200 but the content is not JSON
407+ WHEN is_ok is called
408+ THEN is_ok should be false
409+ WHEN load_detail is called
410+ THEN is should return a Detail object
411+ """
412+ resp = client .get (endpoint = "/docs/static/logo.png" , version = None )
413+ assert is_ok (resp ) is False
414+ obj = load_detail (resp )
415+ obj .status_code = resp .status_code
416+ assert obj .status_code == 200
417+ assert isinstance (obj , Detail )
418+ assert str (obj ).startswith ("200:" ), str (obj )
0 commit comments