~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

(andrew) Handle unicode paths correctly in the smart server. (#458762)

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
import bzrlib.smart.bzrdir, bzrlib.smart.bzrdir as smart_dir
44
44
import bzrlib.smart.packrepository
45
45
import bzrlib.smart.repository
 
46
import bzrlib.smart.vfs
46
47
from bzrlib.smart.request import (
47
48
    FailedSmartServerResponse,
48
49
    SmartServerRequest,
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))
 
177
 
 
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))
173
186
 
174
187
    def test_transport_from_client_path(self):
175
188
        transport = self.get_transport()
1690
1703
        self.assertEqual(SmartServerResponse(('ok',)), response)
1691
1704
 
1692
1705
 
 
1706
class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
 
1707
 
 
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))
 
1717
 
 
1718
 
1693
1719
class TestHandlers(tests.TestCase):
1694
1720
    """Tests for the request.request_handlers object."""
1695
1721