99
103
# the default or a parameterized class, but rather use the
100
104
# TestCaseWithTransport infrastructure to set up a smart server and
102
self.overrideAttr(self, "transport_server", self.make_transport_server)
106
self.transport_server = self.make_transport_server
104
108
def make_transport_server(self):
105
109
return test_server.SmartTCPServer_for_testing('-' + self.id())
932
936
# its repository.
933
937
self.make_tree_with_two_commits()
934
938
rev_id_utf8 = u'\xc8'.encode('utf-8')
935
self.tree.branch.set_last_revision_info(0, 'null:')
939
self.tree.branch.set_revision_history([])
936
940
self.assertEqual(
937
941
(0, 'null:'), self.tree.branch.last_revision_info())
938
942
# We can update the branch to a revision that is present in the
1511
1512
stream_bytes = ''.join(response.body_stream)
1512
1513
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
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')
1527
1516
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
1922
1911
smart_repo.SmartServerRepositoryGetRevisionGraph)
1923
1912
self.assertHandlerEqual('Repository.get_stream',
1924
1913
smart_repo.SmartServerRepositoryGetStream)
1925
self.assertHandlerEqual('Repository.get_stream_1.19',
1926
smart_repo.SmartServerRepositoryGetStream_1_19)
1927
1914
self.assertHandlerEqual('Repository.has_revision',
1928
1915
smart_repo.SmartServerRequestHasRevision)
1929
1916
self.assertHandlerEqual('Repository.insert_stream',
1940
1927
smart_repo.SmartServerRepositoryUnlock)
1941
1928
self.assertHandlerEqual('Transport.is_readonly',
1942
1929
smart_req.SmartServerIsReadonly)
1945
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
1946
"""Tests for SmartTCPServer hooks."""
1949
super(SmartTCPServerHookTests, self).setUp()
1950
self.server = server.SmartTCPServer(self.get_transport())
1952
def test_run_server_started_hooks(self):
1953
"""Test the server started hooks get fired properly."""
1955
server.SmartTCPServer.hooks.install_named_hook('server_started',
1956
lambda backing_urls, url: started_calls.append((backing_urls, url)),
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)),
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)])
1969
def test_run_server_started_hooks_ipv6(self):
1970
"""Test that socknames can contain 4-tuples."""
1971
self.server._sockname = ('::', 42, 0, 0)
1973
server.SmartTCPServer.hooks.install_named_hook('server_started',
1974
lambda backing_urls, url: started_calls.append((backing_urls, url)),
1976
self.server.run_server_started_hooks()
1977
self.assertEquals(started_calls,
1978
[([self.get_transport().base], 'bzr://:::42/')])
1980
def test_run_server_stopped_hooks(self):
1981
"""Test the server stopped hooks."""
1982
self.server._sockname = ('example.com', 42)
1984
server.SmartTCPServer.hooks.install_named_hook('server_stopped',
1985
lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
1987
self.server.run_server_stopped_hooks()
1988
self.assertEquals(stopped_calls,
1989
[([self.get_transport().base], 'bzr://example.com:42/')])