Ejemplo n.º 1
0
def person(app, person_data):
    """Create mef person record."""
    pers = Person.create(data=person_data,
                         delete_pid=False,
                         dbcommit=True,
                         reindex=True)
    flush_index(PersonsSearch.Meta.index)
    return pers
Ejemplo n.º 2
0
def test_person_mef_create(mock_persons_mef_get, app, person_data_tmp,
                           person_response_data):
    """Test MEF person creation."""
    count = Person.count()
    mock_persons_mef_get.return_value = mock_response(
        json_data=person_response_data
    )
    pers_mef = Person.get_record_by_ref(
        'https://mef.rero.ch/api/rero/A017671081')
    flush_index(PersonsSearch.Meta.index)
    assert pers_mef == person_data_tmp
    assert Person.count() == count + 1
    pers_mef.pop('rero')
    pers_mef.pop('gnd')
    pers_mef['sources'] = ['bnf']
    pers_mef.replace(pers_mef, dbcommit=True)
    pers_db = Person.get_record_by_ref(
        'https://mef.rero.ch/api/gnd/172759757')
    assert pers_db['sources'] == ['bnf']
Ejemplo n.º 3
0
def test_person_create_delete(app, person_data_tmp, capsys):
    """Test mef persons creation and deletion."""
    count = create_mef_records([person_data_tmp], verbose=True)
    assert count == 1
    out, err = capsys.readouterr()
    pers = Person.get_record_by_pid('pers1')
    assert out.strip() == 'record uuid: {id}'.format(id=pers.id)
    count = delete_records([pers], verbose=True)
    assert count == 1
    out, err = capsys.readouterr()
    assert out.strip() == 'records deleted: 1'
Ejemplo n.º 4
0
def test_publish_api_harvested_records(app, person_data_tmp, capsys):
    """Test mef person publish api harvested records."""
    publish_api_harvested_records(sender='test', name='mef',
                                  records=[person_data_tmp],
                                  url='http://test.com')
    out, err = capsys.readouterr()
    assert out.strip() == (
        'mef harvester: received 1 records: '
        'https://ils.rero.ch/schemas/persons/person-v0.0.1.json'
    )
    assert Person.count() == 1
Ejemplo n.º 5
0
def test_monitoring_check_es_db_counts(app, client, person_data,
                                       system_librarian_martigny_no_email):
    """Test monitoring check_es_db_counts."""
    res = client.get(url_for('api_monitoring.check_es_db_counts'))
    assert res.status_code == 200
    assert get_json(res) == {'data': {'status': 'green'}}

    pers = Person.create(data=person_data,
                         delete_pid=False,
                         dbcommit=True,
                         reindex=False)
    flush_index(PersonsSearch.Meta.index)
    res = client.get(url_for('api_monitoring.check_es_db_counts'))
    assert res.status_code == 200
    assert get_json(res) == {
        'data': {
            'status': 'red'
        },
        'errors': [{
            'code': 'DB_ES_COUNTER_MISSMATCH',
            'details': 'There are 1 items from pers missing in ES.',
            'id': 'DB_ES_COUNTER_MISSMATCH',
            'links': {
                'about': 'http://localhost/monitoring/check_es_db_counts',
                'pers': 'http://localhost/monitoring/missing_pids/pers'
            },
            'title': "DB items counts don't match ES items count."
        }]
    }

    # this view is only accessible by admin
    res = client.get(url_for('api_monitoring.missing_pids', doc_type='pers'))
    assert res.status_code == 401

    login_user_via_session(client, system_librarian_martigny_no_email.user)
    res = client.get(url_for('api_monitoring.missing_pids', doc_type='pers'))
    assert res.status_code == 403

    # give user superuser admin rights
    db.session.add(
        ActionUsers.allow(superuser_access,
                          user=system_librarian_martigny_no_email.user))
    db.session.commit()
    res = client.get(url_for('api_monitoring.missing_pids', doc_type='pers'))
    assert res.status_code == 200

    assert get_json(res) == {
        'data': {
            'DB': [],
            'ES': ['http://localhost/persons/pers1'],
            'ES duplicate': []
        }
    }