Exemplo n.º 1
0
    def test_wrappedByDefault(self):
        """Make sure that the default fetcher instance wraps
        exceptions by default"""
        default_fetcher = fetchers.getDefaultFetcher()
        self.failUnless(isinstance(default_fetcher, fetchers.ExceptionWrappingFetcher), default_fetcher)

        self.failUnlessRaises(fetchers.HTTPFetchingError, fetchers.fetch, "http://invalid.janrain.com/")
Exemplo n.º 2
0
    def test_wrappedByDefault(self):
        """Make sure that the default fetcher instance wraps
        exceptions by default"""
        default_fetcher = fetchers.getDefaultFetcher()
        self.assertIsInstance(default_fetcher,
                              fetchers.ExceptionWrappingFetcher)

        self.assertRaises(fetchers.HTTPFetchingError, fetchers.fetch,
                          'http://invalid.janrain.com/')
Exemplo n.º 3
0
    def setUp(self):
        CatchLogs.setUp(self)
        self.store = memstore.MemoryStore()

        self.consumer = self.consumer_class(self.store)

        self._orig_fetcher = fetchers.getDefaultFetcher()
        self.fetcher = MockFetcher()
        fetchers.setDefaultFetcher(self.fetcher)
Exemplo n.º 4
0
    def test_notWrapped(self):
        """Make sure that if we set a non-wrapped fetcher as default,
        it will not wrap exceptions."""
        # A fetcher that will raise an exception when it encounters a
        # host that will not resolve
        fetcher = fetchers.Urllib2Fetcher()
        fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)

        self.assertNotIsInstance(fetchers.getDefaultFetcher(), fetchers.ExceptionWrappingFetcher)

        with self.assertRaises(URLError):
            fetchers.fetch('http://invalid.janrain.com/')
Exemplo n.º 5
0
    def test_notWrapped(self):
        """Make sure that if we set a non-wrapped fetcher as default,
        it will not wrap exceptions."""
        # A fetcher that will raise an exception when it encounters a
        # host that will not resolve
        fetcher = fetchers.Urllib2Fetcher()
        fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)

        self.assertNotIsInstance(fetchers.getDefaultFetcher(),
                                 fetchers.ExceptionWrappingFetcher)

        with self.assertRaises(URLError):
            fetchers.fetch('http://invalid.janrain.com/')
Exemplo n.º 6
0
    def test_notWrapped(self):
        """Make sure that if we set a non-wrapped fetcher as default,
        it will not wrap exceptions."""
        # A fetcher that will raise an exception when it encounters a
        # host that will not resolve
        fetcher = fetchers.Urllib2Fetcher()
        fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)

        self.assertFalse(isinstance(fetchers.getDefaultFetcher(),
                               fetchers.ExceptionWrappingFetcher))

        try:
            fetchers.fetch('http://invalid.janrain.com/')
        except fetchers.HTTPFetchingError:
            self.fail('Should not be wrapping exception')
        except Exception as exc:
            self.assertIsInstance(exc, urllib.error.URLError)
            pass
        else:
            self.fail('Should have raised an exception')
Exemplo n.º 7
0
    def test_notWrapped(self):
        """Make sure that if we set a non-wrapped fetcher as default,
        it will not wrap exceptions."""
        # A fetcher that will raise an exception when it encounters a
        # host that will not resolve
        fetcher = fetchers.Urllib2Fetcher()
        fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)

        self.failIf(isinstance(fetchers.getDefaultFetcher(), fetchers.ExceptionWrappingFetcher))

        try:
            fetchers.fetch("http://invalid.janrain.com/")
        except fetchers.HTTPFetchingError:
            self.fail("Should not be wrapping exception")
        except:
            exc = sys.exc_info()[1]
            self.failUnless(isinstance(exc, urllib2.URLError), exc)
            pass
        else:
            self.fail("Should have raised an exception")
Exemplo n.º 8
0
    def test_notWrapped(self):
        """Make sure that if we set a non-wrapped fetcher as default,
        it will not wrap exceptions."""
        # A fetcher that will raise an exception when it encounters a
        # host that will not resolve
        fetcher = fetchers.Urllib2Fetcher()
        fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False)

        self.assertFalse(
            isinstance(fetchers.getDefaultFetcher(),
                       fetchers.ExceptionWrappingFetcher))

        try:
            fetchers.fetch('http://invalid.janrain.com/')
        except fetchers.HTTPFetchingError:
            self.fail('Should not be wrapping exception')
        except Exception as exc:
            self.assertIsInstance(exc, urllib.error.URLError)
            pass
        else:
            self.fail('Should have raised an exception')
Exemplo n.º 9
0
 def test_setDefault(self):
     """Make sure the getDefaultFetcher returns the object set for
     setDefaultFetcher"""
     sentinel = object()
     fetchers.setDefaultFetcher(sentinel, wrap_exceptions=False)
     self.assertTrue(fetchers.getDefaultFetcher() is sentinel)
Exemplo n.º 10
0
 def test_getDefaultNotNone(self):
     """Make sure that None is never returned as a default fetcher"""
     self.assertTrue(fetchers.getDefaultFetcher() is not None)
     fetchers.setDefaultFetcher(None)
     self.assertTrue(fetchers.getDefaultFetcher() is not None)
Exemplo n.º 11
0
 def setUp(self):
     self.oldfetcher = fetchers.getDefaultFetcher()
     fetchers.setDefaultFetcher(self.MockFetcher())
Exemplo n.º 12
0
 def test_setDefault(self):
     """Make sure the getDefaultFetcher returns the object set for
     setDefaultFetcher"""
     sentinel = object()
     fetchers.setDefaultFetcher(sentinel, wrap_exceptions=False)
     self.assertTrue(fetchers.getDefaultFetcher() is sentinel)
Exemplo n.º 13
0
 def test_getDefaultNotNone(self):
     """Make sure that None is never returned as a default fetcher"""
     self.assertTrue(fetchers.getDefaultFetcher() is not None)
     fetchers.setDefaultFetcher(None)
     self.assertTrue(fetchers.getDefaultFetcher() is not None)
Exemplo n.º 14
0
 def setUp(self):
     self.oldfetcher = fetchers.getDefaultFetcher()
     fetchers.setDefaultFetcher(self.MockFetcher())