Ejemplo n.º 1
0
def record_with_two_revisions(app):
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'record rev0'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/schemas/records/hep.json',
        },
        '_collections': ['Literature']
    }

    with db.session.begin_nested():
        record = InspireRecord.create_or_update(record)
        record.commit()
    db.session.commit()

    record['titles'][0]['title'] = 'record rev1'

    with db.session.begin_nested():
        record = InspireRecord.create_or_update(record)
        record.commit()
    db.session.commit()

    yield

    _delete_record('lit', 111)
Ejemplo n.º 2
0
def record_insert_or_replace(json, skip_files=False):
    """Insert or replace a record."""
    pid_type = get_pid_type_from_schema(json['$schema'])
    control_number = json['control_number']

    try:
        pid = PersistentIdentifier.get(pid_type, control_number)
        record = InspireRecord.get_record(pid.object_uuid)
        record.clear()
        record.update(json, skip_files=skip_files)
        if json.get('legacy_creation_date'):
            record.model.created = datetime.strptime(json['legacy_creation_date'], '%Y-%m-%d')
        record.commit()
    except PIDDoesNotExistError:
        record = InspireRecord.create(json, id_=None, skip_files=skip_files)
        if json.get('legacy_creation_date'):
            record.model.created = datetime.strptime(json['legacy_creation_date'], '%Y-%m-%d')
        inspire_recid_minter(str(record.id), json)

    if json.get('deleted'):
        new_recid = get_recid_from_ref(json.get('new_record'))
        if not new_recid:
            record.delete()

    return record
def test_save_roots(workflow_app):

    head = InspireRecord.create_or_update(fake_record('title1', 123), skip_files=False)
    head.commit()
    update = InspireRecord.create_or_update(fake_record('title2', 456), skip_files=False)
    update.commit()

    obj = workflow_object_class.create(
        data={},
        data_type='hep'
    )
    obj.extra_data['head_uuid'] = str(head.id)
    obj.extra_data['update_uuid'] = str(update.id)
    obj.save()

    # Union: keep the most recently created/updated root from each source.
    insert_wf_record_source(json={'version': 'original'}, record_uuid=head.id, source='arxiv')

    insert_wf_record_source(json={'version': 'updated'}, record_uuid=update.id, source='arxiv')

    insert_wf_record_source(json={'version': 'updated'}, record_uuid=update.id, source='publisher')

    save_roots(obj, None)

    arxiv_rec = read_wf_record_source(head.id, 'arxiv')
    assert arxiv_rec.json == {'version': 'updated'}

    pub_rec = read_wf_record_source(head.id, 'publisher')
    assert pub_rec.json == {'version': 'updated'}

    assert not read_wf_record_source(update.id, 'arxiv')
    assert not read_wf_record_source(update.id, 'publisher')
Ejemplo n.º 4
0
def store_record(obj, eng):
    """Insert or replace a record."""
    is_update = obj.extra_data.get('is-update')
    is_authors = eng.workflow_definition.data_type == 'authors'

    if is_update:
        if not is_authors and not current_app.config.get('FEATURE_FLAG_ENABLE_MERGER', False):
            obj.log.info(
                'skipping update record, feature flag ``FEATURE_FLAG_ENABLE_MERGER`` is disabled.'
            )
            return

        record = InspireRecord.get_record(obj.extra_data['head_uuid'])
        obj.data['control_number'] = record['control_number']
        record.clear()
        record.update(obj.data, files_src_records=[obj])

    else:
        # Skip the files to avoid issues in case the record has already pid
        # TODO: remove the skip files once labs becomes master
        record = InspireRecord.create(obj.data, id_=None, skip_files=True)
        # Create persistent identifier.
        # Now that we have a recid, we can properly download the documents
        record.download_documents_and_figures(src_records=[obj])

        obj.data['control_number'] = record['control_number']
        # store head_uuid to store the root later
        obj.extra_data['head_uuid'] = str(record.id)

    record.commit()
    obj.save()
    db.session.commit()
