File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,31 @@ 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
+ # Make sure our expected unicode string literal is indeed unicode
553
+ # in both py2 and py3
554
+ self .assertEqual (reason_unicode [0 ].encode ("utf-8" ), b"\xc2 \xa1 " )
555
+
556
+ sess = OAuth2Session ("test-id" )
557
+
558
+ with self .assertRaises (HTTPError ) as cm :
559
+ sess ._raise_for_5xx (fake_resp )
560
+
561
+ self .assertEqual (cm .exception .args [0 ], expected )
562
+
538
563
539
564
class OAuth2SessionNetrcTest (OAuth2SessionTest ):
540
565
"""Ensure that there is no magic auth handling.
You can’t perform that action at this time.
0 commit comments