示例#1
0
 def testFixUnwantedChars(self):
     dc = createElement('dc:title',
                        nsmap=namespaces.select('dc'),
                        text='\x0b\x1e\x1f\x01Text')
     self.assertXmlEquals(
         '<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Text</dc:title>',
         dc)
     dc = createElement('dc:title',
                        nsmap=namespaces.select('dc'),
                        attrib={'key': '\x0b\x1e\x1f\x01Text'})
     self.assertXmlEquals(
         '<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/" key="Text"/>',
         dc)
示例#2
0
    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>&lt;title&gt;</dc:title></oai_dc:dc>',
            dc)

        self.assertXmlEquals(
            '<dc:iets xmlns:dc="http://purl.org/dc/elements/1.1/" key="&lt;&quot;value&quot;>">te"xt</dc:iets>',
            createElement('dc:iets',
                          attrib={'key': '<"value">'},
                          text='te"xt',
                          nsmap=namespaces.select('dc')))
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
示例#4
0
    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"],
        )
示例#5
0
    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)
示例#6
0
 def testFixUnwantedChars(self):
     dc = createElement('dc:title', nsmap=namespaces.select('dc'), text='\x0b\x1e\x1f\x01Text')
     self.assertXmlEquals('<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">Text</dc:title>', dc)
     dc = createElement('dc:title', nsmap=namespaces.select('dc'), attrib={'key':'\x0b\x1e\x1f\x01Text'})
     self.assertXmlEquals('<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/" key="Text"/>', dc)
示例#7
0
    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>&lt;title&gt;</dc:title></oai_dc:dc>', dc)

        self.assertXmlEquals('<dc:iets xmlns:dc="http://purl.org/dc/elements/1.1/" key="&lt;&quot;value&quot;>">te"xt</dc:iets>', createElement('dc:iets', attrib={'key':'<"value">'}, text='te"xt', nsmap=namespaces.select('dc')))