Exemple #1
0
def test_ac_cannot_edit_officer_outside_their_dept_badge_number(
        mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        star_no = '1234'
        new_star_no = '12345'
        officer = Officer.query.except_(
            Officer.query.filter_by(department_id=AC_DEPT)).first()
        form = AssignmentForm(star_no=star_no, rank='COMMANDER')

        # Remove existing assignments
        Assignment.query.filter_by(officer_id=officer.id).delete()

        rv = client.post(url_for('main.add_assignment', officer_id=officer.id),
                         data=form.data,
                         follow_redirects=True)
        print(rv.data.decode('utf-8'))
        assert 'Added new assignment' in rv.data.decode('utf-8')
        assert '<td>{}</td>'.format(star_no) in rv.data.decode('utf-8')

        login_ac(client)

        form = AssignmentForm(star_no=new_star_no)
        officer = Officer.query.filter_by(id=officer.id).one()

        rv = client.post(url_for('main.edit_assignment',
                                 officer_id=officer.id,
                                 assignment_id=officer.assignments[0].id,
                                 form=form),
                         data=form.data,
                         follow_redirects=True)

        assert rv.status_code == 403
def test_ac_cannot_edit_officer_outside_their_dept_badge_number(
        mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)

        star_no = '1234'
        new_star_no = '12345'
        officer = Officer.query.except_(
            Officer.query.filter_by(department_id=AC_DEPT)).first()
        form = AssignmentForm(star_no=star_no, rank='COMMANDER')

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

        form = AssignmentForm(star_no=new_star_no)
        officer = Officer.query.filter_by(id=officer.id).one()

        rv = client.post(url_for('main.edit_assignment',
                                 officer_id=officer.id,
                                 assignment_id=officer.assignments[0].id,
                                 form=form),
                         data=form.data,
                         follow_redirects=True)

        assert rv.status_code == 403
Exemple #3
0
def test_admin_can_edit_officer_badge_number(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        # Remove existing assignments
        Assignment.query.filter_by(officer_id=3).delete()

        form = AssignmentForm(star_no='1234', rank='COMMANDER')

        rv = client.post(url_for('main.add_assignment', officer_id=3),
                         data=form.data,
                         follow_redirects=True)
        # print(rv.data.decode('utf-8'))
        assert 'Added new assignment' in rv.data.decode('utf-8')
        assert '<td>1234</td>' in rv.data.decode('utf-8')

        form = AssignmentForm(star_no='12345')
        officer = Officer.query.filter_by(id=3).one()

        rv = client.post(url_for('main.edit_assignment',
                                 officer_id=officer.id,
                                 assignment_id=officer.assignments[0].id,
                                 form=form),
                         data=form.data,
                         follow_redirects=True)

        assert 'Edited officer assignment' in rv.data.decode('utf-8')
        assert '<td>12345</td>' in rv.data.decode('utf-8')
        assert officer.assignments[0].star_no == '12345'
def test_admin_can_edit_officer_badge_number(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        form = AssignmentForm(star_no='1234',
                              rank='COMMANDER')

        rv = client.post(
            url_for('main.officer_profile', officer_id=3),
            data=form.data,
            follow_redirects=True
        )

        form = AssignmentForm(star_no='12345')
        officer = Officer.query.filter_by(id=3).one()

        rv = client.post(
            url_for('main.edit_assignment', officer_id=officer.id,
                    assignment_id=officer.assignments[0].id,
                    form=form),
            data=form.data,
            follow_redirects=True
        )

        assert 'Edited officer assignment' in rv.data
        assert officer.assignments[0].star_no == '12345'
def test_admin_can_add_officer_badge_number(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        form = AssignmentForm(star_no='1234', rank='COMMANDER')

        rv = client.post(url_for('main.add_assignment', officer_id=3),
                         data=form.data,
                         follow_redirects=True)

        assert 'Added new assignment' in rv.data
def test_ac_cannot_add_non_dept_officer_badge(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)

        form = AssignmentForm(star_no='1234', rank='COMMANDER')
        officer = Officer.query.except_(
            Officer.query.filter_by(department_id=AC_DEPT)).first()

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

        assert rv.status_code == 403
def test_ac_can_add_officer_badge_number_in_their_dept(mockdata, client,
                                                       session):
    with current_app.test_request_context():
        login_ac(client)

        form = AssignmentForm(star_no='S1234', rank='COMMANDER')
        officer = Officer.query.filter_by(department_id=AC_DEPT).first()

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

        assert 'Added new assignment' in rv.data

        # test that assignment exists in database
        assignment = Officer.query.filter(
            Officer.assignments.any(star_no='S1234'))
        assert assignment is not None