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)
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}
def test_traceback(self): self._to_no_debug_mode() (actlogmw, request) = self._init_request() with mw.log().register(): pass actlogmw.process_response(request, None)
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
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 })
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_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)
def logging(request): with mw.log().log('log1', x=10, y='str', id=id, time=now): pass
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)
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)
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_raise_noexists_method(self): mw.log().notexists_method()
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)