def test_manual_merge_existing_records(workflow_app):

    json_head = fake_record('This is the HEAD', 1)
    json_update = fake_record('While this is the update', 2)

    # this two fields will create a merging conflict
    json_head['core'] = True
    json_update['core'] = False

    head = InspireRecord.create_or_update(json_head, skip_files=False)
    head.commit()
    update = InspireRecord.create_or_update(json_update, skip_files=False)
    update.commit()
    head_id = head.id
    update_id = update.id

    obj_id = start_merger(
        head_id=1,
        update_id=2,
        current_user_id=1,
    )

    do_resolve_manual_merge_wf(workflow_app, obj_id)

    # retrieve it again, otherwise Detached Instance Error
    obj = workflow_object_class.get(obj_id)

    assert obj.status == ObjectStatus.COMPLETED
    assert obj.extra_data['approved'] is True
    assert obj.extra_data['auto-approved'] is False

    # no root present before
    last_root = read_wf_record_source(head_id, 'arxiv')
    assert last_root is None

    update_source = LiteratureReader(update).source
    root_update = read_wf_record_source(update_id, update_source)
    assert root_update is None

    # check that head's content has been replaced by merged
    deleted_record = RecordMetadata.query.filter_by(id=update_id).one()

    latest_record = get_db_record('lit', 1)

    assert deleted_record.json['deleted'] is True

    # check deleted record is linked in the latest one
    deleted_rec_ref = {'$ref': 'http://localhost:5000/api/literature/2'}
    assert [deleted_rec_ref] == latest_record['deleted_records']

    # check the merged record is linked in the deleted one
    new_record_metadata = {'$ref': 'http://localhost:5000/api/literature/1'}
    assert new_record_metadata == deleted_record.json['new_record']

    del latest_record['deleted_records']
    assert latest_record == obj.data  # -> resulted merged record
Ejemplo n.º 6
0
def test_create_with_source_record_with_different_control_number(isolated_app):
    expected_file_content = 'dummy body'
    rec1_expected_key = '1_Fulltext.pdf'
    rec2_expected_key = '2_Fulltext.pdf'

    record1_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 1,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        '_collections': [
            'Literature'
        ],  # DESY harvest
        'documents': [{
            'key': 'Fulltext.pdf',
            'url': '/some/non/existing/path.pdf',
        }],
    }

    record2_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 2,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        '_collections': [
            'Literature'
        ],  # DESY harvest
    }

    record1 = InspireRecord.create(record1_json)
    rec1_file_content = open(
        record1.files[rec1_expected_key].obj.file.uri
    ).read()
    assert rec1_file_content == expected_file_content

    record2_json['documents'] = copy.deepcopy(record1['documents'])

    record2 = InspireRecord.create(record2_json, files_src_records=[record1])

    assert len(record2.files) == len(record2_json['documents'])
    assert len(record2['documents']) == len(record2_json['documents'])
    assert record2['documents'][0]['url'] != record1['documents'][0]['url']
    rec2_file_content = open(
        record2.files[rec2_expected_key].obj.file.uri
    ).read()
    assert rec2_file_content == expected_file_content
Ejemplo n.º 7
0
def record_to_merge(workflow_app):
    json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        '_collections': [
            'Literature'
        ],
        'authors': [
            {
                'full_name': 'Jessica, Jones',
            },
        ],
        'document_type': [
            'thesis'
        ],
        'number_of_pages': 100,
        'preprint_date': '2016-11-16',
        'public_notes': [
            {
                'source': 'arXiv',
                'value': '100 pages, 36 figures'
            }
        ],
        'titles': [
            {
                'title': 'Alias Investigations'
            }
        ],
        'dois': [
            {
                'value': '10.1007/978-3-319-15001-7'
            }
        ],
    }
    record = InspireRecord.create(json, id_=None, skip_files=True)
    record.commit()
    rec_uuid = record.id

    db.session.commit()
    es.indices.refresh('records-hep')

    yield record

    record = InspireRecord.get_record(rec_uuid)
    pid = PersistentIdentifier.get(
        pid_type='lit',
        pid_value=record['control_number']
    )

    pid.unassign()
    pid.delete()
    record.delete()
    record.commit()
