コード例 #1
0
def test_user_can_add_tag(mockdata, client, session):
    with current_app.test_request_context():
        login_user(client)
        form = FaceTag(officer_id=1,
                       image_id=4,
                       dataX=34,
                       dataY=32,
                       dataWidth=3,
                       dataHeight=33)

        rv = client.post(url_for('main.label_data', image_id=4),
                         data=form.data,
                         follow_redirects=True)
        assert 'Tag added to database' in rv.data
コード例 #2
0
def test_featured_tag_replaces_others(mockdata, client, session):
    with current_app.test_request_context():
        login_admin(client)

        tag1 = Face.query.first()
        officer = Officer.query.filter_by(id=tag1.officer_id).one()

        # Add second tag for officer
        mock = MagicMock(return_value=Image.query.filter(Image.id != tag1.img_id).first())
        with patch('OpenOversight.app.main.views.crop_image', mock):
            image = Image.query.filter(Image.department_id == officer.department_id).first()
            form = FaceTag(officer_id=officer.id,
                           image_id=image.id,
                           dataX=34,
                           dataY=32,
                           dataWidth=3,
                           dataHeight=33)
            rv = client.post(
                url_for('main.label_data', image_id=image.id),
                data=form.data,
                follow_redirects=True
            )
            views.crop_image.assert_called_once()
            assert b'Tag added to database' in rv.data

        tag2 = Face.query.filter(Face.officer_id == tag1.officer_id).filter(Face.id != tag1.id).one_or_none()
        assert tag2 is not None

        # Set tag 1 as featured
        rv = client.post(
            url_for('main.set_featured_tag', tag_id=tag1.id),
            follow_redirects=True
        )
        assert b'Successfully set this tag as featured' in rv.data

        tag1 = Face.query.filter(Face.id == tag1.id).one()
        assert tag1.featured is True

        # Set tag 2 as featured
        rv = client.post(
            url_for('main.set_featured_tag', tag_id=tag2.id),
            follow_redirects=True
        )
        assert b'Successfully set this tag as featured' in rv.data

        tag1 = Face.query.filter(Face.id == tag1.id).one()
        tag2 = Face.query.filter(Face.id == tag2.id).one()
        assert tag1.featured is False
        assert tag2.featured is True
コード例 #3
0
def test_user_cannot_tag_nonexistent_officer(mockdata, client, session):
    with current_app.test_request_context():
        login_user(client)
        tag = Face.query.first()
        form = FaceTag(officer_id=999999999999999999,
                       image_id=tag.img_id,
                       dataX=34,
                       dataY=32,
                       dataWidth=3,
                       dataHeight=33)

        rv = client.post(url_for('main.label_data', image_id=tag.img_id),
                         data=form.data,
                         follow_redirects=True)
        assert 'Invalid officer ID' in rv.data
コード例 #4
0
def test_user_cannot_add_tag_if_it_exists(mockdata, client, session):
    with current_app.test_request_context():
        login_user(client)
        tag = Face.query.first()
        form = FaceTag(officer_id=tag.officer_id,
                       image_id=tag.img_id,
                       dataX=34,
                       dataY=32,
                       dataWidth=3,
                       dataHeight=33)

        rv = client.post(url_for('main.label_data', image_id=tag.img_id),
                         data=form.data,
                         follow_redirects=True)
        assert 'Tag already exists between this officer and image! Tag not added.' in rv.data
コード例 #5
0
def test_user_can_add_tag(mockdata, client, session):
    with current_app.test_request_context():
        login_user(client)
        officer = Image.query.filter_by(department_id=1).first()
        image = Image.query.filter_by(department_id=1).first()
        form = FaceTag(officer_id=officer.id,
                       image_id=image.id,
                       dataX=34,
                       dataY=32,
                       dataWidth=3,
                       dataHeight=33)

        rv = client.post(url_for('main.label_data', image_id=image.id),
                         data=form.data,
                         follow_redirects=True)
        assert 'Tag added to database' in rv.data
コード例 #6
0
def test_user_cannot_tag_officer_mismatched_with_department(mockdata, client, session):
    with current_app.test_request_context():
        login_user(client)
        tag = Face.query.first()
        form = FaceTag(officer_id=tag.officer_id,
                       image_id=tag.original_image_id,
                       dataX=34,
                       dataY=32,
                       dataWidth=3,
                       dataHeight=33)

        rv = client.post(
            url_for('main.label_data', department_id=2, image_id=tag.original_image_id),
            data=form.data,
            follow_redirects=True
        )
        assert b"The officer is not in Chicago Police Department. Are you sure that is the correct OpenOversight ID?" in rv.data
コード例 #7
0
def test_user_can_add_tag(mockdata, client, session):
    with current_app.test_request_context():
        mock = MagicMock(return_value=Image.query.first())
        with patch('OpenOversight.app.main.views.crop_image', mock):
            officer = Officer.query.filter_by(department_id=1).first()
            image = Image.query.filter_by(department_id=1).first()
            login_user(client)
            form = FaceTag(officer_id=officer.id,
                           image_id=image.id,
                           dataX=34,
                           dataY=32,
                           dataWidth=3,
                           dataHeight=33)
            rv = client.post(url_for('main.label_data', image_id=image.id),
                             data=form.data,
                             follow_redirects=True)
            views.crop_image.assert_called_once()
            assert b'Tag added to database' in rv.data