Esempio n. 1
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())
        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)

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

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

        form = EditOfficerForm(last_name='Changed')

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

        assert 'Changed' in rv.data
        assert 'Testerinski' not in rv.data
Esempio n. 2
0
def test_edit_officers_with_blank_uids(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        # Blank out all officer UID's
        session.execute(
            Officer.__table__.update().values(unique_internal_identifier=None))
        session.commit()

        [officer1, officer2] = Officer.query.limit(2).all()
        assert officer1.unique_internal_identifier is None
        assert officer2.unique_internal_identifier is None

        form = EditOfficerForm(last_name='Changed',
                               unique_internal_identifier='')
        data = process_form_data(form.data)

        # Edit first officer
        rv = client.post(url_for('main.edit_officer', officer_id=officer1.id),
                         data=data,
                         follow_redirects=True)
        assert 'Officer Changed edited' in rv.data.decode('utf-8')
        assert officer1.last_name == 'Changed'
        assert officer1.unique_internal_identifier is None

        # Edit second officer
        rv = client.post(url_for('main.edit_officer', officer_id=officer2.id),
                         data=data,
                         follow_redirects=True)
        assert 'Officer Changed edited' in rv.data.decode('utf-8')
        assert officer2.last_name == 'Changed'
        assert officer2.unique_internal_identifier is None
def test_ac_can_edit_officer_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)
        department = Department.query.filter_by(id=AC_DEPT).first()
        first_name = 'Testier'
        last_name = 'OTester'
        middle_initial = 'R'
        suffix = ''
        race = random.choice(RACE_CHOICES)[0]
        gender = random.choice(GENDER_CHOICES)[0]
        form = AddOfficerForm(first_name=first_name,
                              last_name=last_name,
                              middle_initial=middle_initial,
                              suffix=suffix,
                              race=race,
                              gender=gender,
                              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
        )

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

        new_last_name = 'Shiny'
        form = EditOfficerForm(
            first_name=first_name,
            last_name=new_last_name,
            suffix=suffix,
            race=race,
            gender=gender,
            department=department.id,
            # 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.edit_officer', officer_id=officer.id),
            data=data,
            follow_redirects=True
        )

        assert new_last_name in rv.data
        assert last_name not in rv.data

        # Check the changes were added to the database
        officer = Officer.query.filter_by(
            id=officer.id).one()
        assert officer.last_name == new_last_name
def test_ac_cannot_edit_officer_not_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)

        officer = officer = Officer.query.except_(Officer.query.filter_by(department_id=AC_DEPT)).first()
        old_last_name = officer.last_name

        new_last_name = 'Shiny'
        form = EditOfficerForm(
            last_name=new_last_name,
            # 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.edit_officer', officer_id=officer.id),
            data=data,
            follow_redirects=True
        )

        assert rv.status_code == 403

        # Ensure changes were not made to database
        officer = Officer.query.filter_by(
            id=officer.id).one()
        assert officer.last_name == old_last_name
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
Esempio n. 6
0
def test_ac_cannot_edit_officer_not_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)

        officer = officer = Officer.query.except_(
            Officer.query.filter_by(department_id=AC_DEPT)).first()
        old_last_name = officer.last_name

        new_last_name = 'Shiny'
        form = EditOfficerForm(last_name=new_last_name, )

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

        assert rv.status_code == 403

        # Ensure changes were not made to database
        officer = Officer.query.filter_by(id=officer.id).one()
        assert officer.last_name == old_last_name