def test_formatting(self): err = error.TelnyxError(u"öre") assert six.text_type(err) == u"öre" if six.PY2: assert str(err) == "\xc3\xb6re" else: assert str(err) == u"öre"
def test_formatting_with_message_none_and_request_id_none(self): err = error.TelnyxError(None) assert six.text_type(err) == u"<empty message>" if six.PY2: assert str(err) == "<empty message>" else: assert str(err) == u"<empty message>"
def test_formatting_with_none(self): err = error.TelnyxError(None, http_headers={"request-id": "123"}) assert six.text_type(err) == u"Request 123: <empty message>" if six.PY2: assert str(err) == "Request 123: <empty message>" else: assert str(err) == "Request 123: <empty message>"
def test_formatting_with_request_id(self): err = error.TelnyxError(u"öre", http_headers={"request-id": "123"}) assert six.text_type(err) == u"Request 123: öre" if six.PY2: assert str(err) == "Request 123: \xc3\xb6re" else: assert str(err) == u"Request 123: öre"
def test_repr(self): obj = telnyx.telnyx_object.TelnyxObject("foo", "bar", myparam=5) obj["record_type"] = u"\u4e00boo\u1f00" obj.date = datetime.datetime.fromtimestamp(1511136000) res = repr(obj) if six.PY2: res = six.text_type(repr(obj), "utf-8") assert u"<TelnyxObject \u4e00boo\u1f00" in res assert u"id=foo" in res assert u'"date": 1511136000' in res
def fmt(key, val): # Handle case where val is a bytes or bytesarray if six.PY3 and hasattr(val, "decode"): val = val.decode("utf-8") # Check if val is already a string to avoid re-encoding into # ascii. Since the code is sent through 2to3, we can't just # use unicode(val, encoding='utf8') since it will be # translated incorrectly. if not isinstance(val, six.string_types): val = six.text_type(val) if re.search(r"\s", val): val = repr(val) # key should already be a string if re.search(r"\s", key): key = repr(key) return u"{key}={val}".format(key=key, val=val)