def jhep_with_malformed_title(app):
    """Temporarily add a malformed title to the JHEP record."""
    record = get_db_record('jou', 1213103)
    record['title_variants'].append('+++++')
    record = InspireRecord.create_or_update(record)
    record.commit()

    yield

    record = get_db_record('jou', 1213103)
    record['title_variants'] = record['title_variants'][:-1]
    record = InspireRecord.create_or_update(record)
    record.commit()
Ejemplo n.º 9
0
def _delete_merged_records(pid_type, merged_pid_value, deleted_pid_value, merged_uuid, deleted_uuid):
    InspireRecord.get_record(merged_uuid)._delete(force=True)
    InspireRecord.get_record(deleted_uuid)._delete(force=True)

    merged_pid = PersistentIdentifier.get(pid_type, merged_pid_value)
    deleted_pid = PersistentIdentifier.get(pid_type, deleted_pid_value)

    Redirect.query.filter(Redirect.id == deleted_pid.object_uuid).delete()

    db.session.delete(merged_pid)
    db.session.delete(deleted_pid)

    db.session.commit()
def book_with_another_document_type(app):
    """Temporarily add another document type to a book record."""
    record = get_db_record('lit', 1373790)
    record['document_type'] = ['book', 'proceedings']
    record = InspireRecord.create_or_update(record)
    record.commit()

    yield

    record = get_db_record('lit', 1373790)
    record['document_type'] = ['book']
    record = InspireRecord.create_or_update(record)
    record.commit()
Ejemplo n.º 11
0
def cern_with_hal_id(app):
    """Temporarily add the HAL id to the CERN record."""
    record = get_db_record('ins', 902725)
    record['external_system_identifiers'] = [{'schema': 'HAL', 'value': '300037'}]
    record = InspireRecord.create_or_update(record)
    record.commit()
    es.indices.refresh('records-institutions')

    yield

    record = get_db_record('ins', 902725)
    del record['external_system_identifiers']
    record = InspireRecord.create_or_update(record)
    record.commit()
    es.indices.refresh('records-institutions')
Ejemplo n.º 12
0
def _create_and_index_record(record):
    record = InspireRecord.create(record)
    inspire_recid_minter(record.id, record)
    db.session.commit()
    es.indices.refresh('records-hep')

    return record
Ejemplo n.º 13
0
def test_download_local_file(isolated_app):
    with NamedTemporaryFile(suffix=';1') as temp_file:
        file_location = 'file://{0}'.format(quote(temp_file.name))
        file_name = os.path.basename(temp_file.name)
        data = {
            '$schema': 'http://localhost:5000/schemas/records/hep.json',
            '_collections': [
                'Literature'
            ],
            'document_type': [
                'article'
            ],
            'titles': [
                {
                    'title': 'h'
                },
            ],
            'documents': [
                {
                    'key': file_name,
                    'url': file_location,
                },
            ],
        }

        record = InspireRecord.create(data)

        documents = record['documents']
        files = record['_files']

        assert 1 == len(documents)
        assert 1 == len(files)
Ejemplo n.º 14
0
def test_literature_citations_api_without_results(api_client):
    record_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'document_type': [
            'article',
        ],
        'control_number': 111,
        'titles': [
            {
                'title': 'Jessica Jones',
            },
        ],
        '_collections': ['Literature']
    }
    record = InspireRecord.create(record_json)
    record.commit()

    es.indices.refresh('records-hep')

    response = api_client.get(
        '/literature/111/citations',
        headers={'Accept': 'application/json'}
    )
    result = json.loads(response.get_data(as_text=True))

    expected_metadata = {
        "citation_count": 0,
        "citations": [],
    }

    assert response.status_code == 200
    assert expected_metadata == result['metadata']

    _delete_record('lit', 111)
Ejemplo n.º 15
0
def test_create_handles_figures(isolated_app):
    record_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 1,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        '_collections': [
            'Literature'
        ],
        'figures': [{
            'key': 'graph.png',
            'url': '/afs/cern.ch/project/inspire/PROD/var/data/files/g151/3037619/graph.png;1',
        }]  # record/1628455/export/xme
    }

    record = InspireRecord.create(record_json)
    expected_file_content = 'dummy body'
    expected_key = '1_graph.png'

    assert expected_key in record.files.keys
    assert len(record.files) == 1
    assert len(record['figures']) == len(record_json['figures'])
    file_content = open(record.files[expected_key].obj.file.uri).read()
    assert file_content == expected_file_content
