def department_with_ranks(department, session): for order, rank in enumerate(RANK_CHOICES_1): session.add( models.Job(job_title=rank, order=order, is_sworn_officer=True, department=department)) session.commit() return department
def add_mockdata(session): NUM_OFFICERS = current_app.config['NUM_OFFICERS'] department = models.Department( name='Springfield Police Department', short_name='SPD', unique_internal_identifier_label='homer_number') session.add(department) department2 = models.Department(name='Chicago Police Department', short_name='CPD') session.add(department2) session.commit() i = 0 for rank in RANK_CHOICES_1: session.add( models.Job(job_title=rank, order=i, is_sworn_officer=True, department_id=1)) i += 1 i = 0 for rank in RANK_CHOICES_2: session.add( models.Job(job_title=rank, order=i, is_sworn_officer=True, department_id=2)) i += 1 session.commit() # Ensure test data is deterministic SEED = current_app.config['SEED'] random.seed(SEED) test_units = [ models.Unit(descrip="test", department_id=1), models.Unit(descrip='District 13', department_id=1), models.Unit(descrip='Donut Devourers', department_id=1), models.Unit(descrip='Bureau of Organized Crime', department_id=2), models.Unit(descrip='Porky\'s BBQ: Rub Division', department_id=2) ] session.add_all(test_units) session.commit() test_images = [models.Image(filepath='/static/images/test_cop{}.png'.format(x + 1), department_id=1) for x in range(5)] + \ [models.Image(filepath='/static/images/test_cop{}.png'.format(x + 1), department_id=2) for x in range(5)] officers = [generate_officer() for o in range(NUM_OFFICERS)] session.add_all(officers) session.add_all(test_images) session.commit() all_officers = models.Officer.query.all() officers_dept1 = models.Officer.query.filter_by(department_id=1).all() officers_dept2 = models.Officer.query.filter_by(department_id=2).all() # assures that there are some assigned and unassigned images in each department assigned_images_dept1 = models.Image.query.filter_by( department_id=1).limit(3).all() assigned_images_dept2 = models.Image.query.filter_by( department_id=2).limit(2).all() jobs_dept1 = models.Job.query.filter_by(department_id=1).all() jobs_dept2 = models.Job.query.filter_by(department_id=2).all() assignments_dept1 = [ build_assignment(officer, test_units, jobs_dept1) for officer in officers_dept1 ] assignments_dept2 = [ build_assignment(officer, test_units, jobs_dept2) for officer in officers_dept2 ] salaries = [build_salary(officer) for officer in all_officers] faces_dept1 = [ assign_faces(officer, assigned_images_dept1) for officer in officers_dept1 ] faces_dept2 = [ assign_faces(officer, assigned_images_dept2) for officer in officers_dept2 ] faces1 = [f for f in faces_dept1 if f] faces2 = [f for f in faces_dept2 if f] session.commit() session.add_all(assignments_dept1) session.add_all(assignments_dept2) session.add_all(salaries) session.add_all(faces1) session.add_all(faces2) test_user = models.User(email='*****@*****.**', username='******', password='******', confirmed=True) session.add(test_user) test_admin = models.User(email='*****@*****.**', username='******', password='******', confirmed=True, is_administrator=True) session.add(test_admin) test_area_coordinator = models.User(email='*****@*****.**', username='******', password='******', confirmed=True, is_area_coordinator=True, ac_department_id=AC_DEPT) session.add(test_area_coordinator) test_unconfirmed_user = models.User(email='*****@*****.**', username='******', password='******', confirmed=False) session.add(test_unconfirmed_user) session.commit() test_addresses = [ models.Location(street_name='Test St', cross_street1='Cross St', cross_street2='2nd St', city='My City', state='AZ', zip_code='23456'), models.Location(street_name='Testing St', cross_street1='First St', cross_street2='Fourth St', city='Another City', state='ME', zip_code='23456') ] session.add_all(test_addresses) session.commit() test_license_plates = [ models.LicensePlate(number='603EEE', state='MA'), models.LicensePlate(number='404301', state='WA') ] session.add_all(test_license_plates) session.commit() test_links = [ models.Link(url='https://stackoverflow.com/', link_type='link', user=test_admin, user_id=test_admin.id), models.Link(url='http://www.youtube.com/?v=help', link_type='video', user=test_admin, user_id=test_admin.id) ] session.add_all(test_links) session.commit() test_incidents = [ models.Incident(date=datetime.date(2016, 3, 16), time=datetime.time(4, 20), report_number='42', description='A thing happened', department_id=1, address=test_addresses[0], license_plates=test_license_plates, links=test_links, officers=[all_officers[o] for o in range(4)], creator_id=1, last_updated_id=1), models.Incident(date=datetime.date(2017, 12, 11), time=datetime.time(2, 40), report_number='38', description='A thing happened', department_id=2, address=test_addresses[1], license_plates=[test_license_plates[0]], links=test_links, officers=[all_officers[o] for o in range(3)], creator_id=2, last_updated_id=1), models.Incident( date=datetime.datetime(2019, 1, 15), report_number='39', description= 'A test description that has over 300 chars. The purpose is to see how to display a larger descrption. Descriptions can get lengthy. So lengthy. It is a description with a lot to say. Descriptions can get lengthy. So lengthy. It is a description with a lot to say. Descriptions can get lengthy. So lengthy. It is a description with a lot to say. Lengthy lengthy lengthy.', department_id=2, address=test_addresses[1], license_plates=[test_license_plates[0]], links=test_links, officers=[all_officers[o] for o in range(1)], creator_id=2, last_updated_id=1), ] session.add_all(test_incidents) session.commit() users_that_can_create_notes = [test_admin, test_area_coordinator] # for testing routes first_officer = models.Officer.query.get(1) note = build_note(first_officer, test_admin) session.add(note) for officer in models.Officer.query.limit(20): user = random.choice(users_that_can_create_notes) note = build_note(officer, user) session.add(note) session.commit() users_that_can_create_descriptions = [test_admin, test_area_coordinator] # for testing routes first_officer = models.Officer.query.get(1) description = build_description(first_officer, test_admin) session.add(description) for officer in models.Officer.query.limit(20): user = random.choice(users_that_can_create_descriptions) description = build_description(officer, user) session.add(description) session.commit() return assignments_dept1[0].star_no