예제 #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/')
예제 #2
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/')
예제 #3
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')
예제 #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.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')
예제 #5
0
 def setUp(self):
     self.oldfetcher = fetchers.getDefaultFetcher()
     fetchers.setDefaultFetcher(self.MockFetcher())
예제 #6
0
 def test_setDefault(self):
     """Make sure the getDefaultFetcher returns the object set for
     setDefaultFetcher"""
     sentinel = object()
     fetchers.setDefaultFetcher(sentinel, wrap_exceptions=False)
     self.failUnless(fetchers.getDefaultFetcher() is sentinel)
예제 #7
0
 def test_getDefaultNotNone(self):
     """Make sure that None is never returned as a default fetcher"""
     self.failUnless(fetchers.getDefaultFetcher() is not None)
     fetchers.setDefaultFetcher(None)
     self.failUnless(fetchers.getDefaultFetcher() is not None)
예제 #8
0
 def setUp(self):
     self.oldfetcher = fetchers.getDefaultFetcher()
     fetchers.setDefaultFetcher(self.MockFetcher())
예제 #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.failUnless(fetchers.getDefaultFetcher() is sentinel)
예제 #10
0
 def test_getDefaultNotNone(self):
     """Make sure that None is never returned as a default fetcher"""
     self.failUnless(fetchers.getDefaultFetcher() is not None)
     fetchers.setDefaultFetcher(None)
     self.failUnless(fetchers.getDefaultFetcher() is not None)