diff options
Diffstat (limited to '_pytest/test_http_check_ratelimited.py')
-rw-r--r-- | _pytest/test_http_check_ratelimited.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/_pytest/test_http_check_ratelimited.py b/_pytest/test_http_check_ratelimited.py new file mode 100644 index 0000000..948f247 --- /dev/null +++ b/_pytest/test_http_check_ratelimited.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +from __future__ import print_function, unicode_literals +from textwrap import dedent + +from wee_slack import SlackRequest + + +def test_http_check_ratelimited_supports_multiple_headers(realish_eventrouter): + response = ( + dedent( + """ + HTTP/1.1 200 Connection established + + HTTP/2 200 + content-type: application/json; charset=utf-8 + + {"ok": true} + """ + ) + .strip() + .replace("\n", "\r\n") + ) + + request_metadata = SlackRequest(None, "", token="xoxp-1") + body, error = realish_eventrouter.http_check_ratelimited(request_metadata, response) + assert body == '{"ok": true}' + assert error == "" + + +def test_http_check_ratelimited_return_error_when_ratelimited(realish_eventrouter): + response = ( + dedent( + """ + HTTP/2 429 + content-type: application/json; charset=utf-8 + retry-after: 10 + + {"ok": false, "error": "ratelimited"} + """ + ) + .strip() + .replace("\n", "\r\n") + ) + + request_metadata = SlackRequest(None, "", token="xoxp-1") + body, error = realish_eventrouter.http_check_ratelimited(request_metadata, response) + assert body == "" + assert error == "ratelimited" |