103
99
# the default or a parameterized class, but rather use the
104
100
# TestCaseWithTransport infrastructure to set up a smart server and
106
self.transport_server = self.make_transport_server
102
self.overrideAttr(self, "transport_server", self.make_transport_server)
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
1512
1511
stream_bytes = ''.join(response.body_stream)
1513
1512
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')
1516
1527
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
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)
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/')])