'A normal request is handled properly'

def test_request(self):

    email = self.example_email('hamlet')
    self.login(email)
    with patch('zerver.decorator.rate_limit') as rate_limit_patch:
        rate_limit_patch.side_effect = capture_and_throw
        result = self.client_get('/json/users')
        self.assert_json_error(result, 'Internal    server    error', status_code=500)
        rate_limit_patch.assert_called_once()
        global captured_request
        global captured_exc_info
        record = self.logger.makeRecord('name', logging.ERROR, 'function', 15, 'message', {}, captured_exc_info)
        record.request = captured_request
        report = self.run_handler(record)
        self.assertIn('user_email', report)
        self.assertIn('message', report)
        self.assertIn('stack_trace', report)
        with patch('zerver.logging_handlers.traceback.print_exc'):
            with patch('zerver.logging_handlers.add_request_metadata', side_effect=Exception('Unexpected    exception!')):
                report = self.run_handler(record)
        self.assertNotIn('user_email', report)
        self.assertIn('message', report)
        self.assertEqual(report['stack_trace'], 'See    /var/log/zulip/errors.log')
        record.request.user = AnonymousUser()
        report = self.run_handler(record)
        self.assertIn('host', report)
        self.assertIn('user_email', report)
        self.assertIn('message', report)
        self.assertIn('stack_trace', report)
        def get_host_error():
            raise Exception('Get    Host    Failure!')
        orig_get_host = record.request.get_host
        record.request.get_host = get_host_error
        report = self.run_handler(record)
        record.request.get_host = orig_get_host
        self.assertIn('host', report)
        self.assertIn('user_email', report)
        self.assertIn('message', report)
        self.assertIn('stack_trace', report)
        with patch('zerver.logging_handlers.get_exception_reporter_filter', return_value=15):
            record.request.method = 'POST'
            report = self.run_handler(record)
            record.request.method = 'GET'
        self.assertIn('host', report)
        self.assertIn('user_email', report)
        self.assertIn('message', report)
        self.assertIn('stack_trace', report)
        with patch('zerver.logging_handlers.queue_json_publish', side_effect=Exception('queue    error')):
            self.handler.emit(record)
        with self.settings(STAGING_ERROR_NOTIFICATIONS=True):
            with patch('zerver.lib.error_notify.notify_server_error', side_effect=Exception('queue    error')):
                self.handler.emit(record)
        record.exc_info = None
        report = self.run_handler(record)
        self.assertIn('host', report)
        self.assertIn('user_email', report)
        self.assertIn('message', report)
        self.assertEqual(report['stack_trace'], None)
        record.request.user = None
        with patch('zerver.logging_handlers.traceback.print_exc'):
            report = self.run_handler(record)
        self.assertIn('host', report)
        self.assertIn('user_email', report)
        self.assertIn('message', report)
        self.assertIn('stack_trace', report)
