~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/tests/test_xmlrpc.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-27 20:14:40 UTC
  • mfrom: (13524.1.2 bug791492)
  • Revision ID: launchpad@pqm.canonical.com-20110727201440-503gw5xzmkgw1ghe
[r=danilo][bug=791492] [r=danilo][bug=791492] add a timeout for
        mailman's xmlrpc serverproxy of Launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Test the generic and/or shared xmlrpc code that Launchpad provides."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
import httplib
 
9
 
 
10
from canonical.testing.layers import BaseLayer
 
11
from lp.services.xmlrpc import (
 
12
    HTTP,
 
13
    Transport,
 
14
    )
 
15
from lp.testing import TestCase
 
16
 
 
17
 
 
18
class DummyConnectionClass:
 
19
    def __init__(self, *args, **kwargs):
 
20
        self.args = args
 
21
        self.kwargs = kwargs
 
22
 
 
23
    def __getattr__(self, name):
 
24
        return name
 
25
 
 
26
 
 
27
class TestTransport(TestCase):
 
28
    """Test code that allows xmlrpclib.ServerProxy to have a socket timeout"""
 
29
 
 
30
    layer = BaseLayer
 
31
 
 
32
    def test_default_initialization(self):
 
33
        transport = Transport()
 
34
        conn = httplib.HTTPConnection('localhost')
 
35
        self.assertEqual(conn.timeout, transport.timeout)
 
36
 
 
37
    def test_custom_initialization(self):
 
38
        transport = Transport(timeout=25)
 
39
        self.assertEqual(25, transport.timeout)
 
40
 
 
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
 
46
        try:
 
47
            transport = Transport(timeout=25)
 
48
            http = transport.make_connection('localhost')
 
49
            self.assertEqual(25, http._conn.kwargs['timeout'])
 
50
        finally:
 
51
            del HTTP.__dict__['_connection_class']