Пример #1
0
def test_admin_can_add_new_officer_with_suffix(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        links = [
            LinkForm(url='http://www.pleasework.com', link_type='link').data,
            LinkForm(url='http://www.avideo/?v=2345jk', link_type='video').data
        ]
        form = AddOfficerForm(first_name='Testy',
                              last_name='McTesty',
                              middle_initial='T',
                              suffix='Jr',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              links=links)

        data = process_form_data(form.data)

        rv = client.post(url_for('main.add_officer'),
                         data=data,
                         follow_redirects=True)

        assert 'New Officer McTesty added' in rv.data.decode('utf-8')

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='McTesty').one()
        assert officer.first_name == 'Testy'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
        assert officer.suffix == 'Jr'
Пример #2
0
def test_admin_adds_officer_with_letter_in_badge_no(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        department = random.choice(dept_choices())
        form = AddOfficerForm(first_name='Test',
                              last_name='Testersly',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no='T666',
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990)
        data = process_form_data(form.data)

        rv = client.post(url_for('main.add_officer'),
                         data=data,
                         follow_redirects=True)

        assert 'New Officer Testersly added' in rv.data.decode('utf-8')

        # Check the officer was added to the database
        officer = Officer.query.filter_by(last_name='Testersly').one()
        assert officer.first_name == 'Test'
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
        assert officer.assignments[0].star_no == 'T666'
def test_admin_adds_officer_without_middle_initial(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        department = random.choice(dept_choices())
        form = AddOfficerForm(first_name='Test',
                              last_name='McTesty',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              # because of encoding error, link_type must be set for tests
                              links=[LinkForm(link_type='link').data])
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.add_officer'),
            data=data,
            follow_redirects=True
        )

        assert 'McTesty' in rv.data

        # Check the officer was added to the database
        officer = Officer.query.filter_by(
            last_name='McTesty').one()
        assert officer.first_name == 'Test'
        assert officer.middle_initial == ''
        assert officer.race == 'WHITE'
        assert officer.gender == 'M'
def test_officer_csv(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        links = [
            LinkForm(url='http://www.pleasework.com', link_type='link').data,
        ]
        form = AddOfficerForm(first_name='CKtVwe2gqhAIc',
                              last_name='FVkcjigWUeUyA',
                              middle_initial='T',
                              suffix='Jr',
                              race='WHITE',
                              gender='M',
                              star_no=90009,
                              rank='PO',
                              department=department.id,
                              birth_year=1910,
                              links=links)
        # add the officer
        rv = client.post(
            url_for('main.add_officer'),
            data=process_form_data(form.data),
            follow_redirects=True
        )
        # dump officer csv
        rv = client.get(
            url_for('main.download_dept_csv', department_id=department.id),
            follow_redirects=True
        )
        # get csv entry matching officer last n"createdame
        csv = list(filter(lambda row: form.last_name.data in row, rv.data.decode('utf-8').split("\n")))
        assert len(csv) == 1
        assert form.first_name.data in csv[0]
        assert form.last_name.data in csv[0]
        assert form.rank.data in csv[0]
def test_admin_can_edit_existing_officer(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())
        link_url0 = 'http://pleasework.com'
        link_url1 = 'http://avideo/?v=2345jk'
        links = [
            LinkForm(url=link_url0, link_type='link').data,
            LinkForm(url=link_url0, link_type='video').data
        ]
        form = AddOfficerForm(first_name='Test',
                              last_name='Testerinski',
                              middle_initial='T',
                              race='WHITE',
                              gender='M',
                              star_no=666,
                              rank='COMMANDER',
                              department=department.id,
                              birth_year=1990,
                              links=links)
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.add_officer'),
            data=data,
            follow_redirects=True
        )

        officer = Officer.query.filter_by(
            last_name='Testerinski').one()

        form = EditOfficerForm(last_name='Changed', links=links[:1])
        data = process_form_data(form.data)

        rv = client.post(
            url_for('main.edit_officer', officer_id=officer.id),
            data=data,
            follow_redirects=True
        )

        assert 'Changed' in rv.data
        assert 'Testerinski' not in rv.data
        assert link_url0 in rv.data
        assert link_url1 not in rv.data
Пример #6
0
def test_incidents_csv(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)
        department = random.choice(dept_choices())

        # Delete existing incidents for chosen department
        Incident.query.filter_by(department_id=department.id).delete()

        incident_date = datetime(2000, 5, 25, 1, 45)
        report_number = '42'

        address_form = LocationForm(street_name='ABCDE',
                                    city='FGHI',
                                    state='IA')
        link_form = LinkForm(url='http://example.com', link_type='video')
        license_plates_form = LicensePlateForm(state='AZ')
        form = IncidentForm(date_field=str(incident_date.date()),
                            time_field=str(incident_date.time()),
                            report_number=report_number,
                            description='Something happened',
                            department=str(department.id),
                            department_id=department.id,
                            address=address_form.data,
                            links=[link_form.data],
                            license_plates=[license_plates_form.data],
                            officers=[])
        # add the incident
        rv = client.post(url_for('main.incident_api') + 'new',
                         data=process_form_data(form.data),
                         follow_redirects=True)
        assert "created" in rv.data.decode('utf-8')
        # dump incident csv
        rv = client.get(url_for('main.download_incidents_csv',
                                department_id=department.id),
                        follow_redirects=True)

        # get the csv entry with matching report number
        csv = list(
            filter(lambda row: report_number in row,
                   rv.data.decode('utf-8').split("\n")))
        print(csv)
        assert len(csv) == 1
        assert form.description.data in csv[0]