File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,34 @@ def fake_send(r, **kwargs):
535
535
sess .fetch_token (url )
536
536
self .assertTrue (sess .authorized )
537
537
538
+ def test_raise_for_5xx (self ):
539
+ for reason_bytes in [
540
+ b"\xa1 An error occurred!" , # iso-8859-i
541
+ b"\xc2 \xa1 An error occurred!" , # utf-8
542
+ ]:
543
+ fake_resp = mock .MagicMock ()
544
+ fake_resp .status_code = 504
545
+ fake_resp .reason = reason_bytes
546
+ reason_unicode = "¡An error occurred!"
547
+ fake_resp .url = "https://example.com/token"
548
+ expected = (
549
+ "504 Server Error: " + reason_unicode + " for url: " + fake_resp .url
550
+ )
551
+
552
+ # Verify that our sample is unicode in both Python2 and Python3
553
+ try :
554
+ unicode ("" )
555
+ except NameError :
556
+ unicode = str
557
+ self .assertIsInstance (reason_unicode , unicode )
558
+
559
+ sess = OAuth2Session ("test-id" )
560
+
561
+ with self .assertRaises (HTTPError ) as cm :
562
+ sess ._raise_for_5xx (fake_resp )
563
+
564
+ self .assertEqual (cm .exception .args [0 ], expected )
565
+
538
566
539
567
class OAuth2SessionNetrcTest (OAuth2SessionTest ):
540
568
"""Ensure that there is no magic auth handling.
You can’t perform that action at this time.
0 commit comments