def test_create_event_attendee(db_handle): event = Event(creator_token="token", title="test event", time=datetime.utcnow(), location="here", identifier="12345678") attendee = User(user_token="token", user_name="user_name", user_identifier="user_identifier") # add the event for the attendee, should back populate to the events attendee.event = event db_handle.session.add(event) db_handle.session.add(attendee) db_handle.session.commit() assert Event.query.first().attendees[0] == attendee # event = Event(creator_token="token", title="test event", time=datetime.utcnow(), location="here") # attendees = [] # for i in range(5): # attendee = User(user_token="token", user_name="user_name_" + str(i) # attendee.event = event # attendees.append(attendee) # # add the event for the attendee, should back populate to the events # # db_handle.session.add(event) # # db_handle.session.add(attendee) # # db_handle.session.commit() # assert Event.query.first().attendees[0] == attendee
def add_event(): if request.method == 'POST': event_data = request.args name = event_data.get('name') date = event_data.get('date') author = event_data.get('author') try: EventToCreate().load(event_data) except ValidationError: abort(400, description="Invalid Group") new_event = Event(name=name, date=date, author=author) db.session.add(new_event) db.session.commit() new_group = Calendar(user_id=author, event_id=new_event.id) db.session.add(new_group) db.session.commit() return jsonify(_id().dump(new_event)) else: abort(405, description="Method Not Allowed")
def save_event_info(session, event_dict): ''' Save a dictionary of event into to the datastore session then return that event instance ''' # Select the current event, filtering on event_url and organization. filter = Event.event_url == event_dict['event_url'], \ Event.organization_name == event_dict['organization_name'] existing_event = session.query(Event).filter(*filter).first() # If this is a new event, save and return it. if not existing_event: new_event = Event(**event_dict) session.add(new_event) return new_event # Mark the existing event for safekeeping. existing_event.keep = True # Update existing event details for (field, value) in event_dict.items(): setattr(existing_event, field, value) # Flush existing object, to prevent a sqlalchemy.orm.exc.StaleDataError. session.flush()
def test_create_event_positive(db_handle): event = Event(creator_token="token", title="test event", time=datetime.utcnow(), location="here", identifier="12345678") db_handle.session.add(event) db_handle.session.commit() assert Event.query.count() == 1
def schedule_afternoon_lyft(go_home_time, facebook_id): event = Event(facebook_id=facebook_id) # Create datetime out of go_to_work_time afternoon_info_card_time = datetime.now() afternoon_info_card_time = afternoon_info_card_time + timedelta(minutes=-30) afternoon_info_card_time = afternoon_info_card_time.replace(hour=go_home_time, minute=0) event.send_timestamp = afternoon_info_card_time event.trigger_enum = 3 db.session.add(event) try: db.session.commit() except IntegrityError: db.session.rollback() return False return True
def test_Event(self): p = Event(Name='Name', Name_house='Name owner', Type='Type', Data='03.02.2021') db.session.add(p) db.session.commit() assert p.Name == 'Name' assert p.Name_house == 'Name owner' assert p.Type == 'Type' assert p.Data == '03.02.2021'
def schedule_morning_info_card(go_to_work_time, facebook_id): event = Event(facebook_id=facebook_id) # Create datetime out of go_to_work_time morning_info_card_time = datetime.now() print 'current_time' print morning_info_card_time.hour morning_info_card_time = morning_info_card_time.replace(hour=go_to_work_time, minute=0) morning_info_card_time = morning_info_card_time + timedelta(hours=-1) event.send_timestamp = morning_info_card_time event.trigger_enum = 1 db.session.add(event) try: db.session.commit() except IntegrityError: db.session.rollback() return False return True
def test_create_full_event_positive(db_handle): event = Event( creator_token="token", creator_name="Creator MacLovin", description="This is a test event :)", title="test event", time=datetime.utcnow(), location="here", identifier="12345678", image= "https://ouluhealth.fi/wp-content/uploads/2019/02/HIMMS_OuluSideEvent2019.jpg" ) db_handle.session.add(event) db_handle.session.commit() assert Event.query.count() == 1
def test_create_event_negative(db_handle): events = [ Event(), Event(creator_token="token", title="test event", time=datetime.utcnow(), location=None), Event(creator_token="token", title="test event", time=None, location="here"), Event(creator_token="token", title=None, time=datetime.utcnow(), location="here"), Event(creator_token=None, title="test event", time=datetime.utcnow(), location="here"), Event( creator_token="token", title="test event", time=datetime.utcnow(), location="here", creator_name= "RI18SnEMQJyoclWJ9siJ9PVY4Xx7ikneZsXy0O8DUPTuwKWqv6Xg4l1bsRfA6SAgV1PogTvtxFuCpsb6" ), Event(creator_token="token", title="test event", time=datetime.utcnow(), location="here", image=True), Event(creator_token="token", title="test event", time=datetime.utcnow(), location="here", description=404) # Event(creator_token="token", title="test event", time=datetime.utcnow(), location="here", ), ] for event in events: with pytest.raises(IntegrityError): db_handle.session.add(event) db_handle.session.commit() db_handle.session.rollback()
def _populate_db(): for i in range(1, 4): event = Event(title="test-event-{}".format(i), time=datetime.utcnow(), location="test-location{}".format(i), creator_token="creator_token{}".format(i), identifier="identifier{}".format(i)) user = User(user_token="token{}".format(i), user_name="user-name{}".format(i), event=event, event_id=event.identifier, user_identifier="user-identifier-{}".format(i)) app.db.session.add(event) app.db.session.add(user) test_events.append(event.as_dict()) test_users.append(user.as_dict()) app.db.session.commit()
def save_event_info(session, event_dict): ''' Save a dictionary of event into to the datastore session then return that event instance ''' # Select the current event, filtering on event_url and organization name. filter = Event.event_url == event_dict['event_url'], \ Event.organization_name == event_dict['organization_name'] existing_event = session.query(Event).filter(*filter).first() # If this is a new event, save and return it. if not existing_event: new_event = Event(**event_dict) session.add(new_event) return new_event # Preserve the existing event. # :::here (event/true) existing_event.keep = True # Update existing event details for (field, value) in event_dict.items(): setattr(existing_event, field, value)
import json from app import Event from app import db from webscrapers import ebrite_scraper num_rows_deleted = db.session.query(Event).delete() db.session.commit() scraped_data = ebrite_scraper.scrape_it() for i in scraped_data: r = Event(name=i['event_name'], link=i['link'], date=i['date'], time=i['time'], image=i['image']) events_by_name_and_date = Event.query.filter_by( name=i['event_name']).filter_by(date=i['date']).all() if len(events_by_name_and_date) == 0: db.session.add(r) db.session.commit()
vals.append(val) if exec % 60 == 0: new_events = [] x = np.asarray(vals) peaks, _ = find_peaks(x, distance=150) troughs, _ = find_peaks(-x, distance=150) for i in peaks: val = x[i] * peak_scaling if val >= baseline_threshold: print(int(val), "added at", datetime.now()) level = Event.query.order_by( Event.id.desc()).first().level + val new_events.append( Event(type="refill", value=val, level=level, units="grams")) for i in troughs: val = x[i] * trough_scaling if val <= -baseline_threshold: print(int(val), "removed at", datetime.now()) level = max( Event.query.order_by(Event.id.desc()).first().level + val, 0) if level > 0: new_events.append( Event(type="eating", value=-val, level=level, units="grams"))
from app import db from app import Event import dateutil.parser db.create_all() date_val = dateutil.parser.isoparse("2021-05-14T09:25:43.511Z") date_val2 = dateutil.parser.isoparse("2021-05-14T09:45:23.511Z") date_val3 = dateutil.parser.isoparse("2021-05-14T11:15:43.511Z") event = Event(type="eating",time = date_val,value = 50, level = 480, units = "grams") event2 = Event(type="refill",time = date_val2,value = 200, level = 680, units = "grams") event3 = Event(type="eating",time = date_val3,value = 100, level = 580, units = "grams") db.session.add(event) db.session.add(event2) db.session.add(event3) db.session.commit()
def main(): db.create_all() ho = Category(title="hobby") ps = Category(title="psychologia") co = Category(title="programowanie") rr = Category(title="związki") lm = Category(title="muzyka") st = Category(title="live stream") ev1 = Event( title="Zarządzanie sobą w kryzysie tożsamości", host_name="prof. Henryk Sienkiewicz", url="https://www.youtube.com/watch?v=J53UK_bul5Y", categories=[ps], planned_start=datetime(2020, 10, 12, 17, 30), estimated_duration=2, description="Lorem ipsum dolor sit amet, consectetur adipisicing \ elit, sed do eiusmod tempor incididunt ut labore et dolore magna \ aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ ullamco laboris nisi ut aliquip ex ea commodo consequat.", ) ev2 = Event( title="Python w terrarium, czyli o wirtualnych środowiskach", host_name="Jakub Wężowy", url="https://www.youtube.com/watch?v=J53UK_bul5Y", categories=[co], planned_start=datetime(2020, 10, 13, 17, 30), estimated_duration=1, description="Lorem ipsum dolor sit amet, consectetur adipisicing \ elit, sed do eiusmod tempor incididunt ut labore et dolore magna \ aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ ullamco laboris nisi ut aliquip ex ea commodo consequat.", ) ev3 = Event( title="Z szydełkowaniem na przeciw COVID-19", host_name="Grażka Szydełkowa", url="https://www.youtube.com/watch?v=J53UK_bul5Y", categories=[ho], planned_start=datetime(2020, 10, 16, 17, 30), estimated_duration=2, description="Lorem ipsum dolor sit amet, consectetur adipisicing \ elit, sed do eiusmod tempor incididunt ut labore et dolore magna \ aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ ullamco laboris nisi ut aliquip ex ea commodo consequat.", ) ev4 = Event( title="Programowanie ludzkiego mózgu z wykorzystaniem pakietu numpy \ i anaconda", host_name="Jakub Wężowy", url="https://www.youtube.com/watch?v=J53UK_bul5Y", categories=[ho, co], planned_start=datetime(2020, 10, 22, 18, 00), estimated_duration=3, description="Lorem ipsum dolor sit amet, consectetur adipisicing \ elit, sed do eiusmod tempor incididunt ut labore et dolore magna \ aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ ullamco laboris nisi ut aliquip ex ea commodo consequat.", ) ev5 = Event( title="Szukanie w stogu siana, czyli miłość w czasie zarazy", host_name="Agnieszka Buchałka", url="https://www.youtube.com/watch?v=J53UK_bul5Y", categories=[rr], planned_start=datetime(2020, 10, 22, 14, 30), estimated_duration=2, description="Lorem ipsum dolor sit amet, consectetur adipisicing \ elit, sed do eiusmod tempor incididunt ut labore et dolore magna \ aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ ullamco laboris nisi ut aliquip ex ea commodo consequat.", ) ev6 = Event( title="PsyTrans TECHNO Party ELO320", host_name="DJ Kolbas", url="https://www.youtube.com/watch?v=J53UK_bul5Y", categories=[lm, st], planned_start=datetime(2020, 10, 30, 20, 00), estimated_duration=5, description="Lorem ipsum dolor sit amet, consectetur adipisicing \ elit, sed do eiusmod tempor incididunt ut labore et dolore magna \ aliqua. Ut enim ad minim veniam, quis nostrud exercitation \ ullamco laboris nisi ut aliquip ex ea commodo consequat.", ) categories = [ "joga", "fitness", "czytanie książek na głos", "terapia grupowa", "zajęcia teatralne", "gotowanie", ] obj_categories = [Category(title=cat) for cat in categories] db.session.add_all([ho, ps, co, ev1, ev2, ev3, ev4, ev5, ev6]) db.session.add_all(obj_categories) db.session.commit() db.session.close()
db.session.commit() page_id[row[u'页面'] + 'web'] = page_web.id page_id[row[u'页面'] + 'ios'] = page_ios.id page_id[row[u'页面'] + 'and'] = page_and.id elif i > 0 and df[sheet].ix[i-1][u'页面'] != row[u'页面']: page_web = Page(appversion.id, row[u'页面'], row['page_key'], 'web') db.session.add(page_web) page_ios = Page(appversion.id, row[u'页面'], row['page_key'], 'ios') db.session.add(page_ios) page_and = Page(appversion.id, row[u'页面'], row['page_key'], 'andriod') db.session.add(page_and) db.session.commit() page_id[row[u'页面'] + 'web'] = page_web.id page_id[row[u'页面'] + 'ios'] = page_ios.id page_id[row[u'页面'] + 'and'] = page_and.id if row['se_category.1'] != '' or row['se_action.1'] != '': event_ios = Event(row[u'事件'], row[u'对象'], page_id[row[u'页面'] + 'ios'], row['type'], row['sub_type'], row['se_category.1'], row['se_action.1'], row[u'额外信息']) db.session.add(event_ios) if row['se_category'] != '' or row['se_action'] != '': event_and = Event(row[u'事件'], row[u'对象'], page_id[row[u'页面'] + 'and'], row['type'], row['sub_type'], row['se_category'], row['se_action'], row[u'额外信息']) db.session.add(event_and) if row['se_category.2'] != '' or row['se_action.2'] != '': event_web = Event(row[u'事件'], row[u'对象'], page_id[row[u'页面'] + 'web'], row['type'], row['sub_type'], row['se_category.2'], row['se_action.2'], row[u'额外信息']) db.session.add(event_web) db.session.commit()
def init_database(test_client): # Create the database and the database table db.create_all() loc1 = Location(title="New-York", code="NY") loc2 = Location(title="Los-Angeles", code="LA") loc3 = Location(title="San-Fransicko", code="SF") loc4 = Location(title="London", code="LO") loc5 = Location(title="Berlin", code="BR") loc6 = Location(title="Paris", code="PR") loc7 = Location(title="Mocsow", code="MSC") loc8 = Location(title="Saint-Petersburg", code="SPB") loc9 = Location(title="Omsk", code="OMG") db.session.add_all( [loc1, loc2, loc3, loc4, loc5, loc6, loc7, loc7, loc8, loc9]) user1 = Participant(name="bob", email="*****@*****.**", location=loc1.code) user2 = Participant(name="bil", email="*****@*****.**", location=loc2.code) user3 = Participant(name="djon", email="*****@*****.**", location=loc3.code) user4 = Participant(name="djek", email="*****@*****.**", location=loc4.code) user5 = Participant(name="max", email="*****@*****.**", location=loc5.code) user6 = Participant(name="elena", email="*****@*****.**", location=loc6.code) user7 = Participant(name="olga", email="*****@*****.**", location=loc7.code) user8 = Participant(name="ruslan", email="*****@*****.**", location=loc8.code) user9 = Participant(name="vova", email="*****@*****.**", location=loc9.code) users = [user1, user2, user3, user4, user5, user6, user7, user8, user9] for user in users: user.about = '' user.picture = '' user.password = '******' evt1 = Event(title="Async or else", description="don't wait for least slow. go in parallel", _type=Event.TypeEnum.LECTURE.value, location=loc1, address="ball street, 34", seats=0, _category=Event.CategoryEnum.PYTHON.value) evt2 = Event(title="Monkey testing and it's perspective", description="why you want reliable test?", _type=Event.TypeEnum.LECTURE.value, location=loc2, address="bay of bug, 41", seats=134, _category=Event.CategoryEnum.PROJECT_MANAGMENT.value) evt3 = Event( title="Making a word a better place throuth a inspiring speeches", description="don't wait for least slow. go in parallel", _type=Event.TypeEnum.INSPIRING_BULLSHIT.value, location=loc3, address="ball street, 34", seats=28, _category=Event.CategoryEnum.PROJECT_MANAGMENT.value) evt4 = Event(title="prolog and you", description="have you some basic logic? let's check", _type=Event.TypeEnum.HACKATON.value, location=loc4, address="irvish street, 63", seats=12, _category=Event.CategoryEnum.ESOLANG.value) enr1 = Enrollment(event=evt1, participant=user3) enr2 = Enrollment(event=evt1, participant=user3) enr3 = Enrollment(event=evt2, participant=user3) enr4 = Enrollment(event=evt2, participant=user1) enr5 = Enrollment(event=evt4, participant=user6) enr6 = Enrollment(event=evt3, participant=user2) db.session.add_all([evt1, evt2, evt3, evt4]) db.session.add_all(users) # Commit the changes for the users db.session.commit() yield db # this is where the testing happens! Enrollment.query.delete() Event.query.delete() Participant.query.delete() Location.query.delete() db.session.commit()