Exemplo n.º 1
0
    def test_request_is_sent(self):
        http_client = MockHTTPClient()

        req = ThreadedRequest('http://foo/bar', '<data></data>',
                              http_client=http_client)
        req.run()  # synced call

        self.assertEquals([{'url': 'http://foo/bar',
                            'data': '<data></data>'}],
                          http_client.posted)
Exemplo n.º 2
0
    def test_exceptions_are_catched_and_printed(self):
        http_client = ErrorMockHTTPClient()
        log = StringIO()
        req = ThreadedRequest('http://foo/bar',
                              '<data></data>',
                              http_client=http_client,
                              log=log)

        with NothingRaised():
            req.run()  # synced call

        self.assertEquals('ERROR: Failed to post to errbit: Exception: HTTP Error',
                          log.getvalue())
Exemplo n.º 3
0
    def post(self, exc_info, request=None):
        if not self.get_errbit_url():
            logging.error('ERRBIT_URL not configured as environment variable.')

        if not self.get_api_key():
            logging.error('ERRBIT_API_KEY not configured as environment variable.')

        xml = xmlgenerator.generate_xml(self.get_api_key(),
                                        self.get_notifier(),
                                        exc_info, request=request,
                                        environment=self.get_environment())

        http_client = self.http_client()
        req = ThreadedRequest(self.get_errbit_url(), xml, http_client=http_client)
        req.start()
Exemplo n.º 4
0
    def post(self, exc_info, request=None):
        if not self.get_errbit_url():
            logging.error('ERRBIT_URL not configured as environment variable.')

        if not self.get_api_key():
            logging.error(
                'ERRBIT_API_KEY not configured as environment variable.')

        xml = xmlgenerator.generate_xml(self.get_api_key(),
                                        self.get_notifier(),
                                        exc_info,
                                        request=request,
                                        environment=self.get_environment())

        req = ThreadedRequest(self.get_errbit_url(), xml)
        req.start()
Exemplo n.º 5
0
    def post(self, exc_info, request=None):
        if not self.get_errbit_url():
            logging.error('ERRBIT_URL not configured as environment variable.')
            return

        if not self.get_api_key():
            logging.error('ERRBIT_API_KEY not configured as environment '
                          'variable.')
            return

        if self.is_ignored(exc_info):
            return

        xml = xmlgenerator.generate_xml(self.get_api_key(),
                                        self.get_notifier(),
                                        exc_info,
                                        request=request,
                                        environment=self.get_environment())

        http_client = self.http_client()
        req = ThreadedRequest(self.get_errbit_url(),
                              xml,
                              http_client=http_client)
        req.start()
Exemplo n.º 6
0
    def test_request_is_sent(self):
        http_client = MockHTTPClient()

        req = ThreadedRequest('http://foo/bar',
                              '<data></data>',
                              http_client=http_client)
        req.start()
        req.join()

        self.assertEquals([{
            'url': 'http://foo/bar',
            'data': '<data></data>'
        }], http_client.posted)
Exemplo n.º 7
0
    def test_exceptions_are_catched_and_printed(self):
        http_client = ErrorMockHTTPClient()
        log = StringIO()
        req = ThreadedRequest('http://foo/bar',
                              '<data></data>',
                              http_client=http_client,
                              log=log)

        with NothingRaised():
            req.start()
            req.join()

        self.assertEquals(
            'ERROR: Failed to post to errbit: Exception: HTTP Error',
            log.getvalue())
Exemplo n.º 8
0
    def test_exceptions_are_catched_and_logged(self):
        self.expect_request('http://foo', 'data', throws=500)
        self.mocker.replay()

        ThreadedRequest('http://foo', 'data').run()
        self.assertIn('http error 500', self.read_log())
Exemplo n.º 9
0
    def test_request_is_sent(self):
        self.expect_request('http://foo/bar', '<data></data>')
        self.mocker.replay()

        req = ThreadedRequest('http://foo/bar', '<data></data>')
        req.run()  # synced call