Пример #1
0
def test_halt_record_accepts_custom_msg():
    obj = MockObj({}, {})
    eng = MockEng()

    bar_message_halt_record = halt_record(message='bar')

    assert bar_message_halt_record(obj, eng) is None
    assert eng.msg == 'bar'
def test_mark():
    obj = MockObj({}, {})
    eng = MockEng()

    foobar_mark = mark('foo', 'bar')

    assert foobar_mark(obj, eng) is None
    assert obj.extra_data == {'foo': 'bar'}
Пример #3
0
def test_mark_overwrites():
    obj = MockObj({}, {'foo': 'bar'})
    eng = MockEng()

    foobaz_mark = mark('foo', 'baz')

    assert foobaz_mark(obj, eng) is None
    assert obj.extra_data == {'foo': 'baz'}
Пример #4
0
def test_halt_record_accepts_custom_action():
    obj = MockObj({}, {})
    eng = MockEng()

    foo_action_halt_record = halt_record(action='foo')

    assert foo_action_halt_record(obj, eng) is None
    assert eng.action == 'foo'
Пример #5
0
def test_is_fuzzy_match_approved_returns_true_if_there_is_a_match_approved(mock_match):
    data = {}
    extra_data = {'fuzzy_match_approved_id': 4328}

    obj = MockObj(data, extra_data)
    eng = MockEng()

    assert is_fuzzy_match_approved(obj, eng)
Пример #6
0
def test_is_fuzzy_match_approved_returns_False_if_there_is_not_a_match_approved(mock_match):
    data = {}
    extra_data = {}

    obj = MockObj(data, extra_data)
    eng = MockEng()

    assert not is_fuzzy_match_approved(obj, eng)
def test_new_ticket_context(data, extra_data, user):
    obj = MockObj(data, extra_data)
    ctx = new_ticket_context(user, obj)

    assert isinstance(ctx['object'], MockObj)
    assert ctx['email'] == '*****@*****.**'
    assert ctx['subject'] == 'Your suggestion to INSPIRE: author John Doe'
    assert ctx['user_comment'] == 'Foo bar'
def test_reply_ticket_context(data, extra_data, user):
    obj = MockObj(data, extra_data)
    ctx = reply_ticket_context(user, obj)
    assert isinstance(ctx['object'], MockObj)
    assert isinstance(ctx['user'], User)
    assert ctx['author_name'] == 'John Doe'
    assert ctx['reason'] == 'Test reason'
    assert ctx['record_url'] == 'http://example.com'
def test_guess_experiments_fails_without_a_magpie_url(g_m_u):
    g_m_u.return_value = None

    obj = MockObj({}, {})
    eng = MockEng()

    assert guess_experiments(obj, eng) is None
    assert obj.extra_data == {}
def test_prepare_update_payload_overwrites():
    obj = MockObj({'bar': 'baz'}, {'foo': 'foo'})
    eng = MockEng()

    foo_prepare_update_payload = prepare_update_payload('foo')

    assert foo_prepare_update_payload(obj, eng) is None
    assert obj.extra_data['foo'] == {'bar': 'baz'}
def test_prepare_update_payload_accepts_a_custom_key():
    obj = MockObj({}, {})
    eng = MockEng()

    custom_key_prepare_update_payload = prepare_update_payload('custom_key')

    assert custom_key_prepare_update_payload(obj, eng) is None
    assert obj.extra_data['custom_key'] == {}
def test_prepare_update_payload():
    obj = MockObj({}, {})
    eng = MockEng()

    default_prepare_update_payload = prepare_update_payload()

    assert default_prepare_update_payload(obj, eng) is None
    assert obj.extra_data['update_payload'] == {}
