Example #1
0
    def test_info_logging_404s(self):
        ''' 404 errors log at INFO level
        '''
        with HTTMock(self.auth_csv_example_allowed):
            with HTTMock(self.mock_persona_verify_erica):
                erica = ChimeTestClient(self.app.test_client(), self)
                erica.sign_in('*****@*****.**')

        with self.assertLogs('chime.view_functions', level='INFO') as cm:
            erica.open_link_blindly(url='/nothinghere')

        self.assertEqual(cm.output, ['INFO:chime.view_functions:404: Not Found'])
Example #2
0
    def test_logging_failure_format(self):
        from chime.view_functions import log_application_errors

        @log_application_errors
        def fail():
            raise ValueError('blow up')

        self.app.app.add_url_rule('/fail', None, fail)
        with HTTMock(self.auth_csv_example_allowed):
            with HTTMock(self.mock_persona_verify_erica):
                erica = ChimeTestClient(self.app.test_client(), self)
                erica.sign_in('*****@*****.**')

        with self.assertLogs('chime.view_functions',
                             level='DEBUG',
                             formatter=ChimeErrorReportFormatter()) as cm:
            erica.open_link(url='/fail', expected_status_code=500)

        self.assertEqual(1, len(cm.output))

        self.assertTrue(hasattr(cm.records[0], 'request'))
        self.assertRegexpMatches(cm.output[0], '.*ERROR.*blow up.*')

        self.assertRegexpMatches(cm.output[0], "state =")
        self.assertRegexpMatches(cm.output[0], '"method": "GET"')
Example #3
0
    def test_logging_failure_format(self):
        from chime.view_functions import log_application_errors

        @log_application_errors
        def fail():
            raise ValueError('blow up')

        self.app.app.add_url_rule('/fail', None, fail)
        with HTTMock(self.auth_csv_example_allowed):
            with HTTMock(self.mock_persona_verify_erica):
                erica = ChimeTestClient(self.app.test_client(), self)
                erica.sign_in('*****@*****.**')

        with self.assertLogs('chime.view_functions', level='DEBUG', formatter=ChimeErrorReportFormatter()) as cm:
            erica.open_link_blindly(url='/fail')

        self.assertEqual(1, len(cm.output))

        self.assertTrue(hasattr(cm.records[0], 'request'))
        self.assertRegexpMatches(cm.output[0], '.*ERROR.*blow up.*')

        self.assertRegexpMatches(cm.output[0], "state =")
        self.assertRegexpMatches(cm.output[0], '"method": "GET"')
Example #4
0
    def test_info_logging_404s(self):
        ''' 404 errors log at INFO level
        '''
        with HTTMock(self.auth_csv_example_allowed):
            with HTTMock(self.mock_persona_verify_erica):
                erica = ChimeTestClient(self.app.test_client(), self)
                erica.sign_in('*****@*****.**')

        with self.assertLogs('chime.view_functions', level='INFO') as cm:
            erica.open_link(url='/nothinghere', expected_status_code=404)

        self.assertEqual(cm.output,
                         ['INFO:chime.view_functions:404: Not Found'])