Esempio n. 1
0
def test_autofill_conclusion_form(app, client, zope_auth, setup_autofill,
                                  request_args, user):
    create_user(user, ['stakeholder'])
    zope_auth.update({'user_id': user})

    resp = client.get(*get_request_params('get', request_args))
    form = resp.forms[1]

    assert form['range_surface_area'].value == '100'
    # assert form['method_range'].value == '2GD'
    # assert form['conclusion_range'].value == 'FV'

    form['complementary_favourable_range'] = '200~~'

    resp = form.submit()
    form = resp.forms[1]

    assert form['range_surface_area'].value == '100'
    # assert form['method_range'].value == '2GD'
    # assert form['conclusion_range'].value == 'FV'

    assert form['complementary_favourable_range'].value == '200~~'
    assert 'form-error-td' in resp.html.find(
        id='complementary_favourable_range').parent.get('class')
    assert resp.html.find('li', {'class': 'flashmessage'}).text == \
        'Please correct the errors below and try again.'
Esempio n. 2
0
def test_404_error(app, setup, zope_auth, client, request_type, request_args,
                   post_params):
    create_user('otheruser')
    set_user('otheruser')
    resp = getattr(client, request_type)(*get_request_params(
        request_type, request_args, post_params), expect_errors=True)
    assert resp.status_code == 404
Esempio n. 3
0
def test_autofill_conclusion_form(app, client, set_auth, setup_autofill,
                                  request_args, user):
    create_user(user, ['stakeholder'])
    force_login(client, user)

    resp = client.get(*get_request_params('get', request_args))
    form = resp.context['manual_form']
    assert form.conclusion_assessment_prev.data == 'FV'
Esempio n. 4
0
def test_edit_comment(app, setup, zope_auth, client):
    create_user('testuser', role_names=['stakeholder'])
    set_user('testuser')
    client.post(*get_request_params(
        'post', ['/species/summary/datasheet/edit_comment/', {
            'period': '1', 'subject': 'Canis lupus', 'region': '',
            'comment_id': 1}], {'comment': 'Test edit comment.'}))
    assert get_instance(WikiComment, id=1).comment == 'Test edit comment.'
Esempio n. 5
0
def test_perms(app, setup, set_auth, client, request_type, request_args,
               post_params):
    resp = getattr(client,
                   request_type)(*get_request_params(request_type,
                                                     request_args,
                                                     post_params),
                                 expect_errors=True)
    assert resp.status_code == 403
Esempio n. 6
0
def test_edit_page(app, setup, zope_auth, client):
    create_user('testuser', role_names=['etc'])
    set_user('testuser')
    client.post(*get_request_params(
        'post', ['/species/summary/datasheet/edit_page/', {
            'period': '1', 'subject': 'Canis lupus', 'region': ''}],
        {'text': 'Test edit page.'}))
    assert get_instance(WikiChange, id=1).active == 0
    assert get_instance(WikiChange, body='Test edit page.').active == 1
Esempio n. 7
0
def test_change_active_revision(app, setup, zope_auth, client):
    create_user('otheruser', role_names=['etc'])
    set_user('otheruser')
    client.post(*get_request_params(
        'post', ['/species/summary/datasheet/page_history/', {
            'period': '1', 'subject': 'Canis lupus', 'region': ''}],
        {'revision_id': 3}))
    assert get_instance(WikiChange, id=1).active == 0
    assert get_instance(WikiChange, id=3).active == 1
Esempio n. 8
0
def test_perms_auth_user(app, setup, set_auth, client, request_type,
                         request_args, post_params):
    create_user('otheruser')
    set_user('otheruser')
    resp = getattr(client,
                   request_type)(*get_request_params(request_type,
                                                     request_args,
                                                     post_params),
                                 expect_errors=True)
    assert resp.status_code == 403
Esempio n. 9
0
def test_add_conclusion_etc(app, client, set_auth, setup_add, request_args,
                            post_params, user, MS, roles, model_cls):
    create_user(user, roles, ms=MS)
    force_login(client, user)

    resp = client.post(*get_request_params('post', request_args, post_params))
    assert resp.status_code == 200

    post_params.pop('submit', None)
    manual_ass = model_cls.query.filter_by(**post_params).one()
    assert manual_ass.MS == 'EU28'
Esempio n. 10
0
def test_update_decision(app, client, set_auth, setup_decision, request_args,
                         post_params, user, roles, expect_errors, status_code,
                         success, message):
    create_user(user, roles)
    force_login(client, user)
    resp = client.post(*get_request_params('post', request_args, post_params),
                       expect_errors=expect_errors)

    assert resp.status_code == status_code
    if status_code == 200:
        assert resp.json['success'] == success
        assert resp.json.get('error', '') == message