def test_fuzzy_match_returns_true_if_something_matched_with_more_than_1_public_notes(
        mock_match, enable_fuzzy_matcher):
    schema = load_schema('hep')
    public_notes_schema = schema['properties']['public_notes']
    titles_schema = schema['properties']['titles']

    matched_record = {
        'control_number':
        1472986,
        'titles': [
            {
                'title': 'title',
            },
        ],
        'public_notes': [
            {
                'source': 'arXiv',
                'value': '4 pages, 4 figures',
            },
            {
                'source': 'arXiv',
                'value': 'Some other public note',
            },
        ],
    }

    assert validate(matched_record['titles'], titles_schema) is None
    assert validate(matched_record['public_notes'],
                    public_notes_schema) is None

    mock_match.return_value = iter([{'_source': matched_record}])

    data = {}
    extra_data = {}

    obj = MockObj(data, extra_data)
    eng = MockEng()

    assert fuzzy_match(obj, eng)
    assert 'matches' in obj.extra_data

    expected = [{
        'control_number':
        1472986,
        'title':
        'title',
        'public_notes': [
            {
                'value': '4 pages, 4 figures'
            },
            {
                'value': 'Some other public note'
            },
        ],
    }]
    result = get_value(obj.extra_data, 'matches.fuzzy')

    assert expected == result
Пример #14
0
def test_arxiv_author_list_handles_multiple_author_xml_files():
    schema = load_schema('hep')
    eprints_subschema = schema['properties']['arxiv_eprints']

    filename = pkg_resources.resource_filename(
        __name__, os.path.join('fixtures', '1703.09986.multiple_author_lists.tar.gz'))

    data = {
        '$schema': 'http://localhost:5000/hep.json',
        'arxiv_eprints': [
            {
                'categories': [
                    'hep-ex',
                ],
                'value': '1703.09986',
            },
        ],
    }  # record/1519995
    validate(data['arxiv_eprints'], eprints_subschema)

    extra_data = {}
    files = MockFiles({
        '1703.09986.tar.gz': AttrDict({
            'file': AttrDict({
                'uri': filename,
            })
        })
    })

    obj = MockObj(data, extra_data, files=files)
    eng = MockEng()

    default_arxiv_author_list = arxiv_author_list()
    default_arxiv_author_list(obj, eng)

    authors_subschema = schema['properties']['authors']
    expected_authors = [
        {
            'affiliations': [{'value': 'Yerevan Phys. Inst.'}],
            'ids': [
                {'value': 'INSPIRE-00312131', 'schema': 'INSPIRE ID'},
                {'value': 'CERN-432142', 'schema': 'CERN'},
            ],
            'full_name': 'Sirunyan, Albert M',
        },
        {
            'affiliations': [{'value': 'Yerevan Phys. Inst.'}],
            'ids': [
                {'value': 'INSPIRE-00312132', 'schema': 'INSPIRE ID'},
                {'value': 'CERN-432143', 'schema': 'CERN'},
            ],
            'full_name': 'Weary, Jake',
        }
    ]
    validate(expected_authors, authors_subschema)

    assert obj.data.get('authors') == expected_authors
def test_halt_record():
    obj = MockObj({}, {'halt_action': 'foo', 'halt_message': 'bar'})
    eng = MockEng()

    default_halt_record = halt_record()

    assert default_halt_record(obj, eng) is None
    assert eng.action == 'foo'
    assert eng.msg == 'bar'
def test_preserve_root():
    config = {'FEATURE_FLAG_ENABLE_MERGER': True}

    with patch.dict(current_app.config, config):
        obj = MockObj({'foo': 'bar'}, {})
        eng = MockEng()

        assert preserve_root(obj, eng) is None
        assert obj.extra_data['merger_root'] == {'foo': 'bar'}
Пример #17
0
def test_guess_keywords_does_not_fail_when_request_fails(j_a_r, g_m_u):
    j_a_r.side_effect = requests.exceptions.RequestException()
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = MockObj({}, {})
    eng = MockEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data == {}
