mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
zerver/tests/test_helpers.py: Use text_type for api_keys.
Also encode/decode strings appropriately when using api_keys to generate basic auth header. Also fix clashing annotations in zerver/tests/test_external.py.
This commit is contained in:
@@ -50,7 +50,7 @@ from zerver.lib.str_utils import NonBinaryStr
|
||||
from contextlib import contextmanager
|
||||
import six
|
||||
|
||||
API_KEYS = {} # type: Dict[str, str]
|
||||
API_KEYS = {} # type: Dict[text_type, text_type]
|
||||
|
||||
@contextmanager
|
||||
def stub(obj, name, f):
|
||||
@@ -285,16 +285,16 @@ class AuthedTestCase(TestCase):
|
||||
'terms': True})
|
||||
|
||||
def get_api_key(self, email):
|
||||
# type: (str) -> str
|
||||
# type: (text_type) -> text_type
|
||||
if email not in API_KEYS:
|
||||
API_KEYS[email] = get_user_profile_by_email(email).api_key
|
||||
return API_KEYS[email]
|
||||
|
||||
def api_auth(self, email):
|
||||
# type: (str) -> Dict[str, str]
|
||||
credentials = "%s:%s" % (email, self.get_api_key(email))
|
||||
# type: (text_type) -> Dict[str, text_type]
|
||||
credentials = u"%s:%s" % (email, self.get_api_key(email))
|
||||
return {
|
||||
'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode(credentials)
|
||||
'HTTP_AUTHORIZATION': u'Basic ' + base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
|
||||
}
|
||||
|
||||
def get_streams(self, email):
|
||||
|
||||
@@ -22,9 +22,10 @@ import DNS
|
||||
import mock
|
||||
import time
|
||||
import ujson
|
||||
from six.moves import urllib
|
||||
|
||||
from six.moves import urllib
|
||||
from six.moves import range
|
||||
from six import text_type
|
||||
|
||||
class MITNameTest(TestCase):
|
||||
def test_valid_hesiod(self):
|
||||
@@ -66,7 +67,7 @@ class RateLimitTests(AuthedTestCase):
|
||||
remove_ratelimit_rule(1, 5)
|
||||
|
||||
def send_api_message(self, email, api_key, content):
|
||||
# type: (str, str, str) -> HttpResponse
|
||||
# type: (text_type, text_type, text_type) -> HttpResponse
|
||||
return self.client.post("/api/v1/send_message", {"type": "stream",
|
||||
"to": "Verona",
|
||||
"client": "test suite",
|
||||
|
||||
Reference in New Issue
Block a user