Exemplo n.º 1
0
    def test_log_decorator(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'
        id2 = 'id2'

        mw.log().set(a=1, x=20, y=100, z=3000)
        #mw.log().log('log1')(self._log1func)(now, id, id2)
        #mw.deco.log('log1')(_log1func)(now, id, id2)
        self._log1func(now, id, id2)

        actlogmw.process_response(request, None)

        log1 = { 'uid': '12345678',
                 'ver': 2,
                 'time': now,
                 'device': DeviceType.FP,
                 'id': id,
                 'action': 'log1',
                 'x': 10,
                 'y': 'str' }
        dlog1 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': id,
                  'parent': 'log1',
                  'action': 'dlog1',
                  'z': 10 }
        dlog3 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': id,
                  'parent': 'log1',
                  'action': 'dlog3' }
        log2 = { 'uid': '12345678',
                 'ver': 2,
                 'time': now,
                 'device': DeviceType.FP,
                 'parentid': id,
                 'parent': 'log1',
                 'id': id2,
                 'action': 'log2',
                 'z': 100 }
        dlog2 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': id2,
                  'parent': 'log2',
                  'action': 'dlog2' }
        expected = [call.emit(log1),
                    call.emit(dlog1),
                    call.emit(dlog3),
                    call.emit(log2),
                    call.emit(dlog2)]
        eq_(expected, mw.sender.mock_calls)
Exemplo n.º 2
0
    def test_continuous_log(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id2 = 'id2'

        with mw.log().log('log1', x=10, y='str', time=now):
            uid = request.action_logger.uid
            device = request.action_logger.device
            actname = mw.log().actname
            actid = mw.log().id

        actlogmw.process_response(request, None)

        with mw.ActionLogger(mw.sender, uid, device, actname, actid):
            mw.log().derivedlog.log('dlog1', z=10, time=now)
            with mw.log().log('log2', id=id2, time=now):
                mw.log().set(z=100)
                mw.log().derivedlog.log('dlog2', time=now)

        log1 = { 'uid': '12345678',
                 'ver': 2,
                 'time': now,
                 'device': DeviceType.FP,
                 'id': actid,
                 'action': 'log1',
                 'x': 10,
                 'y': 'str' }
        dlog1 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': actid,
                  'parent': 'log1',
                  'action': 'dlog1',
                  'z': 10 }
        log2 = { 'uid': '12345678',
                 'ver': 2,
                 'time': now,
                 'device': DeviceType.FP,
                 'parentid': actid,
                 'parent': 'log1',
                 'id': id2,
                 'action': 'log2',
                 'z': 100 }
        dlog2 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': id2,
                  'parent': 'log2',
                  'action': 'dlog2' }
        expected = [call.emit(log1),
                    call.emit(dlog1),
                    call.emit(log2),
                    call.emit(dlog2)]
        eq_(expected, mw.sender.mock_calls)
Exemplo n.º 3
0
        def get_args(self, request):
            if not hasattr(request, 'action_logger'):
                return None

            try:
                from kome.middleware.actionlog import log
            except ImportError:
                return None

            return {'userid': request.action_logger.uid,
                    'devicename': request.action_logger.device,
                    'parent': log().actname,
                    'parentid': log().id}
Exemplo n.º 4
0
    def test_traceback(self):
        self._to_no_debug_mode()

        (actlogmw, request) = self._init_request()
        with mw.log().register():
            pass
        actlogmw.process_response(request, None)
Exemplo n.º 5
0
    def test_traceback(self):
        self._to_no_debug_mode()

        (actlogmw, request) = self._init_request()
        with mw.log().register():
            pass
        actlogmw.process_response(request, None)
Exemplo n.º 6
0
    def test_raise_arg_not_enough(self):
        self._to_debug_mode()

        #raise TypeError('%s() takes %s %d %s (%d given)' % (
        #    f_name, 'at least' if defaults else 'exactly', num_required,
        #    'arguments' if num_required > 1 else 'argument', num_total))
        with mw.log().register():
            pass
