1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test the generic and/or shared xmlrpc code that Launchpad provides."""
10
from canonical.testing.layers import BaseLayer
11
from lp.services.xmlrpc import (
15
from lp.testing import TestCase
18
class DummyConnectionClass:
19
def __init__(self, *args, **kwargs):
23
def __getattr__(self, name):
27
class TestTransport(TestCase):
28
"""Test code that allows xmlrpclib.ServerProxy to have a socket timeout"""
32
def test_default_initialization(self):
33
transport = Transport()
34
conn = httplib.HTTPConnection('localhost')
35
self.assertEqual(conn.timeout, transport.timeout)
37
def test_custom_initialization(self):
38
transport = Transport(timeout=25)
39
self.assertEqual(25, transport.timeout)
41
def test_timeout_passed_to_connection(self):
42
# The _connection_class is actually set on a parent class. We verify
43
# this, so we can just delete it from the class at the end.
44
self.assertEqual(self, HTTP.__dict__.get('_connection_class', self))
45
HTTP._connection_class = DummyConnectionClass
47
transport = Transport(timeout=25)
48
http = transport.make_connection('localhost')
49
self.assertEqual(25, http._conn.kwargs['timeout'])
51
del HTTP.__dict__['_connection_class']