예제 #1
0
def test_abstract_loader_url_fallbacks(get_record, super_get_r_j, g_p_t_f_e):
    with_super = {'SUPER': 'SUPER'}
    with_actual = {'ACTUAL': 'ACTUAL'}
    g_p_t_f_e = 'pt'
    super_get_r_j.return_value = with_super
    get_record.return_value = with_actual

    # Check against prod SERVER_NAME
    config = {'SERVER_NAME': 'http://inspirehep.net'}

    with patch.dict(current_app.config, config):
        expect_actual = JsonRef({'$ref': 'http://inspirehep.net/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        expect_actual = JsonRef({'$ref': '/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        expect_super = JsonRef({'$ref': 'http://otherhost.net/api/e/1'},
                               loader=AbstractRecordLoader())
        assert expect_super == with_super

    # Check against dev SERVER_NAME
    config = {'SERVER_NAME': 'localhost:5000'}

    with patch.dict(current_app.config, config):
        expect_actual = JsonRef({'$ref': 'http://localhost:5000/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        expect_actual = JsonRef({'$ref': '/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        expect_super = JsonRef({'$ref': 'http://inspirehep.net/api/e/1'},
                               loader=AbstractRecordLoader())
        assert expect_super == with_super

    # Check against prod https SERVER_NAME
    config = {'SERVER_NAME': 'https://inspirehep.net'}

    with patch.dict(current_app.config, config):
        expect_actual = JsonRef({'$ref': 'https://inspirehep.net/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        expect_actual = JsonRef({'$ref': '/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        # https should be backwards compatible with resources indexed with http://.
        expect_actual = JsonRef({'$ref': 'http://inspirehep.net/api/e/1'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual

        expect_super = JsonRef({'$ref': 'http://otherhost.net/api/e/1'},
                               loader=AbstractRecordLoader())
        assert expect_super == with_super
예제 #2
0
def test_abstract_loader_return_none(get_record, current_app):
    current_app.config = {'SERVER_NAME': 'http://inspirehep.net'}

    expect_none = JsonRef({'$ref': 'http://inspirehep.net'},
                          loader=AbstractRecordLoader())
    assert expect_none == None
    expect_none = JsonRef({'$ref': 'http://inspirehep.net/'},
                          loader=AbstractRecordLoader())
    assert expect_none == None
    expect_none = JsonRef({'$ref': 'http://inspirehep.net/bad'},
                          loader=AbstractRecordLoader())
    assert expect_none == None
    assert get_record.call_count == 0
def test_abstract_loader_return_none(get_record):
    config = {'SERVER_NAME': 'http://inspirehep.net'}

    with patch.dict(current_app.config, config):
        expect_none = JsonRef({'$ref': 'http://inspirehep.net'},
                              loader=AbstractRecordLoader())
        assert expect_none == None  # noqa: E711
        expect_none = JsonRef({'$ref': 'http://inspirehep.net/'},
                              loader=AbstractRecordLoader())
        assert expect_none == None  # noqa: E711
        expect_none = JsonRef({'$ref': 'http://inspirehep.net/bad'},
                              loader=AbstractRecordLoader())
        assert expect_none == None  # noqa: E711
        assert get_record.call_count == 0
예제 #4
0
def test_abstract_loader_recid_parsing(get_record, current_app):
    current_app.config = {'SERVER_NAME': 'http://inspirehep.net'}
    with_actual = {'ACTUAL': 'ACTUAL'}
    get_record.return_value = with_actual

    expect_actual = JsonRef({'$ref': 'http://inspirehep.net/api/rt1/1'},
                            loader=AbstractRecordLoader())
    # Force evaluation of get_record by this assertion.
    assert expect_actual == with_actual
    get_record.assert_called_with('rt1', '1')

    expect_actual = JsonRef({'$ref': '/api/rt2/2'},
                            loader=AbstractRecordLoader())
    assert expect_actual == with_actual
    get_record.assert_called_with('rt2', '2')

    expect_actual = JsonRef({'$ref': '/rt3/3/'},
                            loader=AbstractRecordLoader())
    assert expect_actual == with_actual
    get_record.assert_called_with('rt3', '3')
예제 #5
0
def test_abstract_loader_recid_parsing(get_record, g_p_t_f_e):
    with_actual = {'ACTUAL': 'ACTUAL'}
    g_p_t_f_e.side_effect = ['pt1', 'pt2', 'pt3']
    get_record.return_value = with_actual

    config = {'SERVER_NAME': 'http://inspirehep.net'}

    with patch.dict(current_app.config, config):
        expect_actual = JsonRef({'$ref': 'http://inspirehep.net/api/e1/1'},
                                loader=AbstractRecordLoader())
        # Force evaluation of get_record by this assertion.
        assert expect_actual == with_actual
        get_record.assert_called_with('pt1', '1')

        expect_actual = JsonRef({'$ref': '/api/e2/2'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual
        get_record.assert_called_with('pt2', '2')

        expect_actual = JsonRef({'$ref': '/e3/3/'},
                                loader=AbstractRecordLoader())
        assert expect_actual == with_actual
        get_record.assert_called_with('pt3', '3')