Exemplo n.º 7
0
    def test_raise_arg_not_enough(self):
        self._to_debug_mode()

        #raise TypeError('%s() takes %s %d %s (%d given)' % (
        #    f_name, 'at least' if defaults else 'exactly', num_required,
        #    'arguments' if num_required > 1 else 'argument', num_total))
        with mw.log().register():
            pass
Exemplo n.º 8
0
    def test_noparent_derivedlog(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'

        mw.log().derivedlog.log('dlog1', z=10, time=now)

        actlogmw.process_response(request, None)

        mw.sender.emit.assert_called_with({
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'action': 'dlog1',
            'z': 10 })
Exemplo n.º 9
0
    def test_noparent_derivedlog(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'

        mw.log().derivedlog.log('dlog1', z=10, time=now)

        actlogmw.process_response(request, None)

        mw.sender.emit.assert_called_with({
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'action': 'dlog1',
            'z': 10
        })
Exemplo n.º 10
0
    def test_log_except_partial(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'
        id2 = 'id2'

        with mw.log().log('log1', x=10, y='str', id=id, time=now):
            mw.log().derivedlog.log('dlog1', z=10, time=now)
            try:
                with mw.log().log('log2', id=id2, time=now):
                    mw.log().derivedlog.log('dlog2', time=now)
                    raise Exception
            except:
                pass
            mw.log().derivedlog.log('dlog3', time=now)

        actlogmw.process_response(request, None)

        log1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'id': id,
            'action': 'log1',
            'x': 10,
            'y': 'str'
        }
        dlog1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id,
            'parent': 'log1',
            'action': 'dlog1',
            'z': 10
        }
        dlog3 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id,
            'parent': 'log1',
            'action': 'dlog3'
        }
        expected = [call.emit(log1), call.emit(dlog1), call.emit(dlog3)]
        eq_(expected, mw.sender.mock_calls)
Exemplo n.º 11
0
    def test_log_except_partial(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'
        id2 = 'id2'

        with mw.log().log('log1', x=10, y='str', id=id, time=now):
            mw.log().derivedlog.log('dlog1', z=10, time=now)
            try:
                with mw.log().log('log2', id=id2, time=now):
                    mw.log().derivedlog.log('dlog2', time=now)
                    raise Exception
            except:
                pass
            mw.log().derivedlog.log('dlog3', time=now)

        actlogmw.process_response(request, None)

        log1 = { 'uid': '12345678',
                 'ver': 2,
                 'time': now,
                 'device': DeviceType.FP,
                 'id': id,
                 'action': 'log1',
                 'x': 10,
                 'y': 'str' }
        dlog1 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': id,
                  'parent': 'log1',
                  'action': 'dlog1',
                  'z': 10 }
        dlog3 = { 'uid': '12345678',
                  'ver': 2,
                  'time': now,
                  'device': DeviceType.FP,
                  'parentid': id,
                  'parent': 'log1',
                  'action': 'dlog3' }
        expected = [call.emit(log1),
                    call.emit(dlog1),
                    call.emit(dlog3)]
        eq_(expected, mw.sender.mock_calls)
