@@ -83,6 +83,48 @@ def test_http_encoding(self):
8383 self .assertEqual (resp , fake )
8484
8585
86+ class TestHostResolutionError (testtools .TestCase ):
87+
88+ def setUp (self ):
89+ super (TestHostResolutionError , self ).setUp ()
90+ self .mock = mox .Mox ()
91+ self .invalid_host = "example.com.incorrect_top_level_domain"
92+
93+ def test_incorrect_domain_error (self ):
94+ """
95+ Make sure that using a domain which does not resolve causes an
96+ exception which mentions that specific hostname as a reason for
97+ failure.
98+ """
99+ class FailingConnectionClass (object ):
100+ def __init__ (self , * args , ** kwargs ):
101+ pass
102+
103+ def putrequest (self , * args , ** kwargs ):
104+ raise socket .gaierror (- 2 , "Name or service not known" )
105+
106+ def request (self , * args , ** kwargs ):
107+ raise socket .gaierror (- 2 , "Name or service not known" )
108+
109+ self .endpoint = 'http://%s:9292' % (self .invalid_host ,)
110+ self .client = http .HTTPClient (self .endpoint , token = u'abc123' )
111+
112+ self .mock .StubOutWithMock (self .client , 'get_connection' )
113+ self .client .get_connection ().AndReturn (FailingConnectionClass ())
114+ self .mock .ReplayAll ()
115+
116+ try :
117+ self .client .raw_request ('GET' , '/example/path' )
118+ self .fail ("gaierror should be raised" )
119+ except exc .InvalidEndpoint as e :
120+ self .assertTrue (self .invalid_host in str (e ),
121+ "exception should contain the hostname" )
122+
123+ def tearDown (self ):
124+ super (TestHostResolutionError , self ).tearDown ()
125+ self .mock .UnsetStubs ()
126+
127+
86128class TestResponseBodyIterator (testtools .TestCase ):
87129 def test_iter_default_chunk_size_64k (self ):
88130 resp = utils .FakeResponse ({}, StringIO .StringIO ('X' * 98304 ))
0 commit comments