Ejemplo n.º 1
0
    def setup_http_strategy(self, http_do):
        config = AttributeGetter({
                "base_url": (lambda: ""),
                "has_access_token": (lambda: False),
                "has_client_credentials": (lambda: False),
                "http_strategy": (lambda: AttributeGetter({"http_do": http_do})),
                "public_key": "",
                "private_key": "",
                "wrap_http_exceptions": False})

        return Http(config, "fake_environment")
Ejemplo n.º 2
0
 def test_header_includes_gzip_accept_encoding(self):
     config = AttributeGetter({
             "base_url": (lambda: ""),
             "has_access_token": (lambda: False),
             "has_client_credentials": (lambda: False),
             "public_key": "",
             "private_key": ""})
     headers = Http(config, "fake_environment")._Http__headers(Http.ContentType.Xml)
     self.assertTrue('Accept-Encoding' in headers)
     self.assertEqual('gzip', headers["Accept-Encoding"])
Ejemplo n.º 3
0
    def test_backtrace_preserved_when_not_wrapping_exceptions(self):
        class Error(Exception):
            pass
        def raise_error(*_):
            raise Error
        http_strategy = AttributeGetter({"http_do": raise_error})
        config = AttributeGetter({
                "base_url": (lambda: ""),
                "has_access_token": (lambda: False),
                "has_client_credentials": (lambda: False),
                "http_strategy": (lambda: http_strategy),
                "public_key": "",
                "private_key": "",
                "wrap_http_exceptions": False})

        try:
            Http(config, "fake_environment").post("/example/path/to/reach")
        except Error:
            _, _, tb = sys.exc_info()
            self.assertEqual('raise_error', traceback.extract_tb(tb)[-1][2])