~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-01-14 23:41:14 UTC
  • mfrom: (5611.1.3 bzr.dev)
  • Revision ID: pqm@pqm.ubuntu.com-20110114234114-r4hdusue691ekeg6
(jelmer) Cope with IPv6 addresses in ``bzr serve`` (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    repository as smart_repo,
42
42
    packrepository as smart_packrepo,
43
43
    request as smart_req,
 
44
    server,
44
45
    vfs,
45
46
    )
46
47
from bzrlib.tests import test_server
1939
1940
            smart_repo.SmartServerRepositoryUnlock)
1940
1941
        self.assertHandlerEqual('Transport.is_readonly',
1941
1942
            smart_req.SmartServerIsReadonly)
 
1943
 
 
1944
 
 
1945
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
 
1946
    """Tests for SmartTCPServer hooks."""
 
1947
 
 
1948
    def setUp(self):
 
1949
        super(SmartTCPServerHookTests, self).setUp()
 
1950
        self.server = server.SmartTCPServer(self.get_transport())
 
1951
 
 
1952
    def test_run_server_started_hooks(self):
 
1953
        """Test the server started hooks get fired properly."""
 
1954
        started_calls = []
 
1955
        server.SmartTCPServer.hooks.install_named_hook('server_started',
 
1956
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
 
1957
            None)
 
1958
        started_ex_calls = []
 
1959
        server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
 
1960
            lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
 
1961
            None)
 
1962
        self.server._sockname = ('example.com', 42)
 
1963
        self.server.run_server_started_hooks()
 
1964
        self.assertEquals(started_calls,
 
1965
            [([self.get_transport().base], 'bzr://example.com:42/')])
 
1966
        self.assertEquals(started_ex_calls,
 
1967
            [([self.get_transport().base], self.server)])
 
1968
 
 
1969
    def test_run_server_started_hooks_ipv6(self):
 
1970
        """Test that socknames can contain 4-tuples."""
 
1971
        self.server._sockname = ('::', 42, 0, 0)
 
1972
        started_calls = []
 
1973
        server.SmartTCPServer.hooks.install_named_hook('server_started',
 
1974
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
 
1975
            None)
 
1976
        self.server.run_server_started_hooks()
 
1977
        self.assertEquals(started_calls,
 
1978
                [([self.get_transport().base], 'bzr://:::42/')])
 
1979
 
 
1980
    def test_run_server_stopped_hooks(self):
 
1981
        """Test the server stopped hooks."""
 
1982
        self.server._sockname = ('example.com', 42)
 
1983
        stopped_calls = []
 
1984
        server.SmartTCPServer.hooks.install_named_hook('server_stopped',
 
1985
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
 
1986
            None)
 
1987
        self.server.run_server_stopped_hooks()
 
1988
        self.assertEquals(stopped_calls,
 
1989
            [([self.get_transport().base], 'bzr://example.com:42/')])