コード例 #1
0
def populate():
    """ Populate database with test data"""

    # Add images from Springfield Police Department
    image1 = models.Image(filepath='static/images/test_cop1.png')
    image2 = models.Image(filepath='static/images/test_cop2.png')
    image3 = models.Image(filepath='static/images/test_cop3.png')
    image4 = models.Image(filepath='static/images/test_cop4.png')
    image5 = models.Image(filepath='static/images/test_cop5.jpg')

    test_images = [image1, image2, image3, image4, image5]
    db.session.add_all(test_images)
    db.session.commit()

    officers = [generate_officer() for o in range(NUM_OFFICERS)]
    db.session.add_all(officers)
    db.session.commit()

    assignments = [build_assignment(officer) for officer in officers]
    db.session.add_all(assignments)
    db.session.commit()

    faces = [assign_faces(officer, test_images) for officer in officers]
    faces = [f for f in faces if f]

    db.session.add_all(faces)
    db.session.commit()
コード例 #2
0
ファイル: test_data.py プロジェクト: ejfox/OpenOversight
def populate():
    """ Populate database with test data"""

    departments = models.Department.query.all()
    if len(departments) > 0:
        print('Test data already inserted, skipping...')
        sys.exit(0)

    department1 = models.Department(name='Springfield Police Department',
                                    short_name='SPD')
    db.session.add(department1)
    department2 = models.Department(name='Gotham Police Department',
                                    short_name='GPD')
    db.session.add(department2)
    db.session.commit()

    # Add images from Springfield Police Department
    image1 = models.Image(filepath='/static/images/test_cop1.png',
                          department_id=department1.id)
    image2 = models.Image(filepath='/static/images/test_cop2.png',
                          department_id=department1.id)
    image3 = models.Image(filepath='/static/images/test_cop3.png',
                          department_id=department2.id)
    image4 = models.Image(filepath='/static/images/test_cop4.png',
                          department_id=department2.id)
    image5 = models.Image(filepath='/static/images/test_cop5.jpg',
                          department_id=department2.id)

    test_images = [image1, image2, image3, image4, image5]
    db.session.add_all(test_images)
    db.session.commit()

    officers = [generate_officer() for o in range(NUM_OFFICERS)]
    db.session.add_all(officers)
    db.session.commit()

    assignments = [build_assignment(officer) for officer in officers]
    db.session.add_all(assignments)
    db.session.commit()

    faces = [assign_faces(officer, test_images) for officer in officers]
    faces = [f for f in faces if f]

    db.session.add_all(faces)
    db.session.commit()

    test_user = models.User(email='*****@*****.**',
                            username='******',
                            password='******',
                            is_administrator=True,
                            confirmed=True)
    db.session.add(test_user)
    db.session.commit()

    test_units = [models.Unit(descrip='District 13', department_id=1),
                  models.Unit(descrip='Bureau of Organized Crime', department_id=1)]
    db.session.add_all(test_units)
    db.session.commit()
コード例 #3
0
def populate():
    """ Populate database with test data"""

    # Add images from Springfield Police Department
    image1 = models.Image(filepath='static/images/test_cop1.png')
    image2 = models.Image(filepath='static/images/test_cop2.png')
    image3 = models.Image(filepath='static/images/test_cop3.png')
    image4 = models.Image(filepath='static/images/test_cop4.png')
    image5 = models.Image(filepath='static/images/test_cop5.jpg')

    test_images = [image1, image2, image3, image4, image5]
    db.session.add_all(test_images)
    db.session.commit()

    officers = [generate_officer() for o in range(NUM_OFFICERS)]
    db.session.add_all(officers)
    db.session.commit()

    assignments = [build_assignment(officer) for officer in officers]
    db.session.add_all(assignments)
    db.session.commit()

    faces = [assign_faces(officer, test_images) for officer in officers]
    faces = [f for f in faces if f]

    db.session.add_all(faces)
    db.session.commit()

    test_user = models.User(email='*****@*****.**',
                            username='******',
                            password='******',
                            confirmed=True)
    db.session.add(test_user)
    db.session.commit()

    test_units = [
        models.Unit(descrip='District 13'),
        models.Unit(descrip='Bureau of Organized Crime')
    ]
    db.session.add_all(test_units)
    db.session.commit()
コード例 #4
0
ファイル: conftest.py プロジェクト: Te-k/OpenOversight
def mockdata(session, request):
    NUM_OFFICERS = current_app.config['NUM_OFFICERS']
    SEED = current_app.config['SEED']
    random.seed(SEED)

    image1 = models.Image(filepath='static/images/test_cop1.png')
    image2 = models.Image(filepath='static/images/test_cop2.png')
    image3 = models.Image(filepath='static/images/test_cop3.png')
    image4 = models.Image(filepath='static/images/test_cop4.png')

    unit1 = models.Unit(descrip="test")

    test_images = [image1, image2, image3, image4]
    officers = [generate_officer() for o in range(NUM_OFFICERS)]
    assignments = [build_assignment(officer, unit1) for officer in officers]
    faces = [assign_faces(officer, test_images) for officer in officers]
    faces = [f for f in faces if f]
    session.add_all(test_images)
    session.add(unit1)
    session.add_all(officers)
    session.add_all(assignments)
    session.add_all(faces)
    session.commit()
    return assignments[0].star_no
