コード例 #1
0
 def add_action_logger(sm):
     #Register Action Logger utility
     try:
         sm.getUtility(IActionLogger)
     except:
         sm.registerUtility(ActionLogger(), IActionLogger)
         self.log.debug('Added action logger utility to %s' %
                        portal.absolute_url())
     else:
         self.log.debug('Already has action logger')
コード例 #2
0
class ActionLoggerTest(TestCase):
    """ Basic unittest """
    def setUp(self):
        self.action_logger = ActionLogger()

    def test_add_log(self):
        """ Add a log using action logger api """

        action_log = ActionLogItem(message="Some message")
        log_id = self.action_logger.append(action_log)
        self.assertEqual({log_id: action_log}, dict(self.action_logger))

    def test_add_log_convenience(self):
        """ Add a log using a convenience method """

        log_id = self.action_logger.create(message="Some type")
        self.assertEqual(len(self.action_logger), 1)

    def test_add_log_error_type(self):
        self.assertRaises(AssertionError, self.action_logger.append,
                          'Bad type')

    def test_items(self):
        types = ['a', 'b', 'c']
        for i in range(1, 10):
            self.action_logger.create(type=random.choice(types),
                                      message="type")
        for log_id, log in self.action_logger.items(type='a'):
            self.assertEqual(log.type, 'a')

        self.assertEqual(len(self.action_logger.items()),
                         len(self.action_logger))

    def test_remove_log(self):
        log_id = self.action_logger.create(type="Some type")
        del self.action_logger[log_id]
        self.assertEqual(dict(self.action_logger), {})
コード例 #3
0
 def setUp(self):
     self.action_logger = ActionLogger()