/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2011, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
16
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
17
"""Test Store implementations."""
18
1185.1.46 by Robert Collins
Aarons branch --basis patch
19
import os
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
20
import gzip
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
21
6686.2.1 by Jelmer Vernooij
Move breezy.store to breezy.plugins.weave_fmt, its only user.
22
from ... import errors as errors
23
from ...errors import BzrError
24
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
25
    BytesIO,
26
    )
6686.2.1 by Jelmer Vernooij
Move breezy.store to breezy.plugins.weave_fmt, its only user.
27
from .store import TransportStore
28
from .store.text import TextStore
29
from .store.versioned import VersionedFileStore
30
from ...tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
31
from ... import transactions
32
from ... import transport
33
from ...transport.memory import MemoryTransport
6670.4.18 by Jelmer Vernooij
Merge move-store.
34
from ...bzr.weave import WeaveFile
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
35
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
36
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
37
class TestStores(object):
1185.16.146 by Martin Pool
Fix up assert with sideeffects in CompressedTextStore._copy_one
38
    """Mixin template class that provides some common tests for stores"""
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
39
40
    def check_content(self, store, fileid, value):
1442.1.35 by Robert Collins
convert all users of __getitem__ into TransportStores to use .get instead
41
        f = store.get(fileid)
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
42
        self.assertEqual(f.read(), value)
43
44
    def fill_store(self, store):
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
45
        store.add(BytesIO(b'hello'), b'a')
46
        store.add(BytesIO(b'other'), b'b')
47
        store.add(BytesIO(b'something'), b'c')
48
        store.add(BytesIO(b'goodbye'), b'123123')
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
49
50
    def test_get(self):
51
        store = self.get_store()
52
        self.fill_store(store)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
53
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
54
        self.check_content(store, b'a', b'hello')
55
        self.check_content(store, b'b', b'other')
56
        self.check_content(store, b'c', b'something')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
57
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
58
        # Make sure that requesting a non-existing file fails
6855.3.1 by Jelmer Vernooij
Several more fixes.
59
        self.assertRaises(KeyError, self.check_content, store, b'd', None)
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
60
974.1.44 by aaron.bentley at utoronto
Added test of double-add in ImmutableStore
61
    def test_multiple_add(self):
62
        """Multiple add with same ID should raise a BzrError"""
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
63
        store = self.get_store()
64
        self.fill_store(store)
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
65
        self.assertRaises(BzrError, store.add, BytesIO(b'goodbye'), b'123123')
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
66
67
68
class TestCompressedTextStore(TestCaseInTempDir, TestStores):
69
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
70
    def get_store(self, path=u'.'):
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
71
        t = transport.get_transport_from_path(path)
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
72
        return TextStore(t, compressed=True)