Ejemplo n.º 16
0
def test_record_with_non_valid_content_is_cleaned_and_created_properly(
        isolated_app):
    record_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 1,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        '_collections': [
            'Literature'
        ],
        # these two fields make the record not valid
        'documents': [],
        'urls': [
            {'url': ''},
        ],
        # record/1628455/export/xme -- with some modification
    }
    non_valid = False
    try:
        validate(record_json)
    except ValidationError:
        non_valid = True

    assert non_valid
    record = InspireRecord.create(record_json)
    validate(record)
Ejemplo n.º 17
0
def test_create_with_skip_files_param_overrides_records_skip_files_conf_and_does_not_add_documents_or_figures(isolated_app):
    record_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 1,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        '_collections': [
            'Literature'
        ],
        'figures': [{
            'key': 'graph.png',
            'url': 'http://www.mdpi.com/2218-1997/3/1/24/png',
        }],
        'documents': [{
            'key': 'arXiv:1710.01187.pdf',
            'url': '/afs/cern.ch/project/inspire/PROD/var/data/files/g151/3037619/content.pdf;1',
        }]  # record/1628455/export/xme -- with some modification
    }

    with patch.dict(isolated_app.config, {'RECORDS_SKIP_FILES': False}):
        record = InspireRecord.create(record_json, skip_files=True)

    assert len(record.files) == 0
    assert record['documents'] == record_json['documents']
    assert record['figures'] == record_json['figures']
 def test_new_record(self):
     recid = 9999912587
     record_json = {
         '$schema': 'http://localhost:5000/schemas/records/hep.json',
         'document_type': [
             'article',
         ],
         'control_number': recid,
         'titles': [
             {
                 'title': 'Jessica Jones',
             },
         ],
         '_collections': ['Literature'],
         'references': [{'record': {
             '$ref': 'http://localhost:5000/api/literature/1498589'}}]
     }
     inspire_record = InspireRecord.create(record_json)
     with override_config(FEATURE_FLAG_ENABLE_ORCID_PUSH=True,
                          FEATURE_FLAG_ORCID_PUSH_WHITELIST_REGEX='.*',
                          ORCID_APP_CREDENTIALS={'consumer_key': '0000-0001-8607-8906'}), \
             mock.patch('inspirehep.modules.records.receivers.push_access_tokens') as mock_push_access_tokens, \
             mock.patch('inspirehep.modules.orcid.tasks.orcid_push.apply_async') as mock_apply_async:
         mock_push_access_tokens.get_access_tokens.return_value = [('myorcid', 'mytoken')]
         inspire_record.commit()
         mock_apply_async.assert_called_once_with(
             kwargs={'orcid': 'myorcid',
                     'oauth_token': 'mytoken',
                     'kwargs_to_pusher': {'record_db_version': inspire_record.model.version_id},
                     'rec_id': recid},
             queue='orcid_push')
     _delete_record('lit', recid)
def test_creating_deleted_record_and_undeleting_created_record_in_es(app):
    search = LiteratureSearch()
    json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        'deleted': True,
        '_collections': ['Literature']
    }

    # When a record is created in the DB with deleted flag True, it is not created in ES.

    record = InspireRecord.create(json)
    record.commit()
    db.session.commit()
    with pytest.raises(NotFoundError):
        search.get_source(record.id)

    # When a record is undeleted, it is created in ES.
    record['deleted'] = False
    record.commit()
    db.session.commit()
    search.get_source(record.id)
    record._delete(force=True)
def test_deleting_record_triggers_delete_in_es(app):
    search = LiteratureSearch()
    json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
        '_collections': ['Literature']
    }

    # When a record is created in the DB, it is also created in ES.

    record = InspireRecord.create(json)
    record.commit()
    db.session.commit()
    search.get_source(record.id)

    # When a record is updated with deleted flag true, it is deleted in ES
    record['deleted'] = True
    record.commit()
    db.session.commit()
    with pytest.raises(NotFoundError):
        search.get_source(record.id)
