def GET(self): web.header('Content-Type', 'application/json') try: i = web.input(eventTypeId=None, entityIds=None, end=None) applicationId = int(i.applicationId) start = long(i.start) end = i.end if end is not None: end = long(end) eventTypeId = i.eventTypeId if eventTypeId is not None: eventTypeId = long(eventTypeId) entityIds = i.entityIds if entityIds is not None: entityIds = json.loads(entityIds) eventList = Event.load_from_db(_db, applicationId=applicationId, start=start, end=end, eventTypeId=eventTypeId, entityIds=entityIds) eventJson = [evt.to_dict() for evt in eventList] j = {'status' : 'ok', 'events' : eventJson} return json.dumps(j) except Exception as e: err_json = {'status' : 'error', 'message' : str(e)} raise web.badrequest(json.dumps(err_json))
def test_entity_query_1(self): with nostderr(): events = Event.load_from_db( self.db, applicationId=1, start=5, entityIds={'1' : [14, 15]} ) self.assertEqual(3, len(events))
def test_cutoff_query_1(self): with nostderr(): events = Event.load_from_db( self.db, applicationId=1, start=15, end=35 ) self.assertEqual(4, len(events))
def test_query_on_empty_db(self): self.clear() with nostderr(): events = Event.load_from_db(self.db, applicationId=1, start=0) self.assertEqual(len(events), 0)
def test_app_query(self): with nostderr(): events = Event.load_from_db(self.db, applicationId=1, start=0) self.assertEqual(8, len(events))