def test_prepare_files_ignores_keys_not_ending_with_pdf():
    data = {}
    extra_data = {}
    files = MockFiles({
        'foo.bar':
        AttrDict({
            'obj':
            AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

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

    assert prepare_files(obj, eng) is None

    expected = {}
    result = obj.data

    assert expected == result

    expected = ''
    result = obj.log._info.getvalue()

    assert expected == result
def test_prepare_files():
    data = {}
    extra_data = {}
    files = MockFiles({
        'foo.pdf': AttrDict({
            'obj': AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

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

    assert prepare_files(obj, eng) is None
    assert obj.data == {
        '_fft': [
            {
                'path': '/data/foo.pdf',
                'type': 'INSPIRE-PUBLIC',
                'filename': 'foo',
                'format': '.pdf',
            },
        ],
    }
    assert 'Non-user PDF files added to FFT.' == obj.log._info.getvalue()
    assert '/data/foo.pdf' in obj.log._debug.getvalue()
def test_prepare_files_annotates_files_from_arxiv():
    schema = load_schema('hep')
    _fft_schema = schema['properties']['_fft']
    arxiv_eprints_schema = schema['properties']['arxiv_eprints']

    data = {
        'arxiv_eprints': [
            {
                'categories': ['hep-th'],
                'value': 'hep-th/9711200',
            },
        ],
    }
    extra_data = {}
    files = MockFiles({
        'foo.pdf':
        AttrDict({
            'obj':
            AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })
    assert validate(data['arxiv_eprints'], arxiv_eprints_schema) is None

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

    assert prepare_files(obj, eng) is None

    expected_fft = [
        {
            'path': '/data/foo.pdf',
            'type': 'arXiv',
            'filename': 'arxiv:foo',
            'format': '.pdf',
        },
    ]
    expected_arxiv_eprints = [
        {
            'categories': [
                'hep-th',
            ],
            'value': 'hep-th/9711200',
        },
    ]
    result = obj.data

    assert validate(result['_fft'], _fft_schema) is None
    assert expected_fft == result['_fft']

    assert validate(result['arxiv_eprints'], arxiv_eprints_schema) is None
    assert expected_arxiv_eprints == result['arxiv_eprints']

    expected = 'Non-user PDF files added to FFT.'
    result = obj.log._info.getvalue()

    assert expected == result
Пример #4
0
def test_prepare_files():
    data = {}
    extra_data = {}
    files = StubFiles({
        'foo.pdf':
        AttrDict({
            'obj':
            AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

    obj = StubObj(data, extra_data, files)
    eng = DummyEng()

    assert prepare_files(obj, eng) is None
    assert obj.data == {
        'fft': [
            {
                'url': '/data/foo.pdf',
                'docfile_type': 'INSPIRE-PUBLIC',
                'filename': 'foo',
                'filetype': '.pdf',
            },
        ],
    }
    assert 'Non-user PDF files added to FFT.' == obj.log._info.getvalue()
    assert '/data/foo.pdf' in obj.log._debug.getvalue()
def test_prepare_files_does_nothing_when_obj_has_no_files():
    data = {}
    extra_data = {}
    files = MockFiles({})

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

    assert prepare_files(obj, eng) is None
    assert obj.data == {}
    assert '' == obj.log._info.getvalue()
    assert '' == obj.log._debug.getvalue()
Пример #6
0
def test_prepare_files_does_nothing_when_obj_has_no_files():
    data = {}
    extra_data = {}
    files = StubFiles({})

    obj = StubObj(data, extra_data, files)
    eng = DummyEng()

    assert prepare_files(obj, eng) is None
    assert obj.data == {}
    assert '' == obj.log._info.getvalue()
    assert '' == obj.log._debug.getvalue()
def test_prepare_files_skips_empty_files():
    data = {}
    extra_data = {}
    files = MockFiles({
        'foo.pdf': AttrDict({}),
    })

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

    assert prepare_files(obj, eng) is None
    assert obj.data == {}
    assert '' == obj.log._info.getvalue()
    assert '' == obj.log._debug.getvalue()
Пример #8
0
def test_prepare_files_skips_empty_files():
    data = {}
    extra_data = {}
    files = StubFiles({
        'foo.pdf': AttrDict({}),
    })

    obj = StubObj(data, extra_data, files)
    eng = DummyEng()

    assert prepare_files(obj, eng) is None
    assert obj.data == {}
    assert '' == obj.log._info.getvalue()
    assert '' == obj.log._debug.getvalue()
def test_prepare_files_does_nothing_when_obj_has_no_files():
    data = {}
    extra_data = {}
    files = MockFiles({})

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

    assert prepare_files(obj, eng) is None

    expected = {}
    result = obj.data

    assert expected == result

    expected = ''
    result = obj.log._info.getvalue()

    assert expected == result
def test_prepare_files_ignores_keys_not_ending_with_pdf():
    data = {}
    extra_data = {}
    files = MockFiles({
        'foo.bar': AttrDict({
            'obj': AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

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

    assert prepare_files(obj, eng) is None
    assert obj.data == {}
    assert '' == obj.log._info.getvalue()
    assert '' == obj.log._debug.getvalue()
def test_prepare_files_skips_empty_files():
    data = {}
    extra_data = {}
    files = MockFiles({
        'foo.pdf': AttrDict({}),
    })

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

    assert prepare_files(obj, eng) is None

    expected = {}
    result = obj.data

    assert expected == result

    expected = ''
    result = obj.log._info.getvalue()

    assert expected == result
def test_prepare_files():
    schema = load_schema('hep')
    subschema = schema['properties']['_fft']

    data = {}
    extra_data = {}
    files = MockFiles({
        'foo.pdf':
        AttrDict({
            'obj':
            AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

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

    assert prepare_files(obj, eng) is None

    expected = [
        {
            'path': '/data/foo.pdf',
            'type': 'INSPIRE-PUBLIC',
            'filename': 'foo',
            'format': '.pdf',
        },
    ]
    result = obj.data

    assert validate(result['_fft'], subschema) is None
    assert expected == result['_fft']

    expected = 'Non-user PDF files added to FFT.'
    result = obj.log._info.getvalue()

    assert expected == result
Пример #13
0
def test_prepare_files_ignores_keys_not_ending_with_pdf():
    data = {}
    extra_data = {}
    files = StubFiles({
        'foo.bar':
        AttrDict({
            'obj':
            AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

    obj = StubObj(data, extra_data, files)
    eng = DummyEng()

    assert prepare_files(obj, eng) is None
    assert obj.data == {}
    assert '' == obj.log._info.getvalue()
    assert '' == obj.log._debug.getvalue()
def test_prepare_files_annotates_files_from_arxiv():
    data = {
        'arxiv_eprints': [
            {'categories': 'hep-th'},
        ],
    }
    extra_data = {}
    files = MockFiles({
        'foo.pdf': AttrDict({
            'obj': AttrDict({
                'file': AttrDict({
                    'uri': '/data/foo.pdf',
                }),
            }),
        }),
    })

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

    assert prepare_files(obj, eng) is None
    assert obj.data == {
        'arxiv_eprints': [
            {'categories': 'hep-th'},
        ],
        '_fft': [
            {
                'path': '/data/foo.pdf',
                'type': 'arXiv',
                'filename': 'arxiv:foo',
                'format': '.pdf',
            },
        ],
    }
    assert 'Non-user PDF files added to FFT.' == obj.log._info.getvalue()
    assert '/data/foo.pdf' in obj.log._debug.getvalue()