23
23
import bzrlib.errors as errors
24
24
from bzrlib.errors import BzrError
25
from bzrlib.store import TransportStore
25
26
from bzrlib.store.text import TextStore
27
from bzrlib.store.versioned import VersionedFileStore
26
28
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
27
import bzrlib.store as store
28
import bzrlib.store.versioned
29
29
import bzrlib.transactions as transactions
30
30
import bzrlib.transport as transport
31
31
from bzrlib.transport.memory import MemoryTransport
32
from bzrlib.weave import WeaveFile
34
35
class TestStores(object):
241
242
class TestTransportStore(TestCase):
243
244
def test__relpath_invalid(self):
244
my_store = store.TransportStore(MockTransport())
245
my_store = TransportStore(MockTransport())
245
246
self.assertRaises(ValueError, my_store._relpath, '/foo')
246
247
self.assertRaises(ValueError, my_store._relpath, 'foo/')
248
249
def test_register_invalid_suffixes(self):
249
my_store = store.TransportStore(MockTransport())
250
my_store = TransportStore(MockTransport())
250
251
self.assertRaises(ValueError, my_store.register_suffix, '/')
251
252
self.assertRaises(ValueError, my_store.register_suffix, '.gz/bar')
253
254
def test__relpath_unregister_suffixes(self):
254
my_store = store.TransportStore(MockTransport())
255
my_store = TransportStore(MockTransport())
255
256
self.assertRaises(ValueError, my_store._relpath, 'foo', ['gz'])
256
257
self.assertRaises(ValueError, my_store._relpath, 'foo', ['dsc', 'gz'])
258
259
def test__relpath_simple(self):
259
my_store = store.TransportStore(MockTransport())
260
my_store = TransportStore(MockTransport())
260
261
self.assertEqual("foo", my_store._relpath('foo'))
262
263
def test__relpath_prefixed(self):
263
my_store = store.TransportStore(MockTransport(), True)
264
my_store = TransportStore(MockTransport(), True)
264
265
self.assertEqual('45/foo', my_store._relpath('foo'))
266
267
def test__relpath_simple_suffixed(self):
267
my_store = store.TransportStore(MockTransport())
268
my_store = TransportStore(MockTransport())
268
269
my_store.register_suffix('bar')
269
270
my_store.register_suffix('baz')
270
271
self.assertEqual('foo.baz', my_store._relpath('foo', ['baz']))
271
272
self.assertEqual('foo.bar.baz', my_store._relpath('foo', ['bar', 'baz']))
273
274
def test__relpath_prefixed_suffixed(self):
274
my_store = store.TransportStore(MockTransport(), True)
275
my_store = TransportStore(MockTransport(), True)
275
276
my_store.register_suffix('bar')
276
277
my_store.register_suffix('baz')
277
278
self.assertEqual('45/foo.baz', my_store._relpath('foo', ['baz']))
393
394
self.assertRaises(KeyError, to_store.get, 'missing', 'sig')
395
396
def test_relpath_escaped(self):
396
my_store = store.TransportStore(MemoryTransport())
397
my_store = TransportStore(MemoryTransport())
397
398
self.assertEqual('%25', my_store._relpath('%'))
399
400
def test_escaped_uppercase(self):
400
401
"""Uppercase letters are escaped for safety on Windows"""
401
my_store = store.TransportStore(MemoryTransport(), prefixed=True,
402
my_store = TransportStore(MemoryTransport(), prefixed=True,
403
404
# a particularly perverse file-id! :-)
404
405
self.assertEquals(my_store._relpath('C:<>'), 'be/%2543%253a%253c%253e')
436
438
self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'b', [], [])
438
440
def test___iter__escaped(self):
439
self.vfstore = store.versioned.VersionedFileStore(MemoryTransport(),
440
prefixed=True, escaped=True)
441
self.vfstore = VersionedFileStore(MemoryTransport(),
442
prefixed=True, escaped=True, versionedfile_class=WeaveFile)
441
443
self.vfstore.get_scope = self.get_scope
442
444
self._transaction = transactions.WriteTransaction()
443
445
vf = self.vfstore.get_weave_or_empty(' ', self._transaction)