def test_model_based_utf8_harvesting(app, sample_config,
                                     sample_record_xml_utf8):
    """Test harvesting using model encoded in utf-8."""
    responses.add(responses.GET,
                  'http://export.arxiv.org/oai2',
                  body=sample_record_xml_utf8,
                  content_type='text/xml;charset=utf-8')

    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1207.1019'],
                                 name=sample_config)
        record = records.pop()
        assert record.raw.find(u'Stéphane') >= 0
    responses.remove(responses.GET, 'http://export.arxiv.org/oai2')
    responses.add(responses.GET,
                  'http://export.arxiv.org/oai2',
                  body=sample_record_xml_utf8,
                  content_type='text/xml')

    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1207.1019'],
                                 name=sample_config,
                                 encoding='utf-8')
        record = records.pop()
        assert record.raw.find(u'Stéphane') >= 0
def test_raise_missing_info(app):
    """Check that the proper exception is raised if name or url is missing."""
    from invenio_oaiharvester.errors import NameOrUrlMissing

    with app.app_context():
        with pytest.raises(NameOrUrlMissing):
            list_records()
        with pytest.raises(NameOrUrlMissing):
            get_records([])
def test_raise_missing_info(app):
    """Check that the proper exception is raised if name or url is missing."""
    from invenio_oaiharvester.errors import NameOrUrlMissing

    with app.app_context():
        with pytest.raises(NameOrUrlMissing):
            list_records()
        with pytest.raises(NameOrUrlMissing):
            get_records([])
def test_model_based_harvesting(app, sample_config, sample_record_xml):
    """Test harvesting using model."""
    responses.add(responses.GET,
                  'http://export.arxiv.org/oai2',
                  body=sample_record_xml,
                  content_type='text/xml')

    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1507.03011'],
                                 name=sample_config)
        assert len(records) == 1
def test_model_based_harvesting(app, sample_config, sample_record_xml):
    """Test harvesting using model."""
    responses.add(
        responses.GET,
        'http://export.arxiv.org/oai2',
        body=sample_record_xml,
        content_type='text/xml'
    )

    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1507.03011'],
                                 name=sample_config)
        assert len(records) == 1
def test_get_from_identifiers(app, sample_record_xml_oai_dc):
    """Test that getting records via identifiers work."""
    responses.add(responses.GET,
                  'http://export.arxiv.org/oai2',
                  body=sample_record_xml_oai_dc,
                  content_type='text/xml')
    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1507.03011'],
                                 url='http://export.arxiv.org/oai2')
        for rec in records:
            identifier_in_request = rec.xml.xpath(
                "//dc:identifier",
                namespaces={"dc": "http://purl.org/dc/elements/1.1/"})[0].text
            assert identifier_in_request == "http://arxiv.org/abs/1507.03011"
def test_get_from_identifiers_with_prefix(app, sample_record_xml):
    """Test that getting records via identifiers work with prefix."""
    responses.add(responses.GET,
                  'http://export.arxiv.org/oai2',
                  body=sample_record_xml,
                  content_type='text/xml')
    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1507.03011'],
                                 metadata_prefix="arXiv",
                                 url='http://export.arxiv.org/oai2')
        for rec in records:
            identifier_in_request = rec.xml.xpath(
                "//arXiv:id",
                namespaces={"arXiv": "http://arxiv.org/OAI/arXiv/"})[0].text
            assert identifier_in_request == "1507.03011"
def test_get_from_identifiers(app, sample_record_xml_oai_dc):
    """Test that getting records via identifiers work."""
    responses.add(
        responses.GET,
        'http://export.arxiv.org/oai2',
        body=sample_record_xml_oai_dc,
        content_type='text/xml'
    )
    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1507.03011'],
                                 url='http://export.arxiv.org/oai2')
        for rec in records:
            identifier_in_request = rec.xml.xpath(
                "//dc:identifier",
                namespaces={"dc": "http://purl.org/dc/elements/1.1/"}
            )[0].text
            assert identifier_in_request == "http://arxiv.org/abs/1507.03011"
def test_get_from_identifiers_with_prefix(app, sample_record_xml):
    """Test that getting records via identifiers work with prefix."""
    responses.add(
        responses.GET,
        'http://export.arxiv.org/oai2',
        body=sample_record_xml,
        content_type='text/xml'
    )
    with app.app_context():
        _, records = get_records(['oai:arXiv.org:1507.03011'],
                                 metadata_prefix="arXiv",
                                 url='http://export.arxiv.org/oai2')
        for rec in records:
            identifier_in_request = rec.xml.xpath(
                "//arXiv:id",
                namespaces={"arXiv": "http://arxiv.org/OAI/arXiv/"}
            )[0].text
            assert identifier_in_request == "1507.03011"