88
90
if self._chroot_server is None:
89
91
backing_transport = tests.TestCaseWithTransport.get_transport(self)
90
92
self._chroot_server = chroot.ChrootServer(backing_transport)
91
self._chroot_server.setUp()
92
self.addCleanup(self._chroot_server.tearDown)
93
self.start_server(self._chroot_server)
93
94
t = get_transport(self._chroot_server.get_url())
94
95
if relpath is not None:
95
96
t = t.clone(relpath)
99
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
100
class TestCaseWithSmartMedium(tests.TestCaseWithMemoryTransport):
102
103
super(TestCaseWithSmartMedium, self).setUp()
170
171
self.assertRaises(
171
172
errors.PathNotChild, request.translate_client_path, 'bar/')
172
173
self.assertEqual('./baz', request.translate_client_path('foo/baz'))
174
e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
175
self.assertEqual('./' + urlutils.escape(e_acute),
176
request.translate_client_path('foo/' + e_acute))
178
def test_translate_client_path_vfs(self):
179
"""VfsRequests receive escaped paths rather than raw UTF-8."""
180
transport = self.get_transport()
181
request = smart.vfs.VfsRequest(transport, 'foo/')
182
e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
183
escaped = urlutils.escape('foo/' + e_acute)
184
self.assertEqual('./' + urlutils.escape(e_acute),
185
request.translate_client_path(escaped))
174
187
def test_transport_from_client_path(self):
175
188
transport = self.get_transport()
414
427
'False', 'False', 'False', '', '', '', '', 'False')
430
class TestSmartServerRequestOpenBzrDir(tests.TestCaseWithMemoryTransport):
432
def test_no_directory(self):
433
backing = self.get_transport()
434
request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing)
435
self.assertEqual(SmartServerResponse(('no', )),
436
request.execute('does-not-exist'))
438
def test_empty_directory(self):
439
backing = self.get_transport()
440
backing.mkdir('empty')
441
request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing)
442
self.assertEqual(SmartServerResponse(('no', )),
443
request.execute('empty'))
445
def test_outside_root_client_path(self):
446
backing = self.get_transport()
447
request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing,
448
root_client_path='root')
449
self.assertEqual(SmartServerResponse(('no', )),
450
request.execute('not-root'))
453
class TestSmartServerRequestOpenBzrDir_2_1(tests.TestCaseWithMemoryTransport):
455
def test_no_directory(self):
456
backing = self.get_transport()
457
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
458
self.assertEqual(SmartServerResponse(('no', )),
459
request.execute('does-not-exist'))
461
def test_empty_directory(self):
462
backing = self.get_transport()
463
backing.mkdir('empty')
464
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
465
self.assertEqual(SmartServerResponse(('no', )),
466
request.execute('empty'))
468
def test_present_without_workingtree(self):
469
backing = self.get_transport()
470
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
471
self.make_bzrdir('.')
472
self.assertEqual(SmartServerResponse(('yes', 'no')),
475
def test_outside_root_client_path(self):
476
backing = self.get_transport()
477
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing,
478
root_client_path='root')
479
self.assertEqual(SmartServerResponse(('no',)),
480
request.execute('not-root'))
483
class TestSmartServerRequestOpenBzrDir_2_1_disk(TestCaseWithChrootedTransport):
485
def test_present_with_workingtree(self):
486
self.vfs_transport_factory = local.LocalURLServer
487
backing = self.get_transport()
488
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
489
bd = self.make_bzrdir('.')
490
bd.create_repository()
492
bd.create_workingtree()
493
self.assertEqual(SmartServerResponse(('yes', 'yes')),
417
497
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
419
499
def test_no_branch(self):
1621
1703
self.assertEqual(SmartServerResponse(('ok',)), response)
1706
class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
1708
def test_unicode_path(self):
1709
"""VFS requests expect unicode paths to be escaped."""
1710
filename = u'foo\N{INTERROBANG}'
1711
filename_escaped = urlutils.escape(filename)
1712
backing = self.get_transport()
1713
request = smart.vfs.GetRequest(backing)
1714
backing.put_bytes_non_atomic(filename_escaped, 'contents')
1715
self.assertEqual(SmartServerResponse(('ok', ), 'contents'),
1716
request.execute(filename_escaped))
1624
1719
class TestHandlers(tests.TestCase):
1625
1720
"""Tests for the request.request_handlers object."""