Пример #18
0
def test_new_ticket_context_handles_unicode(unicode_data, extra_data, user):
    obj = MockObj(unicode_data, extra_data)
    ctx = new_ticket_context(user, obj)

    assert isinstance(ctx['object'], MockObj)
    assert ctx['email'] == '*****@*****.**'
    assert ctx[
        'subject'] == u'Your suggestion to INSPIRE: author Diego Martínez'
    assert ctx['user_comment'] == 'Foo bar'
Пример #19
0
def test_curation_ticket_context(data, extra_data, user):
    obj = MockObj(data, extra_data)
    ctx = curation_ticket_context(user, obj)
    assert isinstance(ctx['object'], MockObj)
    assert ctx['recid'] == 123
    assert ctx['user_comment'] == 'Foo bar'
    assert ctx['subject'] == 'Curation needed for author John Doe [John.Doe.1]'
    assert ctx['email'] == '*****@*****.**'
    assert ctx['record_url'] == 'http://example.com'
Пример #20
0
def test_guess_coreness_does_not_fail_when_request_fails(j_a_r, g_b_u):
    j_a_r.side_effect = requests.exceptions.RequestException()
    g_b_u.return_value = 'https://beard.inspirehep.net/predictor/coreness'

    obj = MockObj({}, {})
    eng = MockEng()

    assert guess_coreness(obj, eng) is None
    assert 'relevance_prediction' not in obj.extra_data
Пример #21
0
def test_is_experimental_paper():
    obj = MockObj({'arxiv_eprints': [
        {
            'categories': ['hep-ex']
        },
    ]}, {})
    eng = MockEng()

    assert is_experimental_paper(obj, eng)
def test_set_exact_match_as_approved_in_extradata_no_exact_key_raises_exception(
):
    data = {}
    extra_data = {'matches': {'wrongkey': [1]}}

    obj = MockObj(data, extra_data)
    eng = MockEng()
    with pytest.raises(KeyError):
        set_exact_match_as_approved_in_extradata(obj, eng)
def test_set_exact_match_as_approved_in_extradata_with_empty_list_raises_exception(
):
    data = {}
    extra_data = {'matches': {'exact': []}}

    obj = MockObj(data, extra_data)
    eng = MockEng()
    with pytest.raises(IndexError):
        set_exact_match_as_approved_in_extradata(obj, eng)
def test_curation_ticket_context():
    data = {
        'arxiv_eprints': [
            {
                'value': 'math.GT/0309136',
            },
            {
                'value': '0706.0001v1',
            },
        ],
        'report_numbers': [
            {
                'value': 'foo',
            },
        ],
        'dois': [
            {
                'value': 'bar',
            },
        ],
    }
    extra_data = {
        'recid': 'baz',
        'url': 'qux',
        'formdata': {
            'url': 'quux',
            'references': [
                'plugh',
            ],
            'extra_comments': [
                'xyzzy',
            ]
        }
    }

    obj = MockObj(data, extra_data)
    user = MockUser('*****@*****.**')

    expected = {
        'recid': 'baz',
        'record_url': 'qux',
        'link_to_pdf': 'quux',
        'email': '*****@*****.**',
        'references': [
            'plugh',
        ],
        'user_comment': [
            'xyzzy',
        ],
        'server_name': 'localhost:5000',
        'subject': 'math.GT/0309136 arXiv:0706.0001v1 doi:bar foo (#baz)',
        'legacy_url': 'https://old.inspirehep.net',
    }
    result = curation_ticket_context(user, obj)

    assert expected == result
