Пример #1
0
def test_identify(app):
    """Test Identify verb."""
    # baseUrls for friends element
    baseUrls = ['http://example.org/1', 'http://example.org/2']
    # parameters for eprints element
    content = {'URL': 'http://arXiv.org/arXiv_content.htm'}
    metadataPolicy = {
        'text': 'Metadata can be used by commercial'
        'and non-commercial service providers',
        'URL': 'http://arXiv.org/arXiv_metadata_use.htm'
    }
    dataPolicy = {
        'text': 'Full content, i.e. preprints may'
        'not be harvested by robots'
    }
    submissionPolicy = {'URL': 'http://arXiv.org/arXiv_submission.htm'}
    # parameters for oai-identifier element
    scheme = 'oai'
    repositoryIdentifier = 'oai-stuff.foo.org'
    delimiter = ':'
    sampleIdentifier = 'oai:oai-stuff.foo.org:5324'

    app.config['OAISERVER_DESCRIPTIONS'] = \
        [friends_description(baseUrls),
         eprints_description(metadataPolicy, dataPolicy,
                             submissionPolicy, content),
         oai_identifier_description(scheme, repositoryIdentifier, delimiter,
                                    sampleIdentifier)]

    with app.test_client() as c:
        result = c.get('/oai2d?verb=Identify')
        assert 200 == result.status_code

        tree = etree.fromstring(result.data)

        assert len(tree.xpath('/x:OAI-PMH', namespaces=NAMESPACES)) == 1
        assert len(tree.xpath('/x:OAI-PMH/x:Identify',
                              namespaces=NAMESPACES)) == 1
        repository_name = tree.xpath('/x:OAI-PMH/x:Identify/x:repositoryName',
                                     namespaces=NAMESPACES)
        assert len(repository_name) == 1
        assert repository_name[0].text == 'Invenio-OAIServer'
        base_url = tree.xpath('/x:OAI-PMH/x:Identify/x:baseURL',
                              namespaces=NAMESPACES)
        assert len(base_url) == 1
        assert base_url[0].text == 'http://app/oai2d'
        protocolVersion = tree.xpath('/x:OAI-PMH/x:Identify/x:protocolVersion',
                                     namespaces=NAMESPACES)
        assert len(protocolVersion) == 1
        assert protocolVersion[0].text == '2.0'
        adminEmail = tree.xpath('/x:OAI-PMH/x:Identify/x:adminEmail',
                                namespaces=NAMESPACES)
        assert len(adminEmail) == 1
        assert adminEmail[0].text == '*****@*****.**'
        earliestDatestamp = tree.xpath(
            '/x:OAI-PMH/x:Identify/x:earliestDatestamp', namespaces=NAMESPACES)
        assert len(earliestDatestamp) == 1
        deletedRecord = tree.xpath('/x:OAI-PMH/x:Identify/x:deletedRecord',
                                   namespaces=NAMESPACES)
        assert len(deletedRecord) == 1
        assert deletedRecord[0].text == 'no'
        granularity = tree.xpath('/x:OAI-PMH/x:Identify/x:granularity',
                                 namespaces=NAMESPACES)
        assert len(granularity) == 1
        description = tree.xpath('/x:OAI-PMH/x:Identify/x:description',
                                 namespaces=NAMESPACES)

        friends_element = description[0]
        for element in friends_element.getchildren():
            for child in element.getchildren():
                assert child.tag == \
                    '{http://www.openarchives.org/OAI/2.0/friends/}baseURL'
                assert child.text in baseUrls

        eprints_root = description[1]
        children = eprints_root[0].getchildren()
        assert children[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}content'
        leaves = children[0].getchildren()
        assert len(leaves) == 1
        assert leaves[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}URL'
        assert leaves[0].text == content['URL']

        assert children[1].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}metadataPolicy'
        leaves = children[1].getchildren()
        assert len(leaves) == 2
        metadataPolicyContents = \
            ['{http://www.openarchives.org/OAI/2.0/eprints}text',
             '{http://www.openarchives.org/OAI/2.0/eprints}URL']
        assert set([leaves[0].tag, leaves[1].tag]) == \
            set(metadataPolicyContents)
        assert set([leaves[0].text, leaves[1].text]) == \
            set(metadataPolicy.values())
        assert children[2].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}dataPolicy'
        leaves = children[2].getchildren()
        assert len(leaves) == 1
        assert leaves[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}text'
        assert leaves[0].text == dataPolicy['text']

        assert children[3].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}submissionPolicy'
        leaves = children[3].getchildren()
        assert len(leaves) == 1
        assert leaves[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}URL'
        assert leaves[0].text == submissionPolicy['URL']

        oai_identifier_root = description[2]
        children = oai_identifier_root[0].getchildren()
        assert children[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}scheme'
        assert children[0].text == scheme
        assert children[1].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}' + \
            'repositoryIdentifier'
        assert children[1].text == repositoryIdentifier
        assert children[2].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}' + \
            'delimiter'
        assert children[2].text == delimiter
        assert children[3].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}' + \
            'sampleIdentifier'
        assert children[3].text == sampleIdentifier