Esempio n. 11
0
def test_add_conclusion_etc(app, client, zope_auth, setup_add, request_args,
                            post_params, user, MS, roles, model_cls):
    create_user(user, roles, ms=MS)
    zope_auth.update({'user_id': user})

    resp = client.post(*get_request_params('post', request_args, post_params))

    assert resp.status_code == 200

    post_params.pop('submit', None)
    manual_ass = model_cls.query.filter_by(**post_params).one()
    assert manual_ass.MS == 'EU27'
Esempio n. 12
0
def test_add_comment(app, setup, zope_auth, client):
    create_user('newuser')
    set_user('newuser')
    request_data = ('post', ['/species/summary/datasheet/add_comment/', {
        'period': '1', 'subject': 'Canis lupus', 'region': ''}],
        {'comment': 'Test add comment.'})
    client.post(*get_request_params(*request_data))
    request_args = request_data[1][1]
    wiki = get_instance(Wiki, dataset_id=request_args['period'],
                        assesment_speciesname=request_args['subject'],
                        region_code=request_args['region'])
    assert request_data[2]['comment'] in [c.comment for c in wiki.comments]
Esempio n. 13
0
def test_update_decision(app, client, zope_auth, setup_decision, request_args,
                         post_params, user, roles, expect_errors, status_code,
                         success, message):
    create_user(user, roles)
    zope_auth.update({'user_id': user})

    resp = client.post(*get_request_params('post', request_args, post_params),
                       expect_errors=expect_errors)

    assert resp.status_code == status_code
    if status_code == 200:
        assert resp.json['success'] == success
        assert resp.json.get('error', '') == message
Esempio n. 14
0
def test_edit_comment(app, setup, set_auth, client):
    create_user('testuser', role_names=['stakeholder'])
    set_user('testuser')
    force_login(client, 'testuser')
    client.post(*get_request_params('post', [
        '/species/summary/datasheet/edit_comment/', {
            'period': '5',
            'subject': 'Canis lupus',
            'region': '',
            'comment_id': 1
        }
    ], {'comment': 'Test edit comment.'}))
    assert get_instance(WikiComment, id=1).comment == 'Test edit comment.'
Esempio n. 15
0
def test_edit_page(app, setup, set_auth, client):
    create_user('testuser', role_names=['etc'])
    set_user('testuser')
    force_login(client, 'testuser')
    client.post(*get_request_params('post', [
        '/species/summary/datasheet/edit_page/', {
            'period': '5',
            'subject': 'Canis lupus',
            'region': ''
        }
    ], {'text': 'Test edit page.'}))
    assert get_instance(WikiChange, id=1).active == 0
    assert get_instance(WikiChange, body='Test edit page.').active == 1
Esempio n. 16
0
def test_change_active_revision(app, setup, set_auth, client):
    create_user('otheruser', role_names=['etc'])
    set_user('otheruser')
    force_login(client, 'otheruser')
    client.post(*get_request_params('post', [
        '/species/summary/datasheet/page_history/', {
            'period': '5',
            'subject': 'Canis lupus',
            'region': ''
        }
    ], {'revision_id': 3}))
    assert get_instance(WikiChange, id=1).active == 0
    assert get_instance(WikiChange, id=3).active == 1
Esempio n. 17
0
def test_edit_conclusion(app, client, set_auth, setup_edit, request_args,
                         post_params, user, roles, expect_errors, status_code,
                         search_text):
    create_user(user, roles)
    force_login(client, user)

    resp = client.post(*get_request_params('post', request_args, post_params),
                       expect_errors=expect_errors)

    assert resp.status_code == status_code

    if resp.status_code == 302:
        resp = resp.follow()

    if search_text:
        assert search_text in resp.html.text
Esempio n. 18
0
def test_edit_conclusion(app, client, zope_auth, setup_edit, request_args,
                         post_params, user, roles, expect_errors, status_code,
                         search_text):
    create_user(user, roles)
    zope_auth.update({'user_id': user})

    resp = client.post(*get_request_params('post', request_args, post_params),
                       expect_errors=expect_errors)

    assert resp.status_code == status_code

    if resp.status_code == 302:
        resp = resp.follow()

    if search_text:
        assert search_text in resp.html.text