Ejemplo n.º 21
0
def sample_record(app):
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        '_collections': [
            'Literature',
        ],
        'control_number': 111,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'sample'}
        ],
    }
    record = _create_and_index_record(record)
    record_id = record.id

    yield record

    pid = PersistentIdentifier.get('lit', '111')
    db.session.delete(pid)
    record = InspireRecord.get_record(record_id)
    record._delete(force=True)
    current_app.extensions[
        'invenio-db'].versioning_manager.transaction_cls.query.delete()
    db.session.commit()
Ejemplo n.º 22
0
def test_that_db_changes_are_mirrored_in_es(app):
    search = LiteratureSearch()
    json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'foo'},
        ],
    }

    # When a record is created in the DB, it is also created in ES.

    record = InspireRecord.create(json)
    es_record = search.get_source(record.id)

    assert get_title(es_record) == 'foo'

    # When a record is updated in the DB, is is also updated in ES.

    record['titles'][0]['title'] = 'bar'
    record.commit()
    es_record = search.get_source(record.id)

    assert get_title(es_record) == 'bar'

    # When a record is deleted in the DB, it is also deleted in ES.

    record._delete(force=True)

    with pytest.raises(NotFoundError):
        es_record = search.get_source(record.id)
Ejemplo n.º 23
0
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_orcid_id(isolated_app):
    record = get_db_record('aut', 1061000)
    record['ids'] = [{'schema': 'INSPIRE BAI', 'value': 'Maurizio.Martinelli.1'}]
    record = InspireRecord.create_or_update(record)
    record.commit()

    with pytest.raises(NoResultFound):
        get_literature_recids_for_orcid('0000-0003-4792-9178')
Ejemplo n.º 24
0
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_ids(isolated_app):
    record = get_db_record('aut', 1061000)
    del record['ids']
    record = InspireRecord.create_or_update(record)
    record.commit()

    with pytest.raises(NoResultFound):
        get_literature_recids_for_orcid('0000-0003-4792-9178')
Ejemplo n.º 25
0
def test_get_literature_recids_for_orcid_raises_if_two_authors_are_found(isolated_app):
    record = get_db_record('aut', 1061000)
    record['control_number'] = 1061001
    record = InspireRecord.create_or_update(record)
    record.commit()

    with pytest.raises(MultipleResultsFound):
        get_literature_recids_for_orcid('0000-0003-4792-9178')
Ejemplo n.º 26
0
def test_create_does_not_save_zombie_identifiers_if_record_creation_fails(isolated_app):
    invalid_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        '_collections': [
            'Literature',
        ],
        'control_number': 1936477,
    }

    with pytest.raises(ValidationError):
        InspireRecord.create(invalid_record)

    record_identifier = RecordIdentifier.query.filter_by(recid=1936477).one_or_none()
    persistent_identifier = PersistentIdentifier.query.filter_by(pid_value='1936477').one_or_none()

    assert not record_identifier
    assert not persistent_identifier
def test_index_after_commit_indexes_raises_if_cited_records_are_not_in_db(
    mocked_indexing_task,
    mocked_permission_check,
    app,
):
    # this test doesn't use the isolated_app because it needs to commit to
    # the DB in order to create records versions.

    citing_json = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'document_type': ['article'],
        'titles': [{'title': 'Record citing the first one'}],
        '_collections': ['Literature'],
        'control_number': 8888,
        'references': [
            {"reference": {'authors': [{'full_name': 'Smith, J.'}]}}
        ]
    }

    record = InspireRecord.create(data=citing_json, skip_files=True)
    record.commit()
    db.session.commit()
    es.indices.refresh('records-hep')

    expected_args = 'lit', record['control_number'], 2
    mocked_indexing_task.assert_called_with(*expected_args)

    # execute mocked task
    index_modified_citations_from_record(*expected_args)

    references = {
        'references': [
            {
                "curated_relation": False,
                "record": {
                    "$ref": "http://localhost:5000/api/literature/9999"
                },
                "reference": {
                    'authors': [{'full_name': 'Smith, J.'}],
                }
            }
        ]
    }

    citing_json.update(references)
    record.clear()
    record.update(citing_json)
    record.commit()
    db.session.commit()
    es.indices.refresh('records-hep')

    expected_args = ('lit', record['control_number'], 3)
    mocked_indexing_task.assert_called_with(*expected_args)
    # execute mocked task
    with pytest.raises(MissingCitedRecordError):
        index_modified_citations_from_record(*expected_args)

    _delete_record('lit', 8888)
