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'])
    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'])
 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)
    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)