Esempio n. 19
0
def test_count_read_comments_view(app, client, set_auth, manual_assessment_cls,
                                  comment_cls, request_args):
    DatasetFactory()
    manual_assessment_cls(region='ALP')
    comment = comment_cls(region='ALP')
    models.db.session.commit()

    user = create_user('someuser')
    comment.readers.append(user)
    models.db.session.commit()

    force_login(client, 'someuser')
    resp = client.get(*get_request_params('get', request_args))

    assert resp.status_code == 200
    assert (resp.html.find('a', {
        'title': 'Comments: Read/Total'
    }).text.strip() == '1/1')
def test_comments(app, client, setup, zope_auth, request_type, request_args,
                  post_params, user, expect_errors, status_code,
                  assert_condition):
    create_user('testuser')
    if user:
        if user[0] != 'testuser':
            create_user(*user)
        zope_auth.update({'user_id': user[0]})

    resp = getattr(client, request_type)(*get_request_params(
        request_type, request_args, post_params), expect_errors=expect_errors)
    assert resp.status_code == status_code

    if resp.status_code == 302:
        resp = resp.follow()

    if assert_condition:
        assert eval(assert_condition)
def test_count_read_comments_view(app, client, zope_auth,
                                  manual_assessment_cls, comment_cls,
                                  request_args):
    DatasetFactory()
    manual_assessment_cls(region='ALP')
    comment = comment_cls(region='ALP')
    models.db.session.commit()

    user = create_user('someuser')
    comment.readers.append(user)
    models.db.session.commit()

    zope_auth.update({'user_id': 'someuser'})
    resp = client.get(*get_request_params('get', request_args))

    assert resp.status_code == 200
    assert (resp.html.find('a', {'title': 'Comments: Read/Total'}).text.strip()
            == '1/1')
Esempio n. 22
0
def test_add_comment(app, setup, set_auth, client):
    create_user('newuser')
    set_user('newuser')
    force_login(client, 'newuser')
    request_data = ('post', [
        '/species/summary/datasheet/add_comment/', {
            'period': '5',
            'subject': 'Canis lupus',
            'region': ''
        }
    ], {
        'comment': 'Test add comment.'
    })
    client.post(*get_request_params(*request_data))
    request_args = request_data[1][1]
    wiki = get_instance(Wiki,
                        dataset_id=request_args['period'],
                        assesment_speciesname=request_args['subject'],
                        region_code=request_args['region'])
    assert request_data[2]['comment'] in [c.comment for c in wiki.comments]
Esempio n. 23
0
def test_comments(app, client, setup, set_auth, request_type, request_args,
                  post_params, user, expect_errors, status_code,
                  assert_condition):
    create_user('testuser')
    if user:
        if user[0] != 'testuser':
            create_user(*user)
        force_login(client, user[0])

    resp = getattr(client,
                   request_type)(*get_request_params(request_type,
                                                     request_args,
                                                     post_params),
                                 expect_errors=expect_errors)
    assert resp.status_code == status_code

    if resp.status_code == 302:
        resp = resp.follow()

    if assert_condition:
        assert eval(assert_condition)
Esempio n. 24
0
def test_delete_conclusion(app, client, zope_auth, setup_edit, request_args,
                           user, status_code, expect_errors, model_cls):
    if user:
        create_user(user)
        zope_auth.update({'user_id': user})

    resp = client.get(*get_request_params('get', request_args),
                      expect_errors=expect_errors)

    assert resp.status_code == status_code

    if model_cls:
        args = request_args[1]
        records = model_cls.query.filter_by(
            dataset_id=args['period'],
            subject=args['subject'],
            region=args['delete_region'],
            user_id=args['delete_user'],
            MS=args['delete_ms'],
        ).all()

        assert len(records) == 1
        assert records[0].deleted == 1
Esempio n. 25
0
def test_delete_conclusion(app, client, set_auth, setup_edit, request_args,
                           user, status_code, expect_errors, model_cls):
    if user:
        create_user(user)
        force_login(client, user)

    resp = client.get(*get_request_params('get', request_args),
                      expect_errors=expect_errors)

    assert resp.status_code == status_code

    if model_cls:
        args = request_args[1]
        records = model_cls.query.filter_by(
            dataset_id=args['period'],
            subject=args['subject'],
            region=args['delete_region'],
            user_id=args['delete_user'],
            MS=args['delete_ms'],
        ).all()

        assert len(records) == 1
        assert records[0].deleted == 1
Esempio n. 26
0
def test_perms(app, setup, zope_auth, client, request_type, request_args,
               post_params):
    resp = getattr(client, request_type)(*get_request_params(
        request_type, request_args, post_params), expect_errors=True)
    assert resp.status_code == 403