Ejemplo n.º 28
0
def test_get_url_empty_urls():
    empty_urls = InspireRecord({
        'urls': []
    })

    expected = ''
    result = Bibtex(empty_urls)._get_url()

    assert expected == result
Ejemplo n.º 29
0
def _create_record(record_json):
    with db.session.begin_nested():
        record = InspireRecord.create_or_update(record_json)
        record.commit()

    db.session.commit()
    es.indices.refresh()

    return record_json
Ejemplo n.º 30
0
def test_get_year_from_imprints_an_empty_list():
    imprints_an_empty_list = InspireRecord({
        'imprints': []
    })

    expected = ''
    result = Bibtex(imprints_an_empty_list)._get_year()

    assert expected == result
Ejemplo n.º 31
0
def test_get_entry_type_no_collections_one_invalid_pubinfo():
    no_collections_one_invalid_pubinfo = InspireRecord({
        'publication_info': {}
    })

    expected = ('article', 'article')
    result = Bibtex(no_collections_one_invalid_pubinfo)._get_entry_type()

    assert expected == result
Ejemplo n.º 32
0
def test_get_volume_from_publication_info_an_empty_list():
    publication_info_an_empty_list = InspireRecord({
        'publication_info': []
    })

    expected = ''
    result = Bibtex(publication_info_an_empty_list)._get_volume()

    assert expected == result
Ejemplo n.º 33
0
def test_get_date_from_legacy_creation_date():
    legacy_creation_date = InspireRecord({
        'legacy_creation_date': '2012'
    })

    expected = 2012
    result = Cv_latex(legacy_creation_date)._get_date()

    assert expected == result
Ejemplo n.º 34
0
def test_get_publi_info_from_publication_info_an_empty_list():
    publication_info_an_empty_list = InspireRecord({'publication_info': []})
    cv_latex_html_text = Cv_latex_html_text(publication_info_an_empty_list,
                                            'cv_latex_html_text', ',')

    expected = []
    result = cv_latex_html_text._get_publi_info()

    assert expected == result
Ejemplo n.º 35
0
def test_get_citation_number_no_citation_count(g_e_r):
    g_e_r.return_value = {}

    no_citation_count = InspireRecord({'control_number': 1})

    expected = ''
    result = Export(no_citation_count)._get_citation_number()

    assert expected == result
Ejemplo n.º 36
0
def _create_and_index_record(record):
    record = InspireRecord.create(record)
    inspire_recid_minter(record.id, record)
    # invenio-collections will populate _collections field in record upon
    # commit
    db.session.commit()
    es.indices.refresh('records-hep')

    return record
Ejemplo n.º 37
0
def test_parse_structures_no_authors(g_e_r):
    g_e_r.return_value = []

    no_authors = InspireRecord({})

    expected = []
    result = tei._parse_structures(no_authors)

    assert expected == result
Ejemplo n.º 38
0
def test_get_archive_prefix_empty_arxiv_eprints():
    empty_arxiv_eprints = InspireRecord({
        'arxiv_eprints': []
    })

    expected = ''
    result = Bibtex(empty_arxiv_eprints)._get_archive_prefix()

    assert expected == result
Ejemplo n.º 39
0
def test_get_value_returns_none_on_index_error():
    single_title = InspireRecord({
        'titles': [{
            'title':
            'Importance of a consistent choice of alpha(s) in the matching of AlpGen and Pythia',
        }],
    })

    assert get_value(single_title, 'titles.title[1]') is None
