def test_logs_with_an_existing_log(self): Log.objects().delete() answer = [{ 'userId': '12345', 'sessionId': 'asdfg', 'actions': [{ 'time': '2018-10-18T21:37:28-06:00', 'type': 'CLICK', 'properties': { 'locationX': 52, 'locationY': 22 } }] }] action = Action(_time='2018-10-18T21:37:28-06:00', _type='CLICK', _properties=ClickProperties(locationX=52, locationY=22)) log = Log(userId='12345', sessionId='asdfg', actions=[action]) log.save() result = LogService.get_logs(None, None, None, None) assert result is not None assert result == answer log.delete()
def test_invalid_datetime_format_logs_3(self): Log.objects().delete() try: result = LogService.get_logs(None, '2018-10-20T21:37:28-04:00', '2018-10-20T21:37:28-04:00', None) assert False except Exception as e: assert str(e) == "INVALID_TIME_FORMAT"
def test_logs_with_an_matching_log_userId(self): Log.objects().delete() answer = [{ "userId": "12345", "sessionId": "asdfg", "actions": [{ "time": "2018-10-18T21:37:28-06:00", "properties": { "locationX": 52, "locationY": 22 }, "type": "CLICK", }, { "time": "2018-10-20T21:37:28-06:00", "properties": { "pageFrom": "X", "pageTo": "Y" }, "type": "NAVIGATE" }] }] action1 = Action(_time='2018-10-18T21:37:28-06:00', _type='CLICK', _properties=ClickProperties(locationX=52, locationY=22)) action2 = Action(_time='2018-10-20T21:37:28-06:00', _type='NAVIGATE', _properties=NavigateProperties(pageFrom='X', pageTo='Y')) log = Log(userId='12345', sessionId='asdfg', actions=[action1, action2]) log.save() result1 = LogService.get_logs('12345', None, None, None) assert result1 is not None assert result1 == answer result2 = LogService.get_logs('asdf', None, None, None) assert result2 is not None assert len(result2) == 0 log.delete()
def get_logs(): userId = request.args.get('userId') from_date = request.args.get('from') to_date = request.args.get('to') types = request.args.get('types') typesList = [] if types is not None: typesList = types.split(',') try: result = LogService.get_logs(userId, from_date, to_date, typesList) except ValueError as e: return {'success': False, 'code': str(e) }, 400 return jsonify(result)
def test_logs_with_a_from_and_to(self): Log.objects().delete() answer1 = [ { "userId": "12345", "sessionId": "asdfg", "actions": [{ "time": "2018-10-17T21:37:28-06:00", "properties": { "locationX": 52, "locationY": 22 }, "type": "CLICK" }] }, { "userId": "ASDFG", "sessionId": "12345", "actions": [{ "time": "2018-10-18T21:37:28-06:00", "properties": { "viewedId": "12345" }, "type": "VIEW" }] }, ] answer2 = [ { "userId": "12345", "sessionId": "asdfg", "actions": [{ "time": "2018-10-19T21:37:28-06:00", "properties": { "pageFrom": 'X', "pageTo": 'Y' }, "type": "NAVIGATE" }] }, { "userId": "ASDFG", "sessionId": "12345", "actions": [{ "time": "2018-10-20T21:37:28-06:00", "properties": { "locationX": 60, "locationY": 30 }, "type": "CLICK" }] }, ] answer3 = [{ "userId": "ASDFG", "sessionId": "12345", "actions": [{ "time": "2018-10-18T21:37:28-06:00", "properties": { "viewedId": "12345", }, "type": "VIEW" }] }] action1 = Action(_time='2018-10-17T21:37:28-06:00', _type='CLICK', _properties=ClickProperties(locationX=52, locationY=22)) action2 = Action(_time='2018-10-19T21:37:28-06:00', _type='NAVIGATE', _properties=NavigateProperties(pageFrom='X', pageTo='Y')) log1 = Log(userId='12345', sessionId='asdfg', actions=[action1, action2]) action3 = Action(_time='2018-10-18T21:37:28-06:00', _type='VIEW', _properties=ViewProperties(viewedId='12345')) action4 = Action(_time='2018-10-20T21:37:28-06:00', _type='CLICK', _properties=ClickProperties(locationX=60, locationY=30)) log2 = Log(userId='ASDFG', sessionId='12345', actions=[action3, action4]) log1.save() log2.save() result1 = LogService.get_logs(None, None, '2018-10-19T00:00:00-06:00', None) assert result1 is not None assert result1 == answer1 result2 = LogService.get_logs(None, '2018-10-19T00:00:00-06:00', None, None) assert result2 is not None assert result2 == answer2 result3 = LogService.get_logs(None, '2018-10-18T00:00:00-06:00', '2018-10-19T00:00:00-06:00', None) assert result3 is not None assert result3 == answer3 log1.delete() log2.delete()
def test_empty_logs(self): Log.objects().delete() result = LogService.get_logs(None, None, None, None) assert len(result) == 0