Esempio n. 1
0
 def _findFragmentNodesWithAboutUris(self, lxmlNode):
     for descriptionNode in xpath(lxmlNode, "*[@rdf:about]"):
         uri = str(descriptionNode.attrib[curieToTag("rdf:about")])
         yield descriptionNode, uri
     for statementNode in xpath(lxmlNode, "rdf:Statement"):
         uri = str(xpathFirst(statementNode, 'rdf:subject/@rdf:resource'))
         yield statementNode, uri
    def testSortKeysWithMissingValues(self):
        body = self.doSruQuery('*', sortKeys='field4,,1')
        records = xpath(body, '//srw:recordIdentifier/text()')
        self.assertEquals('record:1', records[0])

        body = self.doSruQuery('*', sortKeys='field4,,0')
        records = xpath(body, '//srw:recordIdentifier/text()')
        self.assertEquals('record:1', records[0])
    def testSortKeys(self):
        body = self.doSruQuery('*', sortKeys='intfield1,,1')
        records = xpath(body, '//srw:recordIdentifier/text()')
        self.assertEquals(['record:%s' % i for i in xrange(1,11)], records)

        body = self.doSruQuery('*', sortKeys='intfield1,,0')
        records = xpath(body, '//srw:recordIdentifier/text()')
        self.assertEquals(['record:%s' % i for i in xrange(100,90, -1)], records)
    def testMaximumRecords(self):
        body = self.doSruQuery('*', maximumRecords=20)
        records = xpath(body, '//srw:record')
        self.assertEquals(20, len(records))

        body = self.doSruQuery('*', maximumRecords=0, path='/via-remote-sru')
        records = xpath(body, '//srw:record')
        self.assertEquals(0, len(records))
        diag = xpathFirst(body, '//diag:diagnostic/diag:details/text()')
        self.assertEquals(None, diag)
Esempio n. 5
0
 def testGetRecordWithRepositoryIdentifierMissingExpectedPrefix(self):
     oaigetrecord = OaiGetRecord(OaiRepository(identifier="example.org"))
     result = asString(
         oaigetrecord.getRecord(
             arguments=dict(verb=["GetRecord"], metadataPrefix=["oai_dc"], identifier=["not:properly:prefixed:id0"]),
             **self.httpkwargs
         )
     )
     header, body = result.split("\r\n\r\n")
     self.assertTrue(xpath(XML(body), '/oai:OAI-PMH/oai:error[@code="idDoesNotExist"]'), body)
Esempio n. 6
0
 def testAddTwoRecordsWithSameUriAndDeleteLast(self):
     uri = "uri:someuri"
     rdfNode, description = createRdfNode(uri)
     createSubElement(description, "dc:title", text='One')
     consume(self.dna.all.add(identifier="identifier1", partname="ignored", lxmlNode=rdfNode.getroot()))
     rdfNode, description = createRdfNode(uri)
     createSubElement(description, "dc:title", text='Two')
     consume(self.dna.all.add(identifier="identifier2", partname="ignored", lxmlNode=rdfNode.getroot()))
     consume(self.dna.all.delete(identifier="identifier2"))
     record = self.oaiJazz.getRecord(identifier=uri)
     self.assertEquals(['One'], xpath(XML(self.storage.getData(identifier=record.identifier, name='rdf')), '/rdf:RDF/rdf:Description/dc:title/text()'))
Esempio n. 7
0
    def testGetRecordWithMultiSequentialStorage(self):
        oaijazz = OaiJazz(self.tempdir + "/jazz")
        storage = MultiSequentialStorage(self.tempdir + "/seq-store")
        oairecord = OaiRecord()
        oaigetrecord = be(
            (
                OaiGetRecord(repository=OaiRepository()),
                (oaijazz,),
                (oairecord, (RetrieveToGetDataAdapter(), (storage,))),
            )
        )

        oaijazz.addOaiRecord(identifier="id0", sets=(), metadataFormats=[("oai_dc", "", "")])
        storage.addData(identifier="id0", name="oai_dc", data="data01")
        response = oaigetrecord.getRecord(
            arguments=dict(verb=["GetRecord"], metadataPrefix=["oai_dc"], identifier=["id0"]), **self.httpkwargs
        )
        _, body = asString(response).split("\r\n\r\n")
        self.assertEquals("data01", xpath(parse(StringIO(body)), "//oai:metadata")[0].text)
