def test_location_columns(db_handle): """ Tests the types and restrictions of location columns. Checks that numerical values only accepts numbers, and that all of the columns are optional. """ location = _get_location() location.latitude = str(location.latitude) + "°" db_handle.session.add(location) with pytest.raises(StatementError): db_handle.session.commit() db_handle.session.rollback() location = _get_location() location.longitude = str(location.longitude) + "°" db_handle.session.add(location) with pytest.raises(StatementError): db_handle.session.commit() db_handle.session.rollback() location = _get_location() location.altitude = str(location.altitude) + "m" db_handle.session.add(location) with pytest.raises(StatementError): db_handle.session.commit() db_handle.session.rollback() location = Location() db_handle.session.add(location) db_handle.session.commit()
def admin_add_location(): if request.method == 'GET': return render_template('location_form.html', location=None) intro_sound = request.files['intro'] if intro_sound.filename != '' and request.form['name'] != '': location = Location(name=request.form['name'], longitude=request.form['longitude'], latitude=request.form['latitude']) db.session.add(location) db.session.commit() newpath = 'app/static/audio/' + str(location.location_id) if not os.path.exists(newpath): os.makedirs(newpath) intro_sound.save( os.path.join(newpath, 'intro_' + str(location.location_id) + '.mp3')) return redirect('/admin/locations')
def load_locations(): with open(OFFICE_MAPPING_PATH, 'r') as office_mapping: data = json.loads(office_mapping.read()) for room_name in data.keys(): db.session.add(Location(room_name)) 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()
CSV contains one row per *location* (despite name of 'users.csv'); create one user by de-duplicating on user_id, and one location per row. """ import csv from app import db, User, Location db.create_all() # keep track of users added, so we skip adding second time user_ids = set() with open("challenge/users.csv") as f: for row in csv.DictReader(f): if row['user_id'] not in user_ids: user = User(id=row['user_id'], name=row['user_name'], age=row['user_age'], gender=row['user_gender']) db.session.add(user) user_ids.add(row['user_id']) location = Location(user_id=row['user_id'], name=row['last_location'], location=db.func.ll_to_earth( row['lat'], row['long'])) db.session.add(location) db.session.commit()
from app import db, Location, Transmitter l = Location('Lions Gate Garden', '55.9340812', '-3.211218217') t1 = Transmitter('00:A0:50:12:27:0F', 'lions_gate_intro.mp3', 'lions_gate_intro.mp3', 1) t2 = Transmitter('00:A0:50:12:1A:12', 'lions_gate_guilds.mp3', 'lions_gate_guilds.mp3', 1) db.session.add(l) db.session.add(t1) db.session.add(t2) db.session.commit()
from app import db, Venue, Show, Artist, Location, format_datetime location1 = Location(city="San Francisco", state="CA") location2 = Location(city="New York", state="NY") db.session.add(location1) db.session.add(location2) # Add venues venue1 = Venue( name="The Musical Hop", location_id=1, phone="123-123-1234", image_link= "https://images.unsplash.com/photo-1543900694-133f37abaaa5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60", facebook_link="https://www.facebook.com/TheMusicalHop", address="1015 Folsom Street", website="https://www.themusicalhop.com", seeking_talent=True, seeking_description= "We are on the lookout for a local artist to play every two weeks. Please call us." ) venue2 = Venue( name="The Dueling Pianos Bar", location_id=2, phone="914-003-1132", image_link= "https://images.unsplash.com/photo-1497032205916-ac775f0649ae?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80", facebook_link="https://www.facebook.com/theduelingpianos",
def _get_location(sitename="alpha"): return Location(latitude=63.3, longitude=22.6, altitude=24.5, description="test site {}".format(sitename))