Ejemplo n.º 40
0
def test_get_title_returns_empty_string_when_titles_is_an_empty_list():
    titles_an_empty_list = InspireRecord({'titles': []})
    cv_latex_html_text = Cv_latex_html_text(titles_an_empty_list,
                                            'cv_latex_html_text', ',')

    expected = ''
    result = cv_latex_html_text._get_title()

    assert expected == result
Ejemplo n.º 41
0
def test_get_literature_recids_for_orcid_raises_if_two_authors_are_found(
        isolated_app):
    record = get_db_record('aut', 1061000)
    record['control_number'] = 1061001
    record = InspireRecord.create_or_update(record)
    record.commit()

    with pytest.raises(MultipleResultsFound):
        get_literature_recids_for_orcid('0000-0003-4792-9178')
Ejemplo n.º 42
0
def test_get_title_capitalizes_when_title_is_uppercase():
    title_is_uppercase = InspireRecord({'titles': [{'title': 'FOO'}]})
    cv_latex_html_text = Cv_latex_html_text(title_is_uppercase,
                                            'cv_latex_html_text', ',')

    expected = 'Foo'
    result = cv_latex_html_text._get_title()

    assert expected == result
Ejemplo n.º 43
0
def test_get_author_one_author_without_full_name():
    one_author_without_full_name = InspireRecord({
        'authors': [{}]
    })

    expected = []
    result = Bibtex(one_author_without_full_name)._get_author()

    assert expected == result
Ejemplo n.º 44
0
def test_institutes_links():
    record_with_institute = InspireRecord({'institute': ['foo']})

    expected = [
        '\n<a href="search/?cc=Institutions&p=110_u%3Afoo&of=hd">foo</a>'
    ]
    result = institutes_links(record_with_institute)

    assert expected == result
Ejemplo n.º 45
0
def test_get_key_empty(_g_c_k):
    _g_c_k.return_value = True

    dummy = InspireRecord({})

    expected = ''
    result = Bibtex(dummy)._get_key()

    assert expected == result
Ejemplo n.º 46
0
def test_get_date_from_thesis_uses_first_date_found():
    thesis = InspireRecord({
        'thesis': {'date': '1966'}
    })

    expected = 1966
    result = Cv_latex(thesis)._get_date()

    assert expected == result
Ejemplo n.º 47
0
def test_get_key_from_control_number(_g_c_k):
    _g_c_k.return_value = False

    with_control_number = InspireRecord({'control_number': 1})

    expected = 1
    result = Bibtex(with_control_number)._get_key()

    assert expected == result
Ejemplo n.º 48
0
def test_get_journal_publication_info_a_list_no_journal_title():
    publication_info_a_list_no_journal_title = InspireRecord({
        'publication_info': []
    })

    expected = ''
    result = Bibtex(publication_info_a_list_no_journal_title)._get_journal()

    assert expected == result
Ejemplo n.º 49
0
def test_get_year_no_publication_info_no_thesis_no_imprints_no_preprint_date():
    no_publication_info_no_thesis_no_imprints_no_preprint_date = InspireRecord(
        {})

    expected = ''
    result = Bibtex(no_publication_info_no_thesis_no_imprints_no_preprint_date
                    )._get_year()

    assert expected == result
Ejemplo n.º 50
0
def test_get_year_from_preprint_date_an_empty_list():
    preprint_date_an_empty_list = InspireRecord({
        'preprint_date': []
    })

    expected = ''
    result = Bibtex(preprint_date_an_empty_list)._get_year()

    assert expected == result
Ejemplo n.º 51
0
def test_get_author_from_corporate_author_an_empty_list():
    corporate_author_an_empty_list = InspireRecord({'corporate_author': []})
    cv_latex_html_text = Cv_latex_html_text(corporate_author_an_empty_list,
                                            'cv_latex_html_text', ',')

    expected = []
    result = cv_latex_html_text._get_author()

    assert expected == result
Ejemplo n.º 52
0
def test_get_editor_no_author_has_editor_role():
    no_author_has_editor_role = InspireRecord({
        'authors': [
            {'full_name': 'Englert, F.'},
            {'full_name': 'Brout, R.'}
        ]
    })

    assert Bibtex(no_author_has_editor_role)._get_editor() is None