Esempio n. 8
0
 def add(self, identifier, lxmlNode, *args, **kwargs):
     if xpath(lxmlNode, '/oai:record/oai:header[@status="deleted"]'):
         yield self.all.delete(identifier=identifier)
     else:
         yield self.all.add(identifier=identifier, partname='record', lxmlNode=lxmlNode)
 def testFacet(self):
     body = self.doSruQuery('*', facet='untokenized.field2')
     ddItems = xpath(body, "//drilldown:term-drilldown/drilldown:navigator[@name='untokenized.field2']/drilldown:item")
     self.assertEquals(
         set([('value0', '10'), ('value9', '10'), ('value8', '10'), ('value7', '10'), ('value6', '10'), ('value5', '10'), ('value4', '10'), ('value3', '10'), ('value2', '10'), ('value1', '9')]),
         set([(i.attrib['value'], i.attrib['count']) for i in ddItems]))
Esempio n. 10
0
 def testStartRecord(self):
     body = self.doSruQuery('*', maximumRecords=100)
     records = xpath(body, '//srw:recordIdentifier/text()')
     body = self.doSruQuery('*', maximumRecords=10, startRecord=51)
     self.assertEquals(records[50:60], xpath(body, '//srw:recordIdentifier/text()'))
Esempio n. 11
0
 def testRecordIds(self):
     body = self.doSruQuery('*', maximumRecords=100)
     records = xpath(body, '//srw:recordIdentifier/text()')
     self.assertEquals(100, len(records))
     self.assertEquals(set(['record:%s' % i for i in xrange(1,101)]), set(records))
Esempio n. 12
0
 def __iter__(self):
     for record in xpath(self._response, "/srw:searchRetrieveResponse/srw:records/srw:record"):
         yield SruRecord(record)
Esempio n. 13
0
 def testReificationWithBlankNodeSubject(self):
     testNamespaces = namespaces.copyUpdate(dict(test="urn:test#"))
     xpathFirst = testNamespaces.xpathFirst
     rdfXml = '''<rdf:RDF %(xmlns_rdf)s %(xmlns_test)s>
         <rdf:Description>
             <test:relation rdf:ID="_987">object</test:relation>
         </rdf:Description>
         <rdf:Statement rdf:about="#_987">
             <test:reificationRelation>reification object</test:reificationRelation>
         </rdf:Statement>
     </rdf:RDF>''' % testNamespaces
     graph = RDFParser().parse(XML(rdfXml))
     result = Triples2RdfXml(namespaces=testNamespaces).asRdfXml(graph)
     self.assertEquals('reification object', xpathFirst(result, '/rdf:RDF/rdf:Statement[@rdf:about="#_987"]/test:reificationRelation/text()'))
     self.assertEquals(None, xpathFirst(result, '/rdf:RDF/rdf:Statement[@rdf:about="#_987"]/rdf:subject'))  # rdf:Statement with bnode subject should not actually refer to it...!!
     self.assertEquals('object', xpathFirst(result, '/rdf:RDF/rdf:Description/test:relation[@rdf:ID="_987"]/text()'))
     self.assertEquals(['rdf:Description', 'rdf:Statement'], [tagToCurie(node.tag) for node in xpath(result, '/rdf:RDF/*')])
Esempio n. 14
0
 def testReificationWithRdfID(self):
     testNamespaces = namespaces.copyUpdate(dict(test="urn:test#"))
     xpathFirst = testNamespaces.xpathFirst
     rdfXml = '''<rdf:RDF %(xmlns_rdf)s %(xmlns_test)s>
         <rdf:Description rdf:about="some:uri">
             <test:relation rdf:ID="_987">object</test:relation>
         </rdf:Description>
         <rdf:Statement rdf:about="#_987">
             <test:reificationRelation>reification object</test:reificationRelation>
         </rdf:Statement>
     </rdf:RDF>''' % testNamespaces
     graph = RDFParser().parse(XML(rdfXml))
     result = Triples2RdfXml(namespaces=testNamespaces).asRdfXml(graph)
     self.assertEquals('object', xpathFirst(result, '/rdf:RDF/rdf:Description[@rdf:about="some:uri"]/test:relation[@rdf:ID="_987"]/text()'))
     self.assertEquals('reification object', xpathFirst(result, '/rdf:RDF/rdf:Statement[@rdf:about="#_987"]/test:reificationRelation/text()'))
     self.assertEquals(['rdf:Description', 'rdf:Statement'], [tagToCurie(node.tag) for node in xpath(result, '/rdf:RDF/*')])
     self.assertXmlEquals(rdfXml, result)