def oaiResult(adds, deletes): oaipmhNode = createElement('oai:OAI-PMH') listRecords = createSubElement(oaipmhNode, 'oai:ListRecords') for i in range(adds + deletes): record = createSubElement(listRecords, 'oai:record') attrib = {'status': 'deleted'} if i >= adds else {} createSubElement(record, 'oai:header', attrib=attrib) return oaipmhNode
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()'))
def testAddSetInfo(self): record = createElement("oai:record") header = createSubElement(record, "oai:header") createSubElement(header, "oai:setSpec", text="1") consume(self.subject.add("123", "oai_dc", record)) self.assertEquals(["addOaiRecord"], self.observer.calledMethodNames()) self.assertEquals("123", self.observer.calledMethods[0].kwargs["identifier"]) self.assertEquals(set([("1", "1")]), self.observer.calledMethods[0].kwargs["sets"]) self.assertEquals( [("oai_dc", "", "http://www.openarchives.org/OAI/2.0/")], self.observer.calledMethods[0].kwargs["metadataFormats"], )
def testCreateElement(self): dc = createElement('oai_dc:dc', nsmap=namespaces.select('oai_dc', 'dc')) createSubElement(dc, 'dc:title', text='<title>') self.assertXmlEquals( '<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title><title></dc:title></oai_dc:dc>', dc) self.assertXmlEquals( '<dc:iets xmlns:dc="http://purl.org/dc/elements/1.1/" key="<"value">">te"xt</dc:iets>', createElement('dc:iets', attrib={'key': '<"value">'}, text='te"xt', nsmap=namespaces.select('dc')))
def testAddSetInfo(self): record = createElement('oai:record') header = createSubElement(record, 'oai:header') createSubElement(header, 'oai:setSpec', text='1') consume(self.subject.add('123', 'oai_dc', record)) self.assertEqual(['updateSet', 'updateMetadataFormat', 'addOaiRecord'], self.observer.calledMethodNames()) self.assertEqual('123', self.observer.calledMethods[2].kwargs['identifier']) self.assertEqual({ 'setSpec': '1', 'setName': '1' }, self.observer.calledMethods[0].kwargs) self.assertEqual( { 'prefix': 'oai_dc', 'schema': '', 'namespace': "http://www.openarchives.org/OAI/2.0/" }, self.observer.calledMethods[1].kwargs)
def testCreateElement(self): dc = createElement('oai_dc:dc', nsmap=namespaces.select('oai_dc', 'dc')) createSubElement(dc, 'dc:title', text='<title>') self.assertXmlEquals('<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title><title></dc:title></oai_dc:dc>', dc) self.assertXmlEquals('<dc:iets xmlns:dc="http://purl.org/dc/elements/1.1/" key="<"value">">te"xt</dc:iets>', createElement('dc:iets', attrib={'key':'<"value">'}, text='te"xt', nsmap=namespaces.select('dc')))