コード例 #1
0
ファイル: api.py プロジェクト: turtle321/inspire-next
    def dumps(self):
        """Returns a dict 'representation' of the record.

        Note: this is not suitable to create a new record from it, as the
              representation will include some extra fields that should not be
              present in the record's json, see the 'to_dict' method instead.
        """
        base_dict = super(InspireRecord, self).dumps()
        populate_earliest_date(base_dict)
        return base_dict
コード例 #2
0
ファイル: api.py プロジェクト: harunurhan/inspire-next
    def dumps(self):
        """Returns a dict 'representation' of the record.

        Note: this is not suitable to create a new record from it, as the
              representation will include some extra fields that should not be
              present in the record's json, see the 'to_dict' method instead.
        """
        base_dict = super(InspireRecord, self).dumps()
        populate_earliest_date(base_dict)
        return base_dict
コード例 #3
0
def test_populate_earliest_date_from_preprint_date():
    schema = load_schema('hep')
    subschema = schema['properties']['preprint_date']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'preprint_date': '2014-05-29',
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['preprint_date'], subschema) is None

    populate_earliest_date(record)

    expected = '2014-05-29'
    result = record['earliest_date']

    assert expected == result
コード例 #4
0
def test_populate_earliest_date_from_legacy_creation_date():
    schema = load_schema('hep')
    subschema = schema['properties']['legacy_creation_date']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'legacy_creation_date': '2015-11-04',
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['legacy_creation_date'], subschema) is None

    populate_earliest_date(record)

    expected = '2015-11-04'
    result = record['earliest_date']

    assert expected == result
コード例 #5
0
def test_populate_earliest_date_from_thesis_info_defense_date():
    schema = load_schema('hep')
    subschema = schema['properties']['thesis_info']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'thesis_info': {
            'defense_date': '2012-06-01',
        },
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['thesis_info'], subschema) is None

    populate_earliest_date(record)

    expected = '2012-06-01'
    result = record['earliest_date']

    assert expected == result
コード例 #6
0
def test_populate_earliest_date_from_imprints_date():
    schema = load_schema('hep')
    subschema = schema['properties']['imprints']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'imprints': [
            {'date': '2014-09-26'},
        ],
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['imprints'], subschema) is None

    populate_earliest_date(record)

    expected = '2014-09-26'
    result = record['earliest_date']

    assert expected == result
コード例 #7
0
def test_populate_earliest_date_from_publication_info_year():
    schema = load_schema('hep')
    subschema = schema['properties']['publication_info']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'publication_info': [
            {'year': 2014},
        ],
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['publication_info'], subschema) is None

    populate_earliest_date(record)

    expected = '2014'
    result = record['earliest_date']

    assert expected == result
コード例 #8
0
def test_populate_earliest_date_from_thesis_info_defense_date():
    schema = load_schema('hep')
    subschema = schema['properties']['thesis_info']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'thesis_info': {
            'defense_date': '2012-06-01',
        },
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['thesis_info'], subschema) is None

    populate_earliest_date(record)

    expected = '2012-06-01'
    result = record['earliest_date']

    assert expected == result
コード例 #9
0
ファイル: receivers.py プロジェクト: theleestarr/inspire-next
def enhance_before_index(record):
    """Run all the receivers that enhance the record for ES in the right order.

    .. note::

       ``populate_recid_from_ref`` **MUST** come before ``populate_bookautocomplete``
       because the latter puts a JSON reference in a completion _source, which
       would be expanded to an incorrect ``_source_recid`` by the former.

    """
    populate_recid_from_ref(record)

    if is_hep(record):
        populate_abstract_source_suggest(record)
        populate_earliest_date(record)
        populate_author_count(record)
        populate_authors_full_name_unicode_normalized(record)
        populate_inspire_document_type(record)
        populate_name_variations(record)
        populate_number_of_references(record)
        populate_citations_count(record)
        populate_facet_author_name(record)
        populate_ui_display(record, RecordMetadataSchemaV1)

        if is_book(record):
            populate_bookautocomplete(record)

    elif is_author(record):
        populate_authors_name_variations(record)
        populate_author_suggest(record)

    elif is_institution(record):
        populate_affiliation_suggest(record)

    elif is_experiment(record):
        populate_experiment_suggest(record)

    elif is_journal(record):
        populate_title_suggest(record)

    elif is_data(record):
        populate_citations_count(record)