Esempio n. 1
0
 def test_formatting(self):
     err = StripeError(u'öre')
     self.assertEqual(u'öre', six.text_type(err))
     if six.PY2:
         self.assertEqual('\xc3\xb6re', str(err))
     else:
         self.assertEqual(u'öre', str(err))
Esempio n. 2
0
 def test_formatting_with_message_none_and_request_id(self):
     err = StripeError(None, headers={'request-id': '123'})
     self.assertEqual(u'Request 123: <empty message>', six.text_type(err))
     if six.PY2:
         self.assertEqual('Request 123: <empty message>', str(err))
     else:
         self.assertEqual('Request 123: <empty message>', str(err))
Esempio n. 3
0
 def test_formatting_with_message_none_and_request_id_none(self):
     err = StripeError(None)
     self.assertEqual(u'<empty message>', six.text_type(err))
     if six.PY2:
         self.assertEqual('<empty message>', str(err))
     else:
         self.assertEqual('<empty message>', str(err))
Esempio n. 4
0
 def test_formatting_with_message_none_and_request_id_none(self):
     err = error.StripeError(None)
     assert six.text_type(err) == u'<empty message>'
     if six.PY2:
         assert str(err) == '<empty message>'
     else:
         assert str(err) == u'<empty message>'
Esempio n. 5
0
 def test_formatting_with_request_id(self):
     err = StripeError(u'öre', headers={'request-id': '123'})
     self.assertEqual(u'Request 123: öre', six.text_type(err))
     if six.PY2:
         self.assertEqual('Request 123: \xc3\xb6re', str(err))
     else:
         self.assertEqual(u'Request 123: öre', str(err))
Esempio n. 6
0
 def test_formatting(self):
     err = error.StripeError(u'öre')
     assert six.text_type(err) == u'öre'
     if six.PY2:
         assert str(err) == '\xc3\xb6re'
     else:
         assert str(err) == u'öre'
Esempio n. 7
0
 def test_formatting_with_none(self):
     err = error.StripeError(None, 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>'
Esempio n. 8
0
 def test_formatting_with_request_id(self):
     err = error.StripeError(u'öre', 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'
Esempio n. 9
0
 def test_formatting(self):
     err = error.StripeError(u"öre")
     assert six.text_type(err) == u"öre"
     if six.PY2:
         assert str(err) == "\xc3\xb6re"
     else:
         assert str(err) == u"öre"
Esempio n. 10
0
 def test_formatting_with_none(self):
     err = error.StripeError(None, 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>"
Esempio n. 11
0
 def test_formatting_with_request_id(self):
     err = error.StripeError(u"öre", 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 = stripe.stripe_object.StripeObject("foo", "bar", myparam=5)

        obj["object"] = 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"<StripeObject \u4e00boo\u1f00" in res
        assert u"id=foo" in res
        assert u'"date": 1511136000' in res
Esempio n. 13
0
    def test_repr(self):
        obj = stripe.stripe_object.StripeObject("foo", "bar", myparam=5)

        obj["object"] = 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"<StripeObject \u4e00boo\u1f00" in res
        assert u"id=foo" in res
        assert u'"date": 1511136000' in res
Esempio n. 14
0
    def test_repr(self):
        obj = stripe.stripe_object.StripeObject('foo', 'bar', myparam=5)

        obj['object'] = u'\u4e00boo\u1f00'
        obj.date = datetime.datetime.fromtimestamp(1511136000)

        res = repr(obj)

        if six.PY2:
            res = six.text_type(repr(obj), 'utf-8')

        self.assertTrue(u'<StripeObject \u4e00boo\u1f00' in res)
        self.assertTrue(u'id=foo' in res)
        self.assertTrue(u'"date": 1511136000' in res)
Esempio n. 15
0
 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)
Esempio n. 16
0
 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)