1
# Copyright 2012 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6
from mocker import MockerTestCase
8
from offspring.networking import (
10
TimeoutHTTPConnection,
14
class TestTimeoutTransport(MockerTestCase):
16
def test_make_connection_before_python2_6(self):
18
When running on versions earlier than python 2.7, TimeoutTransport's
19
make_connection method should return an instance of TimeoutHTTP as
20
before python 2.7 xmlrpclib continued to use python 1.5 httplib API.
22
mock_sys = self.mocker.replace(sys)
24
self.mocker.result((2,6))
26
transport = TimeoutTransport()
27
connection = transport.make_connection("http://localhost:1234")
28
self.assertTrue(isinstance(connection, TimeoutHTTP))
30
def test_make_connection_on_python2_7_or_later(self):
32
When running on versions python 2.7 or later, TimeoutTransport's
33
make_connection method should return an instance of
34
TimeoutHTTPConnection instead of TimeoutHTTP.
36
mock_sys = self.mocker.replace(sys)
38
self.mocker.result((2,7))
40
transport = TimeoutTransport()
41
connection = transport.make_connection("http://localhost:1234")
42
self.assertTrue(isinstance(connection, TimeoutHTTPConnection))
44
def test_make_connection_saves_extra_headers(self):
46
TimeoutTransport's make_connection should save extra headers returned
47
when it calls it's get_host_info method as extra_headers. It'll be set
48
to a list if there is auth details in host url.
50
After python 2.6, the authorization header will not be sent if it
51
hasn't been saved to extra_headers when make_connection is called.
53
transport = TimeoutTransport()
54
transport.make_connection("http://admin:password@localhost:1234")
55
self.assertTrue(transport._extra_headers is not None)