1185.11.1 by John Arbash Meinel
(broken) Transport work is merged in. Tests do not pass yet.
73
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
74
    def test_total_size(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
75
        store = self.get_store(u'.')
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
76
        store.register_suffix('dsc')
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
77
        store.add(BytesIO(b'goodbye'), b'123123')
78
        store.add(BytesIO(b'goodbye2'), b'123123', 'dsc')
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
79
        # these get gzipped - content should be stable
80
        self.assertEqual(store.total_size(), (2, 55))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
81
1442.1.32 by Robert Collins
Teach CompressedTextStore._relpath to support file suffixes too.
82
    def test__relpath_suffixed(self):
1185.58.4 by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores.
83
        my_store = TextStore(MockTransport(),
84
                             prefixed=True, compressed=True)
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
85
        my_store.register_suffix('dsc')
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
86
        self.assertEqual('45/foo.dsc', my_store._relpath(b'foo', ['dsc']))
1442.1.32 by Robert Collins
Teach CompressedTextStore._relpath to support file suffixes too.
87
1404 by Robert Collins
only pull remote text weaves once per fetch operation
88
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
89
class TestMemoryStore(TestCase):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
90
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
91
    def get_store(self):
1651.1.7 by Martin Pool
Move small ImmutableMemoryStore class into test module,
92
        return TextStore(MemoryTransport())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
93
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
94
    def test_add_and_retrieve(self):
95
        store = self.get_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
96
        store.add(BytesIO(b'hello'), b'aa')
97
        self.assertNotEqual(store.get(b'aa'), None)
98
        self.assertEqual(store.get(b'aa').read(), b'hello')
99
        store.add(BytesIO(b'hello world'), b'bb')
100
        self.assertNotEqual(store.get(b'bb'), None)
101
        self.assertEqual(store.get(b'bb').read(), b'hello world')
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
102
103
    def test_missing_is_absent(self):
104
        store = self.get_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
105
        self.assertNotIn(b'aa', store)
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
106
107
    def test_adding_fails_when_present(self):
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
108
        my_store = self.get_store()
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
109
        my_store.add(BytesIO(b'hello'), b'aa')
1442.1.44 by Robert Collins
Many transport related tweaks:
110
        self.assertRaises(BzrError,
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
111
                          my_store.add, BytesIO(b'hello'), b'aa')
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
112
113
    def test_total_size(self):
114
        store = self.get_store()
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
115
        store.add(BytesIO(b'goodbye'), b'123123')
116
        store.add(BytesIO(b'goodbye2'), b'123123.dsc')
1092.2.1 by Robert Collins
minor refactors to store, create an ImmutableMemoryStore for testing or other such operations
117
        self.assertEqual(store.total_size(), (2, 15))
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
118
        # TODO: Switch the exception form UnlistableStore to
119
        #       or make Stores throw UnlistableStore if their
120
        #       Transport doesn't support listing
121
        # store_c = RemoteStore('http://example.com/')
122
        # self.assertRaises(UnlistableStore, copy_all, store_c, store_b)
123
1404 by Robert Collins
only pull remote text weaves once per fetch operation
124
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
125
class TestTextStore(TestCaseInTempDir, TestStores):
126
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
127
    def get_store(self, path=u'.'):
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
128
        t = transport.get_transport_from_path(path)
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
129
        return TextStore(t, compressed=False)
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
130
131
    def test_total_size(self):
132
        store = self.get_store()
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
133
        store.add(BytesIO(b'goodbye'), b'123123')
134
        store.add(BytesIO(b'goodbye2'), b'123123.dsc')
1442.1.34 by Robert Collins
Remove the Store.get multiple-get interface which was not used, and remove much spurious duplication in teststore.py.
135
        self.assertEqual(store.total_size(), (2, 15))
1393.2.2 by John Arbash Meinel
Updated stores to use Transport
136
        # TODO: Switch the exception form UnlistableStore to
137
        #       or make Stores throw UnlistableStore if their
138
        #       Transport doesn't support listing
139
        # store_c = RemoteStore('http://example.com/')
140
        # self.assertRaises(UnlistableStore, copy_all, store_c, store_b)
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
141
142
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
143
class TestMixedTextStore(TestCaseInTempDir, TestStores):
144
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
145
    def get_store(self, path=u'.', compressed=True):
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
146
        t = transport.get_transport_from_path(path)
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
147
        return TextStore(t, compressed=compressed)
148
149
    def test_get_mixed(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
150
        cs = self.get_store(u'.', compressed=True)
151
        s = self.get_store(u'.', compressed=False)
6973.7.5 by Jelmer Vernooij
s/file/open.
152
        cs.add(BytesIO(b'hello there'), b'a')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
153
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
154
        self.assertPathExists('a.gz')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
155
        self.assertFalse(os.path.lexists('a'))
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
156
6973.7.5 by Jelmer Vernooij
s/file/open.
157
        with gzip.GzipFile('a.gz') as f:
158
            self.assertEqual(f.read(), b'hello there')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
159
6973.7.5 by Jelmer Vernooij
s/file/open.
160
        self.assertEqual(cs.has_id(b'a'), True)
161
        self.assertEqual(s.has_id(b'a'), True)
162
        self.assertEqual(cs.get(b'a').read(), b'hello there')
163
        self.assertEqual(s.get(b'a').read(), b'hello there')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
164
6973.7.6 by Jelmer Vernooij
Fix more tests.
165
        self.assertRaises(BzrError, s.add, BytesIO(b'goodbye'), b'a')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
166
6973.7.6 by Jelmer Vernooij
Fix more tests.
167
        s.add(BytesIO(b'goodbye'), b'b')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
168
        self.assertPathExists('b')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
169
        self.assertFalse(os.path.lexists('b.gz'))
6973.7.5 by Jelmer Vernooij
s/file/open.
170
        with open('b', 'rb') as f:
171
            self.assertEqual(f.read(), b'goodbye')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
172
6973.7.5 by Jelmer Vernooij
s/file/open.
173
        self.assertEqual(cs.has_id(b'b'), True)
174
        self.assertEqual(s.has_id(b'b'), True)
175
        self.assertEqual(cs.get(b'b').read(), b'goodbye')
176
        self.assertEqual(s.get(b'b').read(), b'goodbye')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
177
6973.7.6 by Jelmer Vernooij
Fix more tests.
178
        self.assertRaises(BzrError, cs.add, BytesIO(b'again'), b'b')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
179
6973.7.5 by Jelmer Vernooij
s/file/open.
180
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
181
class MockTransport(transport.Transport):
182
    """A fake transport for testing with."""
183
1442.1.30 by Robert Collins
Add stuf has and mkdir to MockTransport to enable testing store adds
184
    def has(self, filename):
185
        return False
186
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
187
    def __init__(self, url=None):
188
        if url is None:
189
            url = "http://example.com"
190
        super(MockTransport, self).__init__(url)
191
1442.1.30 by Robert Collins
Add stuf has and mkdir to MockTransport to enable testing store adds
192
    def mkdir(self, filename):
193
        return
194
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
195
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
196
class InstrumentedTransportStore(TransportStore):
1442.1.29 by Robert Collins
create an instrumented transport store for testing common logic.
197
    """An instrumented TransportStore.
198
199
    Here we replace template method worker methods with calls that record the
200
    expected results.
201
    """
202
203
    def _add(self, filename, file):
204
        self._calls.append(("_add", filename, file))
205
206
    def __init__(self, transport, prefixed=False):
207
        super(InstrumentedTransportStore, self).__init__(transport, prefixed)
208
        self._calls = []
209
210
211
class TestInstrumentedTransportStore(TestCase):
212
213
    def test__add_records(self):
214
        my_store = InstrumentedTransportStore(MockTransport())
1442.1.30 by Robert Collins
Add stuf has and mkdir to MockTransport to enable testing store adds
215
        my_store._add("filename", "file")
1442.1.29 by Robert Collins
create an instrumented transport store for testing common logic.
216
        self.assertEqual([("_add", "filename", "file")], my_store._calls)
217
218
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
219
class TestMockTransport(TestCase):
220
221
    def test_isinstance(self):
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
222
        self.assertIsInstance(MockTransport(), transport.Transport)
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
223
1442.1.30 by Robert Collins
Add stuf has and mkdir to MockTransport to enable testing store adds
224
    def test_has(self):
225
        self.assertEqual(False, MockTransport().has('foo'))
226
227
    def test_mkdir(self):
228
        MockTransport().mkdir('45')
229
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
230
231
class TestTransportStore(TestCase):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
232
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
233
    def test__relpath_invalid(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
234
        my_store = TransportStore(MockTransport())
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
235
        self.assertRaises(ValueError, my_store._relpath, b'/foo')
236
        self.assertRaises(ValueError, my_store._relpath, b'foo/')
1442.1.24 by Robert Collins
Pull up _check_id and _relpath from Text and CompressedText stores into TransportStore
237
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
238
    def test_register_invalid_suffixes(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
239
        my_store = TransportStore(MockTransport())
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
240
        self.assertRaises(ValueError, my_store.register_suffix, '/')
241
        self.assertRaises(ValueError, my_store.register_suffix, '.gz/bar')
242
243
    def test__relpath_unregister_suffixes(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
244
        my_store = TransportStore(MockTransport())
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
245
        self.assertRaises(ValueError, my_store._relpath, b'foo', [b'gz'])
246
        self.assertRaises(ValueError, my_store._relpath, b'foo', [b'dsc', b'gz'])
1442.1.27 by Robert Collins
Check that file suffixes in TransportStore are also valid
247
1442.1.25 by Robert Collins
Test TransportStore._relpath for simple cases: pull up _prefixed attribute as a result.
248
    def test__relpath_simple(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
249
        my_store = TransportStore(MockTransport())
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
250
        self.assertEqual("foo", my_store._relpath(b'foo'))
1442.1.26 by Robert Collins
Pull up _relpath with gz suffix for CompressedTextStore into TransportStore
251
252
    def test__relpath_prefixed(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
253
        my_store = TransportStore(MockTransport(), True)
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
254
        self.assertEqual('45/foo', my_store._relpath(b'foo'))
1442.1.26 by Robert Collins
Pull up _relpath with gz suffix for CompressedTextStore into TransportStore
255
256
    def test__relpath_simple_suffixed(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
257
        my_store = TransportStore(MockTransport())
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
258
        my_store.register_suffix('bar')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
259
        my_store.register_suffix('baz')
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
260
        self.assertEqual('foo.baz', my_store._relpath(b'foo', ['baz']))
261
        self.assertEqual('foo.bar.baz', my_store._relpath(b'foo', ['bar', 'baz']))
1442.1.27 by Robert Collins
Check that file suffixes in TransportStore are also valid
262
263
    def test__relpath_prefixed_suffixed(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
264
        my_store = TransportStore(MockTransport(), True)
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
265
        my_store.register_suffix('bar')
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
266
        my_store.register_suffix('baz')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
267
        self.assertEqual('45/foo.baz', my_store._relpath(b'foo', ['baz']))
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
268
        self.assertEqual('45/foo.bar.baz',
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
269
                         my_store._relpath(b'foo', ['bar', 'baz']))
1442.1.27 by Robert Collins
Check that file suffixes in TransportStore are also valid
270
1442.1.31 by Robert Collins
test that TransportStore.add calls _add appropriately.
271
    def test_add_simple(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
272
        stream = BytesIO(b"content")
1442.1.31 by Robert Collins
test that TransportStore.add calls _add appropriately.
273
        my_store = InstrumentedTransportStore(MockTransport())
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
274
        my_store.add(stream, b"foo")
1442.1.31 by Robert Collins
test that TransportStore.add calls _add appropriately.
275
        self.assertEqual([("_add", "foo", stream)], my_store._calls)
276
277
    def test_add_prefixed(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
278
        stream = BytesIO(b"content")
1442.1.31 by Robert Collins
test that TransportStore.add calls _add appropriately.
279
        my_store = InstrumentedTransportStore(MockTransport(), True)
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
280
        my_store.add(stream, b"foo")
1442.1.31 by Robert Collins
test that TransportStore.add calls _add appropriately.
281
        self.assertEqual([("_add", "45/foo", stream)], my_store._calls)
1442.1.33 by Robert Collins
teach TransportStore.add to accept an optional file suffix, which does not alter the fileid.
282
283
    def test_add_simple_suffixed(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
284
        stream = BytesIO(b"content")
1442.1.33 by Robert Collins
teach TransportStore.add to accept an optional file suffix, which does not alter the fileid.
285
        my_store = InstrumentedTransportStore(MockTransport())
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
286
        my_store.register_suffix('dsc')
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
287
        my_store.add(stream, b"foo", b'dsc')
1442.1.33 by Robert Collins
teach TransportStore.add to accept an optional file suffix, which does not alter the fileid.
288
        self.assertEqual([("_add", "foo.dsc", stream)], my_store._calls)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
289
1442.1.33 by Robert Collins
teach TransportStore.add to accept an optional file suffix, which does not alter the fileid.
290
    def test_add_simple_suffixed(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
291
        stream = BytesIO(b"content")
1442.1.33 by Robert Collins
teach TransportStore.add to accept an optional file suffix, which does not alter the fileid.
292
        my_store = InstrumentedTransportStore(MockTransport(), True)
1442.1.43 by Robert Collins
add registration of suffixes, in preparation for ensuring iteration is regular
293
        my_store.register_suffix('dsc')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
294
        my_store.add(stream, b"foo", 'dsc')
1442.1.33 by Robert Collins
teach TransportStore.add to accept an optional file suffix, which does not alter the fileid.
295
        self.assertEqual([("_add", "45/foo.dsc", stream)], my_store._calls)
1442.1.46 by Robert Collins
test simple has_id
296
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
297
    def get_populated_store(self, prefixed=False,
1185.16.159 by John Arbash Meinel
Updated the stores, all tests pass, and a store doesn't have to be 100% compressed
298
            store_class=TextStore, compressed=False):
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
299
        my_store = store_class(MemoryTransport(), prefixed,
300
                               compressed=compressed)
1442.1.46 by Robert Collins
test simple has_id
301
        my_store.register_suffix('sig')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
302
        stream = BytesIO(b"signature")
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
303
        my_store.add(stream, b"foo", 'sig')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
304
        stream = BytesIO(b"content")
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
305
        my_store.add(stream, b"foo")
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
306
        stream = BytesIO(b"signature for missing base")
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
307
        my_store.add(stream, b"missing", 'sig')
1442.1.46 by Robert Collins
test simple has_id
308
        return my_store
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
309
1442.1.46 by Robert Collins
test simple has_id
310
    def test_has_simple(self):
311
        my_store = self.get_populated_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
312
        self.assertEqual(True, my_store.has_id(b'foo'))
1442.1.47 by Robert Collins
test for has with suffixed files
313
        my_store = self.get_populated_store(True)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
314
        self.assertEqual(True, my_store.has_id(b'foo'))
1442.1.47 by Robert Collins
test for has with suffixed files
315
316
    def test_has_suffixed(self):
317
        my_store = self.get_populated_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
318
        self.assertEqual(True, my_store.has_id(b'foo', 'sig'))
1442.1.47 by Robert Collins
test for has with suffixed files
319
        my_store = self.get_populated_store(True)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
320
        self.assertEqual(True, my_store.has_id(b'foo', 'sig'))
1442.1.48 by Robert Collins
test that the presence of a signature does not make a missing base file magically appear present
321
322
    def test_has_suffixed_no_base(self):
323
        my_store = self.get_populated_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
324
        self.assertEqual(False, my_store.has_id(b'missing'))
1442.1.48 by Robert Collins
test that the presence of a signature does not make a missing base file magically appear present
325
        my_store = self.get_populated_store(True)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
326
        self.assertEqual(False, my_store.has_id(b'missing'))
1442.1.50 by Robert Collins
test get with suffixes
327
328
    def test_get_simple(self):
329
        my_store = self.get_populated_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
330
        self.assertEqual(b'content', my_store.get(b'foo').read())
1442.1.50 by Robert Collins
test get with suffixes
331
        my_store = self.get_populated_store(True)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
332
        self.assertEqual(b'content', my_store.get(b'foo').read())
1442.1.50 by Robert Collins
test get with suffixes
333
334
    def test_get_suffixed(self):
335
        my_store = self.get_populated_store()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
336
        self.assertEqual(b'signature', my_store.get(b'foo', 'sig').read())
1442.1.50 by Robert Collins
test get with suffixes
337
        my_store = self.get_populated_store(True)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
338
        self.assertEqual(b'signature', my_store.get(b'foo', 'sig').read())
1442.1.50 by Robert Collins
test get with suffixes
339
340
    def test_get_suffixed_no_base(self):
341
        my_store = self.get_populated_store()
6855.3.1 by Jelmer Vernooij
Several more fixes.
342
        self.assertEqual(b'signature for missing base',
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
343
                         my_store.get(b'missing', 'sig').read())
1442.1.50 by Robert Collins
test get with suffixes
344
        my_store = self.get_populated_store(True)
6855.3.1 by Jelmer Vernooij
Several more fixes.
345
        self.assertEqual(b'signature for missing base',
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
346
                         my_store.get(b'missing', 'sig').read())
1442.1.51 by Robert Collins
teach iter about suffixes
347
348
    def test___iter__no_suffix(self):
1185.58.4 by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores.
349
        my_store = TextStore(MemoryTransport(),
350
                             prefixed=False, compressed=False)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
351
        stream = BytesIO(b"content")
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
352
        my_store.add(stream, b"foo")
353
        self.assertEqual({b'foo'},
1442.1.51 by Robert Collins
teach iter about suffixes
354
                         set(my_store.__iter__()))
355
356
    def test___iter__(self):
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
357
        self.assertEqual({b'foo'},
1442.1.51 by Robert Collins
teach iter about suffixes
358
                         set(self.get_populated_store().__iter__()))
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
359
        self.assertEqual({b'foo'},
1442.1.51 by Robert Collins
teach iter about suffixes
360
                         set(self.get_populated_store(True).__iter__()))
361
362
    def test___iter__compressed(self):
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
363
        self.assertEqual({b'foo'},
1442.1.51 by Robert Collins
teach iter about suffixes
364
                         set(self.get_populated_store(
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
365
                             compressed=True).__iter__()))
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
366
        self.assertEqual({b'foo'},
1442.1.51 by Robert Collins
teach iter about suffixes
367
                         set(self.get_populated_store(
1185.16.157 by John Arbash Meinel
Added ability for TextStore to handle both compressed and uncompressed, it just looks for one type first
368
                             True, compressed=True).__iter__()))
1442.1.51 by Robert Collins
teach iter about suffixes
369
370
    def test___len__(self):
371
        self.assertEqual(1, len(self.get_populated_store()))
1442.1.54 by Robert Collins
Teach store.copy_all about fileid suffixes
372
1469 by Robert Collins
Change Transport.* to work with URL's.
373
    def test_relpath_escaped(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
374
        my_store = TransportStore(MemoryTransport())
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
375
        self.assertEqual('%25', my_store._relpath(b'%'))
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
376
1608.2.12 by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely
377
    def test_escaped_uppercase(self):
378
        """Uppercase letters are escaped for safety on Windows"""
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
379
        my_store = TransportStore(MemoryTransport(), prefixed=True,
3350.6.1 by Robert Collins
* New ``versionedfile.KeyMapper`` interface to abstract out the access to
380
            escaped=True)
1608.2.12 by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely
381
        # a particularly perverse file-id! :-)
6963.2.10 by Jelmer Vernooij
Fix a bunch of tests.
382
        self.assertEqual(my_store._relpath(b'C:<>'), 'be/%2543%253a%253c%253e')
1608.2.12 by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely
383
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
384
385
class TestVersionFileStore(TestCaseWithTransport):
386
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
387
    def get_scope(self):
388
        return self._transaction
389
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
390
    def setUp(self):
391
        super(TestVersionFileStore, self).setUp()
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
392
        self.vfstore = VersionedFileStore(MemoryTransport(),
393
            versionedfile_class=WeaveFile)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
394
        self.vfstore.get_scope = self.get_scope
395
        self._transaction = None
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
396
397
    def test_get_weave_registers_dirty_in_write(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
398
        self._transaction = transactions.WriteTransaction()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
399
        vf = self.vfstore.get_weave_or_empty(b'id', self._transaction)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
400
        self._transaction.finish()
401
        self._transaction = None
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
402
        self.assertRaises(errors.OutSideTransaction, vf.add_lines, b'b', [], [])
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
403
        self._transaction = transactions.WriteTransaction()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
404
        vf = self.vfstore.get_weave(b'id', self._transaction)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
405
        self._transaction.finish()
406
        self._transaction = None
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
407
        self.assertRaises(errors.OutSideTransaction, vf.add_lines, b'b', [], [])
1594.2.23 by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files.
408
409
    def test_get_weave_readonly_cant_write(self):
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
410
        self._transaction = transactions.WriteTransaction()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
411
        vf = self.vfstore.get_weave_or_empty(b'id', self._transaction)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
412
        self._transaction.finish()
413
        self._transaction = transactions.ReadOnlyTransaction()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
414
        vf = self.vfstore.get_weave_or_empty(b'id', self._transaction)
415
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, b'b', [], [])
3350.6.1 by Robert Collins
* New ``versionedfile.KeyMapper`` interface to abstract out the access to
416
417
    def test___iter__escaped(self):
5582.9.21 by Jelmer Vernooij
Remove weave references from VersionedfileStore.
418
        self.vfstore = VersionedFileStore(MemoryTransport(),
419
            prefixed=True, escaped=True, versionedfile_class=WeaveFile)
3350.6.1 by Robert Collins
* New ``versionedfile.KeyMapper`` interface to abstract out the access to
420
        self.vfstore.get_scope = self.get_scope
421
        self._transaction = transactions.WriteTransaction()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
422
        vf = self.vfstore.get_weave_or_empty(b' ', self._transaction)
423
        vf.add_lines(b'a', [], [])
3350.6.1 by Robert Collins
* New ``versionedfile.KeyMapper`` interface to abstract out the access to
424
        del vf
425
        self._transaction.finish()
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
426
        self.assertEqual([b' '], list(self.vfstore))