Exemplo n.º 12
0
    def test_log_except_all(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'
        id2 = 'id2'

        try:
            with mw.log().log('log1', x=10, y='str', id=id, time=now):
                mw.log().derivedlog.log('dlog1', z=10, time=now)
                with mw.log().log('log2', id=id2, time=now):
                    mw.log().derivedlog.log('dlog2', time=now)
                    raise Exception
                mw.log().derivedlog.log('dlog3', time=now)
        except:
            pass

        actlogmw.process_response(request, None)

        eq_([], mw.sender.mock_calls)
Exemplo n.º 13
0
    def test_log_except_all(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'
        id2 = 'id2'

        try:
            with mw.log().log('log1', x=10, y='str', id=id, time=now):
                mw.log().derivedlog.log('dlog1', z=10, time=now)
                with mw.log().log('log2', id=id2, time=now):
                    mw.log().derivedlog.log('dlog2', time=now)
                    raise Exception
                mw.log().derivedlog.log('dlog3', time=now)
        except:
            pass

        actlogmw.process_response(request, None)

        eq_([], mw.sender.mock_calls)
Exemplo n.º 14
0
 def logging(request):
     with mw.log().log('log1', x=10, y='str', id=id, time=now):
         pass
Exemplo n.º 15
0
 def _log1func(self, now, id, id2):
     mw.log().set(x=10, y='str', id=id, time=now)
     mw.log().derivedlog.log('dlog1', z=10, time=now)
     self._log2func(now, id, id2)
     mw.log().derivedlog.log('dlog3', time=now)
Exemplo n.º 16
0
 def _log2func(self, now, id, id2):
     mw.log().set(id=id2, time=now)
     mw.log().set(z=100)
     mw.log().derivedlog.log('dlog2', time=now)
Exemplo n.º 17
0
    def test_log_decorator(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id = 'id'
        id2 = 'id2'

        mw.log().set(a=1, x=20, y=100, z=3000)
        #mw.log().log('log1')(self._log1func)(now, id, id2)
        #mw.deco.log('log1')(_log1func)(now, id, id2)
        self._log1func(now, id, id2)

        actlogmw.process_response(request, None)

        log1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'id': id,
            'action': 'log1',
            'x': 10,
            'y': 'str'
        }
        dlog1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id,
            'parent': 'log1',
            'action': 'dlog1',
            'z': 10
        }
        dlog3 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id,
            'parent': 'log1',
            'action': 'dlog3'
        }
        log2 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id,
            'parent': 'log1',
            'id': id2,
            'action': 'log2',
            'z': 100
        }
        dlog2 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id2,
            'parent': 'log2',
            'action': 'dlog2'
        }
        expected = [
            call.emit(log1),
            call.emit(dlog1),
            call.emit(dlog3),
            call.emit(log2),
            call.emit(dlog2)
        ]
        eq_(expected, mw.sender.mock_calls)
Exemplo n.º 18
0
 def test_raise_noexists_method(self):
     mw.log().notexists_method()
Exemplo n.º 19
0
 def test_raise_noexists_method(self):
     mw.log().notexists_method()
Exemplo n.º 20
0
    def test_continuous_log(self):
        (actlogmw, request) = self._init_request()

        now = datetime.now()
        id2 = 'id2'

        with mw.log().log('log1', x=10, y='str', time=now):
            uid = request.action_logger.uid
            device = request.action_logger.device
            actname = mw.log().actname
            actid = mw.log().id

        actlogmw.process_response(request, None)

        with mw.ActionLogger(mw.sender, uid, device, actname, actid):
            mw.log().derivedlog.log('dlog1', z=10, time=now)
            with mw.log().log('log2', id=id2, time=now):
                mw.log().set(z=100)
                mw.log().derivedlog.log('dlog2', time=now)

        log1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'id': actid,
            'action': 'log1',
            'x': 10,
            'y': 'str'
        }
        dlog1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': actid,
            'parent': 'log1',
            'action': 'dlog1',
            'z': 10
        }
        log2 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': actid,
            'parent': 'log1',
            'id': id2,
            'action': 'log2',
            'z': 100
        }
        dlog2 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'parentid': id2,
            'parent': 'log2',
            'action': 'dlog2'
        }
        expected = [
            call.emit(log1),
            call.emit(dlog1),
            call.emit(log2),
            call.emit(dlog2)
        ]
        eq_(expected, mw.sender.mock_calls)
Exemplo n.º 21
0
 def _log2func(self, now, id, id2):
     mw.log().set(id=id2, time=now)
     mw.log().set(z=100)
     mw.log().derivedlog.log('dlog2', time=now)
Exemplo n.º 22
0
 def _log1func(self, now, id, id2):
     mw.log().set(x=10, y='str', id=id, time=now)
     mw.log().derivedlog.log('dlog1', z=10, time=now)
     self._log2func(now, id, id2)
     mw.log().derivedlog.log('dlog3', time=now)
Exemplo n.º 23
0
 def logging(request):
     with mw.log().log('log1', x=10, y='str', id=id, time=now):
         pass