Пример #2
0
def test_identify(app):
    """Test Identify verb."""
    # baseUrls for friends element
    baseUrls = ['http://example.org/1',
                'http://example.org/2']
    # parameters for eprints element
    content = {'URL': 'http://arXiv.org/arXiv_content.htm'}
    metadataPolicy = {'text': 'Metadata can be used by commercial'
                      'and non-commercial service providers',
                      'URL': 'http://arXiv.org/arXiv_metadata_use.htm'}
    dataPolicy = {'text': 'Full content, i.e. preprints may'
                  'not be harvested by robots'}
    submissionPolicy = {'URL': 'http://arXiv.org/arXiv_submission.htm'}
    # parameters for oai-identifier element
    scheme = 'oai'
    repositoryIdentifier = 'oai-stuff.foo.org'
    delimiter = ':'
    sampleIdentifier = 'oai:oai-stuff.foo.org:5324'

    app.config['OAISERVER_DESCRIPTIONS'] = \
        [friends_description(baseUrls),
         eprints_description(metadataPolicy, dataPolicy,
                             submissionPolicy, content),
         oai_identifier_description(scheme, repositoryIdentifier, delimiter,
                                    sampleIdentifier)]

    with app.test_client() as c:
        result = c.get('/oai2d?verb=Identify')
        assert 200 == result.status_code

        tree = etree.fromstring(result.data)

        assert len(tree.xpath('/x:OAI-PMH', namespaces=NAMESPACES)) == 1
        assert len(tree.xpath('/x:OAI-PMH/x:Identify',
                              namespaces=NAMESPACES)) == 1
        repository_name = tree.xpath('/x:OAI-PMH/x:Identify/x:repositoryName',
                                     namespaces=NAMESPACES)
        assert len(repository_name) == 1
        assert repository_name[0].text == 'Invenio-OAIServer'
        base_url = tree.xpath('/x:OAI-PMH/x:Identify/x:baseURL',
                              namespaces=NAMESPACES)
        assert len(base_url) == 1
        assert base_url[0].text == 'http://app/oai2d'
        protocolVersion = tree.xpath(
            '/x:OAI-PMH/x:Identify/x:protocolVersion',
            namespaces=NAMESPACES)
        assert len(protocolVersion) == 1
        assert protocolVersion[0].text == '2.0'
        adminEmail = tree.xpath('/x:OAI-PMH/x:Identify/x:adminEmail',
                                namespaces=NAMESPACES)
        assert len(adminEmail) == 1
        assert adminEmail[0].text == '*****@*****.**'
        earliestDatestamp = tree.xpath(
            '/x:OAI-PMH/x:Identify/x:earliestDatestamp',
            namespaces=NAMESPACES)
        assert len(earliestDatestamp) == 1
        deletedRecord = tree.xpath('/x:OAI-PMH/x:Identify/x:deletedRecord',
                                   namespaces=NAMESPACES)
        assert len(deletedRecord) == 1
        assert deletedRecord[0].text == 'no'
        granularity = tree.xpath('/x:OAI-PMH/x:Identify/x:granularity',
                                 namespaces=NAMESPACES)
        assert len(granularity) == 1
        description = tree.xpath('/x:OAI-PMH/x:Identify/x:description',
                                 namespaces=NAMESPACES)

        friends_element = description[0]
        for element in friends_element.getchildren():
            for child in element.getchildren():
                assert child.tag == \
                    '{http://www.openarchives.org/OAI/2.0/friends/}baseURL'
                assert child.text in baseUrls

        eprints_root = description[1]
        children = eprints_root[0].getchildren()
        assert children[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}content'
        leaves = children[0].getchildren()
        assert len(leaves) == 1
        assert leaves[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}URL'
        assert leaves[0].text == content['URL']

        assert children[1].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}metadataPolicy'
        leaves = children[1].getchildren()
        assert len(leaves) == 2
        metadataPolicyContents = \
            ['{http://www.openarchives.org/OAI/2.0/eprints}text',
             '{http://www.openarchives.org/OAI/2.0/eprints}URL']
        assert set([leaves[0].tag, leaves[1].tag]) == \
            set(metadataPolicyContents)
        assert set([leaves[0].text, leaves[1].text]) == \
            set(metadataPolicy.values())
        assert children[2].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}dataPolicy'
        leaves = children[2].getchildren()
        assert len(leaves) == 1
        assert leaves[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}text'
        assert leaves[0].text == dataPolicy['text']

        assert children[3].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}submissionPolicy'
        leaves = children[3].getchildren()
        assert len(leaves) == 1
        assert leaves[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/eprints}URL'
        assert leaves[0].text == submissionPolicy['URL']

        oai_identifier_root = description[2]
        children = oai_identifier_root[0].getchildren()
        assert children[0].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}scheme'
        assert children[0].text == scheme
        assert children[1].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}' + \
            'repositoryIdentifier'
        assert children[1].text == repositoryIdentifier
        assert children[2].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}' + \
            'delimiter'
        assert children[2].text == delimiter
        assert children[3].tag == \
            '{http://www.openarchives.org/OAI/2.0/oai-identifier}' + \
            'sampleIdentifier'
        assert children[3].text == sampleIdentifier