Ejemplo n.º 53
0
def test_get_title_returns_empty_string_when_no_titles():
    no_titles = InspireRecord({})
    cv_latex_html_text = Cv_latex_html_text(no_titles, 'cv_latex_html_text',
                                            ',')

    expected = ''
    result = cv_latex_html_text._get_title()

    assert expected == result
Ejemplo n.º 54
0
def test_get_volume_from_book_series_an_empty_list():
    book_series_an_empty_list = InspireRecord({
        'book_series': []
    })

    expected = ''
    result = Bibtex(book_series_an_empty_list)._get_volume()

    assert expected == result
Ejemplo n.º 55
0
def cern_with_hal_id(app):
    """Temporarily add the HAL id to the CERN record."""
    record = get_db_record('ins', 902725)
    record['external_system_identifiers'] = [{
        'schema': 'HAL',
        'value': '300037'
    }]
    record = InspireRecord.create_or_update(record)
    record.commit()
    es.indices.refresh('records-institutions')

    yield

    record = get_db_record('ins', 902725)
    del record['external_system_identifiers']
    record = InspireRecord.create_or_update(record)
    record.commit()
    es.indices.refresh('records-institutions')
Ejemplo n.º 56
0
def test_get_literature_recids_for_orcid_still_works_if_author_has_no_ids(
        isolated_app):
    record = get_db_record('aut', 1061000)
    del record['ids']
    record = InspireRecord.create_or_update(record)
    record.commit()

    with pytest.raises(NoResultFound):
        get_literature_recids_for_orcid('0000-0003-4792-9178')
Ejemplo n.º 57
0
def test_get_series_empty_book_series():
    empty_book_series = InspireRecord({
        'book_series': []
    })

    expected = ''
    result = Bibtex(empty_book_series)._get_series()

    assert expected == result
Ejemplo n.º 58
0
def test_appoint_profile_from_claimed_signature(small_app):
    """Check the module for the case where claimed signature takes
    everything.
    """
    from inspirehep.modules.disambiguation.tasks import (
        disambiguation_clustering,
        update_authors_recid
    )

    old_record_id = str(PersistentIdentifier.get('lit', 11883).object_uuid)
    old_record = get_es_record_by_uuid(old_record_id)
    old_author_uuid = old_record['authors'][0]['uuid']

    # Add phonetic block to the record.
    old_record['authors'][0]['signature_block'] = "HAGp"
    old_record['authors'][0]['recid'] = "2"
    es.index(index='records-hep', doc_type='hep',
             id=old_record_id, body=old_record)
    es.indices.refresh('records-hep')

    record_id = str(PersistentIdentifier.get('lit', 1358492).object_uuid)
    record = get_es_record_by_uuid(record_id)
    author_uuid = record['authors'][0]['uuid']

    # Add phonetic block to the record.
    record['authors'][0]['signature_block'] = "HAGp"
    record['authors'][0]['recid'] = "314159265"
    record['authors'][0]['curated_relation'] = True
    es.index(index='records-hep', doc_type='hep',
             id=record_id, body=record)
    es.indices.refresh('records-hep')

    with patch("celery.current_app.send_task",
               return_value=_BeardObject(
                   ({"2": [old_author_uuid, author_uuid]}, {}))):
        with patch("inspirehep.modules.disambiguation.tasks.update_authors_recid.delay",
                   side_effect=update_authors_recid):
            disambiguation_clustering("HAGp")

    assert InspireRecord.get_record(old_record_id)['authors'][0]['recid'] == \
        "314159265"
    assert InspireRecord.get_record(record_id)['authors'][0]['recid'] == \
        "314159265"
Ejemplo n.º 59
0
def test_append_updated_record_to_queue_same_data(small_app):
    """Check if for the same record, the receiver will skip the publication."""
    pid = PersistentIdentifier.get('lit', 11883)
    publication_id = str(pid.object_uuid)
    record = InspireRecord.get_record(publication_id)

    append_updated_record_to_queue(None, record, record, 'records-hep', 'hep')

    assert str(record.id) != \
        DisambiguationRecord.query.order_by(desc('id')).first().record_id