@@ -45,29 +45,10 @@ def strip(self, chars=None): # type: ignore[override]
4545
4646
4747@pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
48- def test_transport_wraps_api_key_character_iteration_failures (transport_class ):
49- class _BrokenIterApiKey (str ):
50- def strip (self , chars = None ): # type: ignore[override]
51- _ = chars
52- return self
53-
54- def __iter__ (self ):
55- raise RuntimeError ("api key iteration exploded" )
56-
57- with pytest .raises (
58- HyperbrowserError , match = "Failed to validate api_key characters"
59- ) as exc_info :
60- transport_class (api_key = _BrokenIterApiKey ("test-key" ))
61-
62- assert isinstance (exc_info .value .original_error , RuntimeError )
63-
64-
65- @pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
66- def test_transport_wraps_api_key_empty_check_length_failures (transport_class ):
48+ def test_transport_wraps_api_key_string_subclass_strip_results (transport_class ):
6749 class _BrokenLengthApiKey (str ):
6850 class _NormalizedKey (str ):
69- def __len__ (self ):
70- raise RuntimeError ("api key length exploded" )
51+ pass
7152
7253 def strip (self , chars = None ): # type: ignore[override]
7354 _ = chars
@@ -76,41 +57,10 @@ def strip(self, chars=None): # type: ignore[override]
7657 with pytest .raises (HyperbrowserError , match = "Failed to normalize api_key" ) as exc_info :
7758 transport_class (api_key = _BrokenLengthApiKey ("test-key" ))
7859
79- assert isinstance (exc_info .value .original_error , RuntimeError )
80-
81-
82- @pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
83- def test_transport_preserves_hyperbrowser_api_key_empty_check_length_failures (
84- transport_class ,
85- ):
86- class _BrokenLengthApiKey (str ):
87- class _NormalizedKey (str ):
88- def __len__ (self ):
89- raise HyperbrowserError ("custom length failure" )
90-
91- def strip (self , chars = None ): # type: ignore[override]
92- _ = chars
93- return self ._NormalizedKey ("test-key" )
94-
95- with pytest .raises (HyperbrowserError , match = "custom length failure" ) as exc_info :
96- transport_class (api_key = _BrokenLengthApiKey ("test-key" ))
97-
98- assert exc_info .value .original_error is None
60+ assert isinstance (exc_info .value .original_error , TypeError )
9961
10062
10163@pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
102- def test_transport_preserves_hyperbrowser_api_key_character_iteration_failures (
103- transport_class ,
104- ):
105- class _BrokenIterApiKey (str ):
106- def strip (self , chars = None ): # type: ignore[override]
107- _ = chars
108- return self
109-
110- def __iter__ (self ):
111- raise HyperbrowserError ("custom iteration failure" )
112-
113- with pytest .raises (HyperbrowserError , match = "custom iteration failure" ) as exc_info :
114- transport_class (api_key = _BrokenIterApiKey ("test-key" ))
115-
116- assert exc_info .value .original_error is None
64+ def test_transport_rejects_blank_normalized_api_keys (transport_class ):
65+ with pytest .raises (HyperbrowserError , match = "api_key must not be empty" ):
66+ transport_class (api_key = " " )
0 commit comments