def get_entry_exit_pairs(user_id, ridList, num=100): events = [] start = base for _ in range(num): room_id = ridList[random.randint(0, len(ridList)-1)] start = gen_datetime(start) if(start >= datetime.now()): break end = gen_datetime(start) events.append(Event(user_id, room_id, 1, start)) events.append(Event(user_id, room_id, 0, end)) start = end return events
def __init__(self, monitor_name, alert_type, alert_name, alert_details, alert_duration, timestamp=None): Event.__init__(self, monitor_name, alert_type, alert_name, alert_details, alert_duration, timestamp=timestamp)
def test_to_json_down(down): assert json.loads(proxy.event_to_json(Event.create_event(down))) == { "u_business_service": E2EMONITORING_SERVICE, "u_priority": E2EMONITORING_DOWN, "u_short_description": "unittest is Down", "u_description": "unittest is Down: for testing purpose.", }
def create(self, event): if not isinstance(event, Event): event = Event.create_event(event) db_event = DBEvent.from_event(event) self.db.session.add(db_event) self.db.session.commit() return db_event
def test_to_json_up(up): assert json.loads(proxy.event_to_json(Event.create_event(up))) == { "u_business_service": E2EMONITORING_SERVICE, "u_priority": E2EMONITORING_UP, "u_short_description": "unittest is Up", "u_description": "unittest is Up (for testing purpose). It was down for 0:01:39.", }
def demo_entities(): """Simple test code to demonstrate using the entity classes. Output is to console. """ TIMED = True SCORED = False print("Demonstrate creating country objects:") CAN = Country("Canada", "CAN") AUS = Country("Australia", "AUS") all_countries.add_item(CAN.get_country_code(), CAN) all_countries.add_item(AUS.get_country_code(), AUS) for country in all_countries.get_items(): print(country) print("\nDemonstrate creating athlete objects, adding them to", "all_athletes and countries:") a1 = Athlete("1", "Athlete", "One", CAN) a2 = Athlete("2", "Athlete", "Two", CAN) a3 = Athlete("10", "Athlete", "Three", CAN) a4 = Athlete("4", "Athlete", "Four", AUS) a5 = Athlete("5", "Athlete", "Five", AUS) a6 = Athlete("20", "Athlete", "Six", AUS) for athlete in [a1, a2, a3, a4, a5, a6]: all_athletes.add_item(athlete.get_id(), athlete) athletes = all_athletes.get_items() for athlete in athletes: print(athlete) CAN.add_athletes([a1, a2, a3]) AUS.add_athletes([a4, a5, a6]) print("\nDemonstrate finding an athlete in all_athletes:") print(all_athletes.find_item("2")) # Create event objects and add athletes to the events. e1 = Event("Event1", TIMED, [a1, a2, a3, a4, a5]) all_events.add_item(e1.get_name(), e1) a2.add_event(e1) a3.add_event(e1) a4.add_event(e1) a5.add_event(e1) e2 = Event("Event2", SCORED, [a1, a2, a3, a5, a6]) all_events.add_item(e2.get_name(), e2) a2.add_event(e2) a3.add_event(e2) a5.add_event(e2) a6.add_event(e2) a1.add_events([e1, e2]) # Create result objects for each athlete in the events. a1.add_result(e1, Result(10.5)) a2.add_result(e1, Result(9.5)) a3.add_result(e1, Result(11.5)) a4.add_result(e1, Result(8.5)) a5.add_result(e1, Result(12.5)) a1.add_result(e2, Result(100.5)) a2.add_result(e2, Result(99.5)) a3.add_result(e2, Result(98.5)) a5.add_result(e2, Result(90.5)) a6.add_result(e2, Result(89.5))
def __repr__(self): return Event.__repr__(self)
def getEventObject(event): return Event(event['user_id'], event['room_id'], event['status'], event['timestamp'])
def test_store_select(up): assert list(storage.select()) == [] event = Event.create_event(up) storage.create(event) assert list(storage.select()) == [event] storage.flush(0)
def test_store_create(up, down): storage.create(Event.create_event(down)) storage.create(up) assert repr(storage) == '<Store with 2 events>' assert len(storage) == 2
def test_create_down(down): event = Event.create_event(down) assert event.alert_type == 1 assert event.alert_name == 'Down' assert event.alert_duration == 0 assert event.monitor_name == 'unittest'
def test_create_up(up): event = Event.create_event(up) assert event.alert_type == 2 assert event.alert_name == 'Up' assert event.alert_duration == 99 assert event.monitor_name == 'unittest'
def test_format(down): assert repr( Event.create_event(down) ) == "<Event for unittest: Down(1) since 0:00:00, for testing purpose>"