def test_arxiv_package_download_logs_on_error(): with requests_mock.Mocker() as requests_mocker: requests_mocker.register_uri( 'GET', 'http://export.arxiv.org/e-print/1605.03951', status_code=500, ) schema = load_schema('hep') subschema = schema['properties']['arxiv_eprints'] data = { 'arxiv_eprints': [ { 'categories': [ 'astro-ph.HE', ], 'value': '1605.03951', }, ], } # literature/1458254 extra_data = {} files = MockFiles({}) assert validate(data['arxiv_eprints'], subschema) is None obj = MockObj(data, extra_data, files=files) eng = MockEng() assert arxiv_package_download(obj, eng) is None expected = 'Cannot retrieve tarball from arXiv for 1605.03951' result = obj.log._error.getvalue() assert expected == result
def test_arxiv_package_download_logs_on_success(): httpretty.register_uri(httpretty.GET, 'http://export.arxiv.org/e-print/1605.03959', body=pkg_resources.resource_string( __name__, os.path.join('fixtures', '1605.03959.tar.gz'))) schema = load_schema('hep') subschema = schema['properties']['arxiv_eprints'] data = { 'arxiv_eprints': [ { 'categories': [ 'hep-th', 'cond-mat.stat-mech', 'cond-mat.str-el', ], 'value': '1605.03959', }, ], } # literature/1458968 extra_data = {} files = MockFiles({}) assert validate(data['arxiv_eprints'], subschema) is None obj = MockObj(data, extra_data, files=files) eng = MockEng() assert arxiv_package_download(obj, eng) is None expected = 'Tarball retrieved from arXiv for 1605.03959' result = obj.log._info.getvalue() assert expected == result
def test_arxiv_package_download_logs_on_success(): with requests_mock.Mocker() as requests_mocker: requests_mocker.register_uri( 'GET', 'http://export.arxiv.org/e-print/1605.03959', content=pkg_resources.resource_string( __name__, os.path.join('fixtures', '1605.03959.tar.gz')), ) schema = load_schema('hep') subschema = schema['properties']['arxiv_eprints'] data = { 'arxiv_eprints': [ { 'categories': [ 'hep-th', 'cond-mat.stat-mech', 'cond-mat.str-el', ], 'value': '1605.03959', }, ], } # literature/1458968 extra_data = {} files = MockFiles({}) assert validate(data['arxiv_eprints'], subschema) is None obj = MockObj(data, extra_data, files=files) eng = MockEng() assert arxiv_package_download(obj, eng) is None expected = 'Tarball retrieved from arXiv for 1605.03959' result = obj.log._info.getvalue() assert expected == result