コード例 #1
0
def test_ac_cannot_add_new_unit_not_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)

        department = Department.query.except_(
            Department.query.filter_by(id=AC_DEPT)).first()
        form = AddUnitForm(descrip='Test', department=department.id)

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

        # Check the unit was not added to the database
        unit = Unit.query.filter_by(descrip='Test').first()
        assert unit is None
コード例 #2
0
def test_ac_can_add_new_unit_in_their_dept(mockdata, client, session):
    with current_app.test_request_context():
        login_ac(client)

        department = Department.query.filter_by(id=AC_DEPT).first()
        form = AddUnitForm(descrip='Test', department=department.id)

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

        assert 'New unit' in rv.data.decode('utf-8')

        # Check the unit was added to the database
        unit = Unit.query.filter_by(descrip='Test').one()
        assert unit.department_id == department.id
コード例 #3
0
def test_admin_can_add_new_unit(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        department = Department.query.filter_by(
            name='Springfield Police Department').first()
        form = AddUnitForm(descrip='Test', department=department.id)

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

        assert 'New unit' in rv.data

        # Check the unit was added to the database
        unit = Unit.query.filter_by(descrip='Test').one()
        assert unit.department_id == department.id