Beispiel #1
0
 def test_when_error_occurs_should_have_called_client(self):
     handler = ErrorHandler(self.config)
     http_handler = FakeHandler()
     handler.handle_error(self.context, http_handler, RuntimeError("Test"))
     content = self.tmp.read()
     log = json.loads(content)
     del log['extra']['timestamp']
     expect(log).to_be_like({
         'Http': {
             'url': 'http://test/test/',
             'method': 'GET',
             'data': [],
             'body': "body",
             'query_string': "a=1&b=2"
         },
         'interfaces.User': {
             'ip': "127.0.0.1",
         },
         'exception': 'Test',
         'extra': {
             'thumbor-version': __version__,
             'Headers': {
                 'header1': 'value1',
                 'Cookie': {
                     'cookie1': 'value',
                     'cookie2': 'value2'
                 }
             },
         }
     })
Beispiel #2
0
 def test_when_error_occurs_should_have_called_client(self):
     handler = ErrorHandler(self.config)
     http_handler = FakeHandler()
     handler.handle_error(self.context, http_handler, RuntimeError("Test"))
     content = self.tmp.read()
     log = json.loads(content)
     del log['extra']['timestamp']
     expect(log).to_be_like({
         'Http': {
             'url': 'http://test/test/',
             'method': 'GET',
             'data': [],
             'body': "body",
             'query_string': "a=1&b=2"
         },
         'interfaces.User': {
             'ip': "127.0.0.1",
         },
         'exception': 'Test',
         'extra': {
             'thumbor-version': __version__,
             'Headers': {
                 'header1': 'value1',
                 'Cookie': {
                     'cookie1': 'value',
                     'cookie2': 'value2'
                 }
             },
         }
     })
Beispiel #3
0
 def test_when_error_occurs_should_have_called_client(self):
     handler = ErrorHandler(self.config)
     http_handler = FakeHandler()
     handler.handle_error(self.context, http_handler, RuntimeError("Test"))
     content = self.tmp.read()
     log = json.loads(content.decode("utf-8"))
     del log["extra"]["timestamp"]
     expect(log).to_be_like({
         "Http": {
             "url": "http://test/test/",
             "method": "GET",
             "data": [],
             "body": "body",
             "query_string": "a=1&b=2",
         },
         "interfaces.User": {
             "ip": "127.0.0.1"
         },
         "exception": "Test",
         "extra": {
             "thumbor-version": __version__,
             "Headers": {
                 "header1": "value1",
                 "Cookie": {
                     "cookie1": "value",
                     "cookie2": "value2"
                 },
             },
         },
     })
Beispiel #4
0
    def test_when_error_occurs_i_use_context_should_have_called_client(self):
        handler = ErrorHandler(self.config)
        http_handler = FakeHandler()
        handler.handle_error(self.context, http_handler, RuntimeError("Test"))
        content = self.tmp.read()

        # check against json version
        log = json.loads(content)
        del log["extra"]["timestamp"]
        expect(log).to_be_like(
            {
                "Http": {
                    "url": "http://test/test/",
                    "method": "GET",
                    "data": [],
                    "body": "body",
                    "query_string": "a=1&b=2",
                },
                "interfaces.User": {"ip": "127.0.0.1"},
                "exception": "Test",
                "extra": {
                    "thumbor-version": __version__,
                    "Headers": {"header1": "value1", "Cookie": {"cookie1": "value", "cookie2": "value2"}},
                },
            }
        )
Beispiel #5
0
        def topic(self):
            #use temporary file to store logs
            tmp = tempfile.NamedTemporaryFile(prefix='thumborTest.')

            cfg = Config(SECURITY_KEY='ACME-SEC', ERROR_FILE_LOGGER=tmp.name)
            server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
            server.security_key = 'ACME-SEC'
            ctx = Context(server, cfg, None)

            handler = ErrorHandler(cfg)
            http_handler = FakeHandler()

            handler.handle_error(ctx, http_handler, RuntimeError("Test"))
            #return content of file
            return tmp.read()
Beispiel #6
0
 def test_when_invalid_configuration_of_filename_with_context_should_be_error(
     self, ):
     cfg = Config(
         ERROR_FILE_NAME_USE_CONTEXT="server..port",
         ERROR_FILE_LOGGER="toto",
     )
     with expect.error_to_happen(RuntimeError):
         ErrorHandler(cfg)
Beispiel #7
0
 def test_WhenInvalidConfigurationOfFileNameWithContext_should_be_error(
         self):
     cfg = Config(ERROR_FILE_NAME_USE_CONTEXT='server..port',
                  ERROR_FILE_LOGGER='toto')
     with expect.error_to_happen(RuntimeError):
         ErrorHandler(cfg)
Beispiel #8
0
 def test_when_invalid_empty_configuration(self):
     with expect.error_to_happen(RuntimeError):
         ErrorHandler(self.config)
Beispiel #9
0
 def topic(self):
     cfg = Config()
     ErrorHandler(cfg)
Beispiel #10
0
 def topic(self):
     cfg = Config(ERROR_FILE_NAME_USE_CONTEXT='server..port', ERROR_FILE_LOGGER='toto')
     ErrorHandler(cfg)