From e8e3277ce7386d41259cb7e644a41e3c03acd8b0 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sat, 17 Jun 2017 00:46:04 -0700 Subject: [PATCH] Merge in previous changes --- disco/api/client.py | 4 ++-- tests/test_reason.py | 11 +++++++++++ tests/utils.py | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/test_reason.py create mode 100644 tests/utils.py diff --git a/disco/api/client.py b/disco/api/client.py index 02e4c11..05bb594 100644 --- a/disco/api/client.py +++ b/disco/api/client.py @@ -4,7 +4,7 @@ import warnings from six.moves.urllib.parse import quote -from disco.api.http import Routes, HTTPClient +from disco.api.http import Routes, HTTPClient, to_bytes from disco.util.logging import LoggingClass from disco.util.sanitize import S from disco.types.user import User @@ -26,7 +26,7 @@ def optional(**kwargs): def _reason_header(value): - return optional(**{'X-Audit-Log-Reason': quote(value)}) + return optional(**{'X-Audit-Log-Reason': quote(to_bytes(value))}) class APIClient(LoggingClass): diff --git a/tests/test_reason.py b/tests/test_reason.py new file mode 100644 index 0000000..8d9b39c --- /dev/null +++ b/tests/test_reason.py @@ -0,0 +1,11 @@ +from unittest import TestCase +from utils import TestAPIClient + + +class TestReason(TestCase): + def test_set_unicode_reason(self): + api = TestAPIClient() + api.guilds_channels_modify(1, 2, 3, reason=u'yo \U0001F4BF test') + + _, kwargs = api.http.calls[0] + self.assertEquals(kwargs['headers']['X-Audit-Log-Reason'], 'yo%20%F0%9F%92%BF%20test') diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..74f9766 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,15 @@ +from disco.api.client import APIClient + + +class CallContainer(object): + def __init__(self): + self.calls = [] + + def __call__(self, *args, **kwargs): + self.calls.append((args, kwargs)) + + +class TestAPIClient(APIClient): + def __init__(self): + self.client = None + self.http = CallContainer()