Browse Source

Merge in previous changes

pull/35/head
Andrei 8 years ago
parent
commit
e8e3277ce7
  1. 4
      disco/api/client.py
  2. 11
      tests/test_reason.py
  3. 15
      tests/utils.py

4
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):

11
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')

15
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()
Loading…
Cancel
Save