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)
    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)
Beispiel #3
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)
    def test_decorator(self):
        request = Mock()
        request.META = {
            'HTTP_USER_AGENT': 'KDDI-SA31 UP.Browser/6.2.0.6.3.129 (GUI) MMP/2.0'
        }
        request.opensocial_viewer_id = '12345678'

        mw.action_log_decorator_initialized = False

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

        @mw.action_log_decorator
        def logging(request):
            with mw.log().log('log1', x=10, y='str', id=id, time=now):
                pass

        mw.sender = Mock()

        logging(request)

        log1 = { 'uid': '12345678',
                 'ver': 2,
                 'time': now,
                 'device': DeviceType.FP,
                 'id': id,
                 'action': 'log1',
                 'x': 10,
                 'y': 'str' }
        expected = [call.emit(log1)]
        eq_(expected, mw.sender.mock_calls)
Beispiel #5
0
    def test_decorator(self):
        request = Mock()
        request.META = {
            'HTTP_USER_AGENT':
            'KDDI-SA31 UP.Browser/6.2.0.6.3.129 (GUI) MMP/2.0'
        }
        request.opensocial_viewer_id = '12345678'

        mw.action_log_decorator_initialized = False

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

        @mw.action_log_decorator
        def logging(request):
            with mw.log().log('log1', x=10, y='str', id=id, time=now):
                pass

        mw.sender = Mock()

        logging(request)

        log1 = {
            'uid': '12345678',
            'ver': 2,
            'time': now,
            'device': DeviceType.FP,
            'id': id,
            'action': 'log1',
            'x': 10,
            'y': 'str'
        }
        expected = [call.emit(log1)]
        eq_(expected, mw.sender.mock_calls)
    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)
Beispiel #7
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)
Beispiel #8
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)