~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: John Arbash Meinel
  • Date: 2011-07-18 14:22:20 UTC
  • mto: This revision was merged to the branch mainline in revision 6033.
  • Revision ID: john@arbash-meinel.com-20110718142220-nwylw659oip1ene9
Start at least testing the package_branch regex.
And start testing the is-up-to-date logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
25
25
"""
26
26
 
27
27
import bz2
28
 
from cStringIO import StringIO
29
 
import tarfile
30
28
 
31
29
from bzrlib import (
32
 
    bencode,
33
30
    branch as _mod_branch,
34
31
    bzrdir,
35
32
    errors,
36
 
    pack,
37
33
    tests,
38
34
    transport,
39
35
    urlutils,
103
99
        # the default or a parameterized class, but rather use the
104
100
        # TestCaseWithTransport infrastructure to set up a smart server and
105
101
        # transport.
106
 
        self.transport_server = self.make_transport_server
 
102
        self.overrideAttr(self, "transport_server", self.make_transport_server)
107
103
 
108
104
    def make_transport_server(self):
109
105
        return test_server.SmartTCPServer_for_testing('-' + self.id())
936
932
        # its repository.
937
933
        self.make_tree_with_two_commits()
938
934
        rev_id_utf8 = u'\xc8'.encode('utf-8')
939
 
        self.tree.branch.set_revision_history([])
 
935
        self.tree.branch.set_last_revision_info(0, 'null:')
940
936
        self.assertEqual(
941
937
            (0, 'null:'), self.tree.branch.last_revision_info())
942
938
        # We can update the branch to a revision that is present in the
1474
1470
            request.execute('stacked', 1, (3, r3)))
1475
1471
 
1476
1472
 
1477
 
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
 
1473
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
1478
1474
 
1479
1475
    def make_two_commit_repo(self):
1480
1476
        tree = self.make_branch_and_memory_tree('.')
1486
1482
        repo = tree.branch.repository
1487
1483
        return repo, r1, r2
1488
1484
 
 
1485
 
 
1486
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
 
1487
 
1489
1488
    def test_ancestry_of(self):
1490
1489
        """The search argument may be a 'ancestry-of' some heads'."""
1491
1490
        backing = self.get_transport()
1512
1511
        stream_bytes = ''.join(response.body_stream)
1513
1512
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1514
1513
 
 
1514
    def test_search_everything(self):
 
1515
        """A search of 'everything' returns a stream."""
 
1516
        backing = self.get_transport()
 
1517
        request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
 
1518
        repo, r1, r2 = self.make_two_commit_repo()
 
1519
        serialised_fetch_spec = 'everything'
 
1520
        request.execute('', repo._format.network_name())
 
1521
        response = request.do_body(serialised_fetch_spec)
 
1522
        self.assertEqual(('ok',), response.args)
 
1523
        stream_bytes = ''.join(response.body_stream)
 
1524
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
 
1525
 
1515
1526
 
1516
1527
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
1517
1528
 
1911
1922
            smart_repo.SmartServerRepositoryGetRevisionGraph)
1912
1923
        self.assertHandlerEqual('Repository.get_stream',
1913
1924
            smart_repo.SmartServerRepositoryGetStream)
 
1925
        self.assertHandlerEqual('Repository.get_stream_1.19',
 
1926
            smart_repo.SmartServerRepositoryGetStream_1_19)
1914
1927
        self.assertHandlerEqual('Repository.has_revision',
1915
1928
            smart_repo.SmartServerRequestHasRevision)
1916
1929
        self.assertHandlerEqual('Repository.insert_stream',
1927
1940
            smart_repo.SmartServerRepositoryUnlock)
1928
1941
        self.assertHandlerEqual('Transport.is_readonly',
1929
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/')])