def test_users_equal_fail_success(): from travel_plan.user.users import User name = 'Bob' email = '*****@*****.**' work = '555-123-4567' home = '555-223-4567' cell = '555-323-4567' department = 'Wilderness' active = False user1 = User(name, email, work, home, cell, department, active) user2 = User('Bob2', email, work, home, cell, department, active) assert user1 != user2
def main(): create_app() from travel_plan import db from travel_plan.car.cars import Car from travel_plan.color.colors import Color from travel_plan.department.departments import Department from travel_plan.location.locations import Location from travel_plan.user.users import User for n in conftest._departments: db.session.add(Department(**n)) for n in conftest._cars: db.session.add(Car(**n)) for n in conftest._users: db.session.add(User(**n)) for n in conftest._locations: db.session.add(Location(**n)) for n in conftest._colors: if not db.session.query(Color).filter(Color.name == n).all(): db.session.add(Color(n)) db.session.commit() db.session.commit()
def initialized_users(users): from travel_plan.user.users import User users = [User(**u) for u in users] for i, u in enumerate(users): u.id = i + 1 yield users
def entry_post(): vm = TravelEntryViewModel() vm.validate() if vm.error: return vm.to_dict() vm.convert_empty_strings_to_none() travel_user_units = [ TravelUserUnit(**t) for t in vm.travelers if t['traveler_name'] ] day_plans = [TravelDay(**pd) for pd in vm.day_plans if pd['date']] emergency_contacts = [ User(u['contact_name'], u['contact_email'], u['contact_work'], u['contact_home'], u['contact_cell'], None, None) for u in vm.contacts ] base_name = file_util.generate_name(vm.trip_leader_name, vm.start_date) travel_files = [ TravelFile(f) for f in file_util.save_files_with_name( vm.uploaded_files, base_name, current_app.config['PDF_FOLDER_PATH']) ] travel_files.append(TravelFile(base_name + '.pdf')) travel_id = travel_services.create_plan( vm.start_date, vm.entry_point, vm.end_date, vm.exit_point, vm.tracked, vm.plb, vm.trip_leader_name, travel_user_units, day_plans, vm.car_plate, vm.car_make, vm.car_model, vm.car_color, vm.car_location, vm.bivy_gear, vm.compass, vm.first_aid_kit, vm.flagging, vm.flare, vm.flashlight, vm.gps, vm.head_lamp, vm.helmet, vm.ice_axe, vm.map, vm.matches, vm.probe_pole, vm.radio, vm.rope, vm.shovel, vm.signal_mirror, vm.space_blanket, vm.spare_battery, vm.tent, vm.whistle, vm.days_of_food, vm.weapon, vm.radio_monitor_time, vm.off_trail_travel, vm.cell_number, vm.satellite_number, emergency_contacts, vm.gar_avg, vm.mitigated_gar, vm.gar_mitigations, vm.notes, travel_files) travel = travel_services.get_travel_from_id(travel_id) pdf_util.make_and_save_pdf(travel, base_name, current_app.config['PDF_FOLDER_PATH']) email_util.email_travel(travel, [f.name for f in travel_files], current_app.config['PDF_FOLDER_PATH']) return redirect(url_for('travel.email_sent'))
def _verify_contact(contact: User) -> User: existing_contact = user_services.get_user_from_name(contact.name) if not existing_contact: contact.active = False return user_services.create_user(user=contact) if existing_contact.work_number != contact.work_number or existing_contact.home_number != contact.home_number or \ existing_contact.cell_number != contact.cell_number or existing_contact.email != contact.email: return user_services.update_user(existing_contact.id, existing_contact.active, email=contact.email, work_number=contact.work_number, home_number=contact.home_number, cell_number=contact.cell_number) return existing_contact
def app_w_db(app_w_empty_db): # with app_w_empty_db.app_context(): from travel_plan import db from travel_plan.car.cars import Car from travel_plan.color.colors import Color from travel_plan.department.departments import Department from travel_plan.location.locations import Location from travel_plan.user.users import User [db.session.add(Department(**d)) for d in _departments] [db.session.add(Color(c)) for c in _colors] [db.session.add(Car(**c)) for c in _cars] [db.session.add(Location(**loc)) for loc in _locations] [db.session.add(User(**u)) for u in _users] db.session.commit() yield app_w_empty_db
def create_user(name: str = '', email: str = None, work_number: str = None, home_number: str = None, cell_number: str = None, department: str = None, active: bool = None, user: User = None) -> Optional[User]: if not user: user = User(name, email, work_number, home_number, cell_number, department, active) try: db.session.add(user) db.session.commit() return user except Exception as e: return None
def _make_travels(_travels): """ convert a list of dicts to a list of TravelUserUnits and a list of dicts into a list of TravelDays This gets around an issue with import order stuff. :return: """ from travel_plan.travel.travel_user_units import TravelUserUnit from travel_plan.travel.travel_days import TravelDay from travel_plan.user.users import User from travel_plan.travel.travel_file import TravelFile travel = copy.deepcopy(_travels) for t in travel: t['traveler_units'] = [TravelUserUnit(*u) for u in t['traveler_units']] t['day_plans'] = [TravelDay(**d) for d in t['day_plans']] t['contacts'] = [User(**u) for u in t['contacts']] t['files'] = [TravelFile(**f) for f in t['files']] return travel