Exemplo n.º 1
0
def test_error_string_summary():
    result = MockResult()
    result.body = '''{
        "status": "error",
        "message": "Property values were not valid"
    }'''

    # Make sure string representation of the error starts with the error
    # message returned by HubSpot.
    exc = HubspotError(result=result, request={})
    exc_str_first_line = str(exc).split("\n", 1)[1]
    ok_(exc_str_first_line.startswith("Property values were not valid"))

    # Test falling back to a default error in case response doesn't contain one.
    exc = HubspotError(result=MockResult(), request={})
    exc_str_first_line = str(exc).split("\n", 1)[1]
    ok_(exc_str_first_line.startswith("Hubspot Error"))
Exemplo n.º 2
0
 def delete_setting(self, name, **options):
     """"Deletes" a specific setting by emptying out its value."""
     params = {}
     if name:
         params["name"] = name
     else:
         raise HubspotError("Setting name required.", "settings")
     return self._call("settings", params=params, method="DELETE", **options)
Exemplo n.º 3
0
 def delete_setting(self, name, **options):
     """"Deletes" a specific setting by emptying out its value."""
     params = {}
     if name:
         params['name'] = name
     else:
         raise HubspotError('Setting name required.')
     return self._call('settings',
                       params=params,
                       method='DELETE',
                       **options)
Exemplo n.º 4
0
def test_unicode_error():
    result = MockResult()
    result.body = 'A HapiException with unicode \\u8131 \xe2\x80\xa2\t'
    result.reason = 'Why must everything have a reason?'
    request = {}
    for key in ('method', 'host', 'url', 'timeout', 'data', 'headers'):
        request[key] = ''
    request['url'] = 'http://adomain/with-unicode-\u8131'
    # Note the following line is missing the 'u' modifier on the string,
    # this is intentional to simulate poorly formatted input that should
    # still be handled without an exception
    request['data'] = 'A HapiException with unicode \\u8131 \xe2\x80\xa2'
    request['headers'] = {'Cookie': 'with unicode \\u8131 \xe2\x80\xa2'}

    exc = HubspotError(result, request)
    ok_(request['url'] in exc)
    ok_(result.reason in exc)
Exemplo n.º 5
0
def test_unicode_error():
    result = MockResult()
    result.body = "A HapiException with unicode \\u8131 \xe2\x80\xa2\t"
    result.reason = "Why must everything have a reason?"
    request = {}
    for key in ("method", "host", "url", "timeout", "data", "headers"):
        request[key] = ""
    request["url"] = "http://adomain/with-unicode-\u8131"
    # Note the following line is missing the 'u' modifier on the string,
    # this is intentional to simulate poorly formatted input that should
    # still be handled without an exception
    request["data"] = "A HapiException with unicode \\u8131 \xe2\x80\xa2"
    request["headers"] = {"Cookie": "with unicode \\u8131 \xe2\x80\xa2"}

    exc = HubspotError(result, request)
    ok_(request["url"] in exc)
    ok_(result.reason in exc)
Exemplo n.º 6
0
def test_error_with_no_result_or_request():
    exc = HubspotError(None, None, 'a silly error')
    ok_('a silly error' in exc)
Exemplo n.º 7
0
def test_error_with_no_result_or_request():
    exc = HubspotError(None, None, "a silly error")
    ok_("a silly error" in exc)
Exemplo n.º 8
0
 def execute_request_failed(a, b):
     raise HubspotError(defaultdict(str), defaultdict(str))
Exemplo n.º 9
0
 def execute_request_with_retries(a, b):
     counter['count'] += 1
     if counter['count'] < 2:
         raise HubspotError(defaultdict(str), defaultdict(str))
     else:
         return TestResult(body='SUCCESS')