コード例 #5
0
ファイル: conftest.py プロジェクト: parhamr/OpenOversight
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
コード例 #6
0
ファイル: conftest.py プロジェクト: romainr88/OpenOversight
def mockdata(session, request):
    NUM_OFFICERS = current_app.config['NUM_OFFICERS']
    department = models.Department(name='Springfield Police Department',
                                   short_name='SPD')
    session.add(department)
    department2 = models.Department(name='Chicago Police Department',
                                    short_name='CPD')
    session.add(department2)
    session.commit()

    # Ensure test data is deterministic
    SEED = current_app.config['SEED']
    random.seed(SEED)

    image1 = models.Image(filepath='static/images/test_cop1.png',
                          department_id=1)
    image2 = models.Image(filepath='static/images/test_cop2.png',
                          department_id=1)
    image3 = models.Image(filepath='static/images/test_cop3.png',
                          department_id=1)
    image4 = models.Image(filepath='static/images/test_cop4.png',
                          department_id=1)

    unit1 = models.Unit(descrip="test")

    test_images = [image1, image2, image3, image4]
    officers = [generate_officer() for o in range(NUM_OFFICERS)]
    session.add_all(officers)
    session.add_all(test_images)
    session.commit()

    officers = models.Officer.query.all()
    test_images = models.Image.query.all()

    assignments = [build_assignment(officer, unit1) for officer in officers]
    faces = [assign_faces(officer, test_images) for officer in officers]
    faces = [f for f in faces if f]
    session.add(unit1)
    session.add_all(assignments)
    session.add_all(faces)

    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_unconfirmed_user = models.User(email='*****@*****.**',
                                        username='******',
                                        password='******', confirmed=False)
    session.add(test_unconfirmed_user)
    session.commit()

    test_units = [models.Unit(descrip='District 13', department_id=1),
                  models.Unit(descrip='Bureau of Organized Crime',
                              department_id=1)]
    session.add_all(test_units)
    session.commit()

    def teardown():
        # Cleanup tables
        models.User.query.delete()
        models.Officer.query.delete()
        models.Image.query.delete()
        models.Face.query.delete()
        models.Unit.query.delete()
        models.Department.query.delete()
        session.commit()
        session.flush()

    return assignments[0].star_no
コード例 #7
0
ファイル: conftest.py プロジェクト: jrabbit/OpenOversight
def mockdata(session, request):
    NUM_OFFICERS = current_app.config['NUM_OFFICERS']
    department = models.Department(name='Springfield Police Department',
                                   short_name='SPD')
    session.add(department)
    department2 = models.Department(name='Chicago Police Department',
                                    short_name='CPD')
    session.add(department2)
    session.commit()

    # Ensure test data is deterministic
    SEED = current_app.config['SEED']
    random.seed(SEED)

    unit1 = models.Unit(descrip="test")

    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()

    assignments = [build_assignment(officer, unit1) 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.add(unit1)
    session.add_all(assignments)
    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_units = [models.Unit(descrip='District 13', department_id=1),
                  models.Unit(descrip='Bureau of Organized Crime',
                              department_id=1)]
    session.add_all(test_units)
    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'),
        models.Link(url='http://www.youtube.com/?v=help', link_type='video')
    ]

    session.add_all(test_links)
    session.commit()

    test_incidents = [
        models.Incident(
            date=datetime(2016, 3, 16),
            report_number='42',
            description='A thing happened',
            department_id=1,
            address=test_addresses[0],
            license_plates=test_license_plates,
            links=test_links,
            officers=[generate_officer() for o in range(4)],
            creator_id=1,
            last_updated_id=1
        ),
        models.Incident(
            date=datetime(2017, 12, 11),
            report_number='38',
            description='A thing happened',
            department_id=2,
            address=test_addresses[1],
            license_plates=[test_license_plates[0]],
            links=test_links,
            officers=[generate_officer() for o in range(3)],
            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()

    def teardown():
        # Cleanup tables
        models.User.query.delete()
        models.Officer.query.delete()
        models.Image.query.delete()
        models.Face.query.delete()
        models.Unit.query.delete()
        models.Department.query.delete()
        session.commit()
        session.flush()

    return assignments[0].star_no
コード例 #8
0
def mockdata(session, request):
    NUM_OFFICERS = current_app.config['NUM_OFFICERS']
    department = models.Department(name='Springfield Police Department',
                                   short_name='SPD')
    session.add(department)
    department2 = models.Department(name='Chicago Police Department',
                                    short_name='CPD')
    session.add(department2)
    session.commit()

    # Ensure test data is deterministic
    SEED = current_app.config['SEED']
    random.seed(SEED)

    unit1 = models.Unit(descrip="test")

    test_images = [models.Image(filepath='static/images/test_cop{}.png'.format(x), department_id=1) for x in range(5)] + \
        [models.Image(filepath='static/images/test_cop{}.png'.format(x), 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()

    assignments = [build_assignment(officer, unit1) 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.add(unit1)
    session.add_all(assignments)
    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_units = [models.Unit(descrip='District 13', department_id=1),
                  models.Unit(descrip='Bureau of Organized Crime',
                              department_id=1)]
    session.add_all(test_units)
    session.commit()

    def teardown():
        # Cleanup tables
        models.User.query.delete()
        models.Officer.query.delete()
        models.Image.query.delete()
        models.Face.query.delete()
        models.Unit.query.delete()
        models.Department.query.delete()
        session.commit()
        session.flush()

    return assignments[0].star_no