Пример #25
0
def test_arxiv_plot_extract_is_safe_to_rerun(mock_os, tmpdir):
    schema = load_schema('hep')
    subschema = schema['properties']['arxiv_eprints']

    filename = pkg_resources.resource_filename(
        __name__, os.path.join('fixtures', '0804.1873.tar.gz'))

    data = {
        'arxiv_eprints': [
            {
                'categories': [
                    'nucl-ex',
                ],
                'value': '0804.1873',
            },
        ],
    }  # literature/783246
    extra_data = {}
    files = MockFiles({
        '0804.1873.tar.gz':
        AttrDict({
            'file': AttrDict({
                'uri': filename,
            }),
        }),
    })
    assert validate(data['arxiv_eprints'], subschema) is None

    obj = MockObj(data, extra_data, files=files)
    eng = MockEng()

    temporary_dir = tmpdir.mkdir('plots')
    mock_os.path.abspath.return_value = str(temporary_dir)

    for _ in range(2):
        assert arxiv_plot_extract(obj, eng) is None

        expected_figures = [{
            'url':
            '/api/files/0b9dd5d1-feae-4ba5-809d-3a029b0bc110/figure1.png',
            'source':
            'arxiv',
            'material':
            'preprint',
            'key':
            'figure1.png',
            'caption':
            'Difference (in MeV) between the theoretical and experimental masses for the 2027 selected nuclei as a function of the mass number.'
        }]
        result = obj.data['figures']

        assert expected_figures == result

        expected_files = ['0804.1873.tar.gz', 'figure1.png']

        assert expected_files == obj.files.keys
def test_pending_in_holding_pen_returns_false_if_nothing_matched(mock_match):
    mock_match.return_value = iter([])

    data = {}
    extra_data = {}

    obj = MockObj(data, extra_data)
    eng = MockEng()

    assert not _pending_in_holding_pen(obj, eng)
def test_pending_in_holding_pen_returns_true_if_something_matched(mock_match):
    mock_match.return_value = iter([{'_id': 1}])

    data = {}
    extra_data = {}

    obj = MockObj(data, extra_data, id=2)
    eng = MockEng()

    assert _pending_in_holding_pen(obj, eng)
Пример #28
0
def test_curation_ticket_context_handles_unicode(unicode_data, extra_data,
                                                 user):
    obj = MockObj(unicode_data, extra_data)
    ctx = curation_ticket_context(user, obj)
    assert isinstance(ctx['object'], MockObj)
    assert ctx['user_comment'] == 'Foo bar'
    assert ctx[
        'subject'] == u'Curation needed for author Diego Martínez [Diego.Martinez.Santos.1]'
    assert ctx['email'] == '*****@*****.**'
    assert ctx['record_url'] == 'http://example.com'
def test_set_exact_match_as_approved_in_extradata():
    data = {}
    extra_data = {'matches': {'exact': [1, 2]}}

    obj = MockObj(data, extra_data)
    eng = MockEng()

    set_exact_match_as_approved_in_extradata(obj, eng)

    assert get_value(obj.extra_data, 'matches.approved') is 1
Пример #30
0
def test_fuzzy_match_returns_true_if_something_matched_with_publication_info(mock_match, enable_fuzzy_matcher):
    schema = load_schema('hep')
    publication_info_schema = schema['properties']['publication_info']
    titles_schema = schema['properties']['titles']

    matched_record = {
        'control_number': 1472986,
        'titles': [
            {
                'title': 'title',
            },
        ],
        'publication_info': [
            {
                'artid': '054021',
                'journal_issue': '5',
                'journal_title': 'Phys.Rev.D',
                'journal_volume': '94',
                'pubinfo_freetext': 'Phys. Rev. D94 (2016) 054021',
                'year': 2016
            },
        ],
    }

    assert validate(matched_record['titles'], titles_schema) is None
    assert validate(matched_record['publication_info'], publication_info_schema) is None

    mock_match.return_value = iter([{'_source': matched_record}])

    data = {}
    extra_data = {}

    obj = MockObj(data, extra_data)
    eng = MockEng()

    assert fuzzy_match(obj, eng)
    assert 'matches' in obj.extra_data

    expected = [{
        'control_number': 1472986,
        'title': 'title',
        'publication_info': [
            {
                'artid': '054021',
                'journal_issue': '5',
                'journal_title': 'Phys.Rev.D',
                'journal_volume': '94',
                'pubinfo_freetext': 'Phys. Rev. D94 (2016) 054021',
                'year': 2016
            },
        ],
    }]
    result = get_value(obj.extra_data, 'matches.fuzzy')

    assert expected == result