def topic(self): cfg = Config(SECURITY_KEY='ACME-SEC', SENTRY_DSN_URL="http://sentry-dsn-url") server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, None) client_mock = FakeSentry("FAKE DSN") handler = ErrorHandler(cfg, client=client_mock) http_handler = FakeHandler() handler.handle_error(ctx, http_handler, RuntimeError("Test")) return client_mock
def test_when_error_occurs_should_have_called_client(self): handler = ErrorHandler(self.config, client=self.client_mock) handler.handle_error(self.context, self.http_handler, RuntimeError("Test")) expect(self.client_mock.captured_exceptions).not_to_be_empty() expect(self.client_mock.captured_exceptions).to_length(1) exception, args, kw = self.client_mock.captured_exceptions[0] expect(exception.__class__.__name__).to_equal("RuntimeError") expect(kw).to_include('data') expect(kw).to_include('extra') data, extra = kw['data'], kw['extra'] expect(extra).to_include('thumbor-version') expect(extra['thumbor-version']).to_equal(__version__) expect(extra).to_include('Headers') expect(extra['Headers']).to_length(2) expect(extra['Headers']).to_include('Cookie') expect(extra['Headers']['Cookie']).to_length(2) expect(data['modules']).not_to_be_empty() del data['modules'] expect(data).to_be_like({ 'sentry.interfaces.Http': { 'url': "http://test/test/", 'method': "GET", 'data': [], 'body': "body", 'query_string': "a=1&b=2" }, 'sentry.interfaces.User': { 'ip': "127.0.0.1", } })
def topic(self): cfg = Config() ErrorHandler(cfg)
def test_when_invalid_configuration(self): with expect.error_to_happen(RuntimeError): ErrorHandler(self.config)