Skip to content

Commit 4a72e26

Browse files
committed
Add test for invalid header
1 parent cbe3fe9 commit 4a72e26

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_auth.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,35 @@ def test_api_rate_limit_exception(self):
679679
{API_RATE_LIMIT_RETRY_AFTER_HEADER: 10},
680680
)
681681

682+
def test_api_rate_limit_invalid_header(self):
683+
auth = Auth(self.dummy_project_id, self.public_key_dict)
684+
685+
# Test do_post empty body
686+
with patch("requests.post") as mock_request:
687+
mock_request.return_value.ok = False
688+
mock_request.return_value.status_code = 429
689+
mock_request.return_value.json.return_value = {
690+
"errorCode": "E130429",
691+
"errorDescription": "https://docs.descope.com/rate-limit",
692+
"errorMessage": "API rate limit exceeded.",
693+
}
694+
mock_request.return_value.headers = {
695+
API_RATE_LIMIT_RETRY_AFTER_HEADER: "hello"
696+
}
697+
with self.assertRaises(RateLimitException) as cm:
698+
auth.do_post("http://test.com", {}, None, None)
699+
the_exception = cm.exception
700+
self.assertEqual(the_exception.status_code, "E130429")
701+
self.assertEqual(the_exception.error_type, ERROR_TYPE_API_RATE_LIMIT)
702+
self.assertEqual(
703+
the_exception.error_description, "https://docs.descope.com/rate-limit"
704+
)
705+
self.assertEqual(the_exception.error_message, "API rate limit exceeded.")
706+
self.assertEqual(
707+
the_exception.rate_limit_parameters,
708+
{API_RATE_LIMIT_RETRY_AFTER_HEADER: 0},
709+
)
710+
682711
def test_api_rate_limit_invalid_response_body(self):
683712
auth = Auth(self.dummy_project_id, self.public_key_dict)
684713

0 commit comments

Comments
 (0)