Ejemplo n.º 1
0
    def testUserAgentDefault(self):
        args = {}
        def myOwnUrlOpen(*fArgs, **fKwargs):
            args['args'] = fArgs
            args['kwargs'] = fKwargs
            return StringIO(oaiResponseXML())

        request = OaiRequest("http://harvest.me", _urlopen=myOwnUrlOpen)
        request.identify()
        
        self.assertEquals("Meresco Harvester trunk", args['args'][0].headers['User-agent'])
Ejemplo n.º 2
0
    def testUserAgentDefault(self):
        args = {}

        def myOwnUrlOpen(*fArgs, **fKwargs):
            args['args'] = fArgs
            args['kwargs'] = fKwargs
            return StringIO(oaiResponseXML())

        request = OaiRequest("http://harvest.me", _urlopen=myOwnUrlOpen)
        request.identify()

        self.assertEqual("Meresco Harvester {}".format(VERSION),
                         args['args'][0].headers['User-agent'])
Ejemplo n.º 3
0
 def performMapping(self, domainId, mappingId, urlString):
     mapping = self._proxy.getMappingObject(mappingId)
     mapping.addObserver(StreamEventLogger(self._output))
     self._output.write(mapping.mappingInfo())
     self._output.write('\n')
     response = OaiRequest(urlString).request()
     for record in response.records:
         response.selectRecord(record)
         try:
             upload = mapping.createUpload(TestRepository, response, doAsserts=True)
             self.writeUpload(upload)
         except DataMapAssertionException, ex:
             self.writeLine('AssertionError: '+str(ex))
Ejemplo n.º 4
0
 def testContextSetToTLS12(self):
     from ssl import SSLError, PROTOCOL_TLSv1_2
     calls = []
     def loggingUrlOpen(*fArgs, **fKwargs):
         calls.append(fKwargs)
         raise SSLError("Some error")
     request = OaiRequest("http://harvest.me", _urlopen=loggingUrlOpen)
     try:
         request.identify()
         self.fail("Should have failed")
     except:
         pass
     self.assertEqual(2, len(calls))
     self.assertEqual(None, calls[0]['context'])
     context=calls[1]['context']
     self.assertEqual(PROTOCOL_TLSv1_2, context.protocol)
Ejemplo n.º 5
0
 def performMapping(self, mappingData, urlString, mappingObject=None):
     if mappingObject:
         mapping = mappingObject
     else:
         mapping = Mapping(mappingData.get('identifier'))
         mapping.fill(None, mappingData)
     mapping.addObserver(StreamEventLogger(self._output))
     self._output.write(mapping.mappingInfo())
     self._output.write('\n')
     response = OaiRequest(urlString).request()
     for record in response.records:
         response.selectRecord(record)
         try:
             upload = mapping.createUpload(TestRepository, response, doAsserts=True)
             self.writeUpload(upload)
         except DataMapAssertionException, ex:
             self.writeLine('AssertionError: '+str(ex))
Ejemplo n.º 6
0
    def testContextSetToTLS12(self):
        from ssl import SSLError, PROTOCOL_TLSv1_2
        calls = []

        def loggingUrlOpen(*fArgs, **fKwargs):
            calls.append(fKwargs)
            raise SSLError("Some error")

        request = OaiRequest("http://harvest.me", _urlopen=loggingUrlOpen)
        try:
            request.identify()
            self.fail("Should have failed")
        except:
            pass
        self.assertEqual(2, len(calls))
        self.assertEqual(None, calls[0]['context'])
        context = calls[1]['context']
        self.assertEqual(PROTOCOL_TLSv1_2, context.protocol)
Ejemplo n.º 7
0
 def performMapping(self, mappingData, urlString, mappingObject=None):
     if mappingObject:
         mapping = mappingObject
     else:
         mapping = Mapping(mappingData.get('identifier'))
         mapping.fill(None, mappingData)
     mapping.addObserver(StreamEventLogger(self._output))
     self._output.write(mapping.mappingInfo() or '')
     self._output.write('\n')
     response = OaiRequest(urlString).request()
     for record in response.records:
         response.selectRecord(record)
         try:
             upload = mapping.createUpload(TestRepository,
                                           response,
                                           doAsserts=True)
             self.writeUpload(upload)
         except DataMapAssertionException as ex:
             self.writeLine('AssertionError: ' + str(ex))
Ejemplo n.º 8
0
 def testHeaders(self):
     self.assertEqual(
         {"User-Agent": "Meresco Harvester {}".format(VERSION)},
         OaiRequest('http://example.com')._headers())
     self.assertEqual({"User-Agent": "User Agent 3.0"},
                      OaiRequest('http://example.com',
                                 userAgent="User Agent 3.0")._headers())
     self.assertEqual(
         {"User-Agent": "Meresco Harvester {}".format(VERSION)},
         OaiRequest('http://example.com', userAgent='')._headers())
     self.assertEqual(
         {"User-Agent": "Meresco Harvester {}".format(VERSION)},
         OaiRequest('http://example.com', userAgent=' ')._headers())
     self.assertEqual(
         {
             "User-Agent": "Meresco Harvester {}".format(VERSION),
             "Authorization": "Bearer GivenKey"
         },
         OaiRequest('http://example.com',
                    authorizationKey='GivenKey')._headers())
Ejemplo n.º 9
0
    def testBuildRequestUrl(self):
        oaiRequest = OaiRequest("http://x.y.z/oai")
        self.assertEqual(
            "http://x.y.z/oai?verb=ListRecords&metadataPrefix=oai_dc",
            oaiRequest._buildRequestUrl([('verb', 'ListRecords'),
                                         ('metadataPrefix', 'oai_dc')]))

        oaiRequest = OaiRequest("http://x.y.z/oai?apikey=xyz123")
        self.assertEqual(
            "http://x.y.z/oai?apikey=xyz123&verb=ListRecords&metadataPrefix=oai_dc",
            oaiRequest._buildRequestUrl([('verb', 'ListRecords'),
                                         ('metadataPrefix', 'oai_dc')]))
Ejemplo n.º 10
0
 def __init__(self, url):
     OaiRequest.__init__(self,url)
     self._createMapping()
Ejemplo n.º 11
0
    def testBuildRequestUrl(self):
        oaiRequest = OaiRequest("http://x.y.z/oai")
        self.assertEquals("http://x.y.z/oai?verb=ListRecords&metadataPrefix=oai_dc", oaiRequest._buildRequestUrl([('verb', 'ListRecords'), ('metadataPrefix', 'oai_dc')]))

        oaiRequest = OaiRequest("http://x.y.z/oai?apikey=xyz123")
        self.assertEquals("http://x.y.z/oai?apikey=xyz123&verb=ListRecords&metadataPrefix=oai_dc", oaiRequest._buildRequestUrl([('verb', 'ListRecords'), ('metadataPrefix', 'oai_dc')]))
Ejemplo n.º 12
0
 def createServer(self, url='http://repository.tudelft.nl/oai'):
     return OaiRequest(url)
Ejemplo n.º 13
0
 def __init__(self, url):
     OaiRequest.__init__(self,url)
     self._createMapping()