|
7 | 7 | from descope import (
|
8 | 8 | API_RATE_LIMIT_RETRY_AFTER_HEADER,
|
9 | 9 | ERROR_TYPE_API_RATE_LIMIT,
|
| 10 | + ERROR_TYPE_SERVER_ERROR, |
10 | 11 | AuthException,
|
11 | 12 | DeliveryMethod,
|
12 | 13 | RateLimitException,
|
@@ -582,6 +583,25 @@ def test_api_rate_limit_exception(self):
|
582 | 583 | {API_RATE_LIMIT_RETRY_AFTER_HEADER: 10},
|
583 | 584 | )
|
584 | 585 |
|
| 586 | + def test_raise_from_response(self): |
| 587 | + auth = Auth(self.dummy_project_id, self.public_key_dict) |
| 588 | + with patch("requests.get") as mock_request: |
| 589 | + mock_request.return_value.ok = False |
| 590 | + mock_request.return_value.status_code = 400 |
| 591 | + mock_request.return_value.error_type = ERROR_TYPE_SERVER_ERROR |
| 592 | + mock_request.return_value.text = """{"errorCode":"E062108","errorDescription":"User not found","errorMessage":"Cannot find user","message":"Cannot find user"}""" |
| 593 | + with self.assertRaises(AuthException) as cm: |
| 594 | + auth.do_get(uri="http://test.com", params=False, allow_redirects=None) |
| 595 | + the_exception = cm.exception |
| 596 | + self.assertEqual(the_exception.status_code, 400) |
| 597 | + self.assertEqual(the_exception.error_type, ERROR_TYPE_SERVER_ERROR) |
| 598 | + with open("/tmp/ex.txt", "w") as f: |
| 599 | + f.write(the_exception.error_message) |
| 600 | + self.assertEqual( |
| 601 | + the_exception.error_message, |
| 602 | + """{"errorCode":"E062108","errorDescription":"User not found","errorMessage":"Cannot find user","message":"Cannot find user"}""", |
| 603 | + ) |
| 604 | + |
585 | 605 |
|
586 | 606 | if __name__ == "__main__":
|
587 | 607 | unittest.main()
|
0 commit comments