Example #1
0
 def _install_upgrades(self, *api_ids):
     executioner = IExecutioner(self.portal_setup)
     try:
         with ResponseLogger(self.request.RESPONSE, annotate_result=True):
             executioner.install_upgrades_by_api_ids(*api_ids)
     except Exception, exc:
         raise AbortTransactionWithStreamedResponse(exc)
Example #2
0
 def _install_profiles(self, *profile_ids, **options):
     executioner = IExecutioner(self.portal_setup)
     try:
         with ResponseLogger(self.request.RESPONSE, annotate_result=True):
             executioner.install_profiles_by_profile_ids(
                 *profile_ids, **options)
     except Exception as exc:
         raise AbortTransactionWithStreamedResponse(exc)
Example #3
0
 def _install_upgrades(self, *api_ids, **kwargs):
     propose_deferrable = kwargs.pop('propose_deferrable', True)
     executioner = IExecutioner(self.portal_setup)
     try:
         with ResponseLogger(self.request.RESPONSE, annotate_result=True):
             executioner.install_upgrades_by_api_ids(
                 *api_ids, propose_deferrable=propose_deferrable)
     except Exception as exc:
         raise AbortTransactionWithStreamedResponse(exc)
    def test_logging(self):
        response = StringIO()

        with ResponseLogger(response):
            logging.error('foo')
            logging.error('bar')

        response.seek(0)
        self.assertEqual(['foo', u'bar'], response.read().strip().split('\n'))
Example #5
0
    def test_annotate_result_on_success(self):
        response = BytesIO()

        with ResponseLogger(response, annotate_result=True):
            logging.error('foo')
            logging.error('bar')

        response.seek(0)
        self.assertEqual([b'foo', b'bar', b'Result: SUCCESS'],
                         response.read().strip().split(b'\n'))
Example #6
0
    def test_logged_tags_get_escaped(self):
        response = BytesIO()

        with ResponseLogger(response):
            logging.error('ERROR: Something at <TextBlock at /bla/blub>')

        response.seek(0)
        self.assertEqual(
            [b'ERROR: Something at &lt;TextBlock at /bla/blub&gt;'],
            response.read().strip().split(b'\n'))
    def test_logging_exceptions(self):
        response = StringIO()

        with self.assertRaises(KeyError):
            with ResponseLogger(response):
                raise KeyError('foo')

        response.seek(0)
        output = response.read().strip()
        # Dynamically replace paths so that it works on all machines
        output = re.sub(r'(File ").*(ftw/upgrade/.*")', r'\1/.../\2', output)

        self.assertEqual(output.split('\n'), [
            'FAILED', 'Traceback (most recent call last):',
            '  File "/.../ftw/upgrade/tests/'
            'test_manage_view.py", line 31, in test_logging_exceptions',
            "    raise KeyError('foo')", "KeyError: 'foo'"
        ])
    def test_annotate_result_on_error(self):
        response = StringIO()

        with self.assertRaises(KeyError):
            with ResponseLogger(response, annotate_result=True):
                raise KeyError('foo')

        response.seek(0)
        output = response.read().strip()
        # Dynamically replace paths so that it works on all machines
        output = re.sub(r'(File ").*(ftw/upgrade/.*")', r'\1/.../\2', output)
        output = re.sub(r'(line )\d*', r'line XX', output)

        self.assertEqual([
            'FAILED', 'Traceback (most recent call last):',
            '  File "/.../ftw/upgrade/tests/'
            'test_manage_view.py", line XX, in test_annotate_result_on_error',
            "    raise KeyError('foo')", "KeyError: 'foo'", 'Result: FAILURE'
        ], output.split('\n'))