~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    )
43
43
from bzrlib.revision import NULL_REVISION
44
44
from bzrlib.smart import server
45
 
from bzrlib.smart.client import SmartClient
46
 
from bzrlib.transport import remote as remote_transport
 
45
from bzrlib.smart.client import _SmartClient
47
46
from bzrlib.transport.memory import MemoryTransport
48
47
 
49
48
 
57
56
        # make a branch that can be opened over the smart transport
58
57
        self.local_wt = BzrDir.create_standalone_workingtree('.')
59
58
 
 
59
    def tearDown(self):
 
60
        self.transport.disconnect()
 
61
        tests.TestCaseWithTransport.tearDown(self)
 
62
 
60
63
    def test_is_readonly(self):
61
64
        # XXX: this is a poor way to test RemoteTransport, but currently there's
62
65
        # no easy way to substitute in a fake client on a transport like we can
71
74
        # open a standalone branch in the working directory
72
75
        b = remote.RemoteBzrDir(self.transport)
73
76
        branch = b.open_branch()
 
77
        self.assertIsInstance(branch, Branch)
74
78
 
75
79
    def test_remote_repository(self):
76
80
        b = BzrDir.open_from_transport(self.transport)
90
94
    def test_find_correct_format(self):
91
95
        """Should open a RemoteBzrDir over a RemoteTransport"""
92
96
        fmt = BzrDirFormat.find_format(self.transport)
93
 
        self.assertTrue(RemoteBzrDirFormat in BzrDirFormat._control_formats)
 
97
        self.assertTrue(RemoteBzrDirFormat
 
98
                        in BzrDirFormat._control_server_formats)
94
99
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
95
100
 
96
101
    def test_open_detected_smart_format(self):
123
128
        return self._body_buffer.read(count)
124
129
 
125
130
 
126
 
class FakeClient(SmartClient):
127
 
    """Lookalike for SmartClient allowing testing."""
 
131
class FakeClient(_SmartClient):
 
132
    """Lookalike for _SmartClient allowing testing."""
128
133
    
129
134
    def __init__(self, responses):
130
135
        # We don't call the super init because there is no medium.
149
154
class TestBzrDirOpenBranch(tests.TestCase):
150
155
 
151
156
    def test_branch_present(self):
152
 
        client = FakeClient([(('ok', ''), ), (('ok', '', 'False', 'False'), )])
 
157
        client = FakeClient([(('ok', ''), ), (('ok', '', 'no', 'no'), )])
153
158
        transport = MemoryTransport()
154
159
        transport.mkdir('quack')
155
160
        transport = transport.clone('quack')
175
180
 
176
181
    def check_open_repository(self, rich_root, subtrees):
177
182
        if rich_root:
178
 
            rich_response = 'True'
 
183
            rich_response = 'yes'
179
184
        else:
180
 
            rich_response = 'False'
 
185
            rich_response = 'no'
181
186
        if subtrees:
182
 
            subtree_response = 'True'
 
187
            subtree_response = 'yes'
183
188
        else:
184
 
            subtree_response = 'False'
 
189
            subtree_response = 'no'
185
190
        client = FakeClient([(('ok', '', rich_response, subtree_response), ),])
186
191
        transport = MemoryTransport()
187
192
        transport.mkdir('quack')
207
212
 
208
213
    def test_empty_branch(self):
209
214
        # in an empty branch we decode the response properly
210
 
        client = FakeClient([(('ok', '0', ''), )])
 
215
        client = FakeClient([(('ok', '0', 'null:'), )])
211
216
        transport = MemoryTransport()
212
217
        transport.mkdir('quack')
213
218
        transport = transport.clone('quack')
265
270
        result = branch.set_revision_history([])
266
271
        self.assertEqual(
267
272
            [('call', 'Branch.set_last_revision',
268
 
                ('///branch/', 'branch token', 'repo token', ''))],
 
273
                ('///branch/', 'branch token', 'repo token', 'null:'))],
269
274
            client._calls)
270
275
        branch.unlock()
271
276
        self.assertEqual(None, result)
325
330
        branch.unlock()
326
331
 
327
332
 
328
 
class TestBranchControlGetBranchConf(tests.TestCase):
 
333
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
329
334
    """Test branch.control_files api munging...
330
335
 
331
 
    we special case RemoteBranch.control_files.get('branch.conf') to
 
336
    We special case RemoteBranch.control_files.get('branch.conf') to
332
337
    call a specific API so that RemoteBranch's can intercept configuration
333
338
    file reading, allowing them to signal to the client about things like
334
339
    'email is configured for commits'.
337
342
    def test_get_branch_conf(self):
338
343
        # in an empty branch we decode the response properly
339
344
        client = FakeClient([(('ok', ), 'config file body')])
340
 
        transport = MemoryTransport()
341
 
        transport.mkdir('quack')
342
 
        transport = transport.clone('quack')
 
345
        # we need to make a real branch because the remote_branch.control_files
 
346
        # will trigger _ensure_real.
 
347
        branch = self.make_branch('quack')
 
348
        transport = branch.bzrdir.root_transport
343
349
        # we do not want bzrdir to make any remote calls
344
350
        bzrdir = RemoteBzrDir(transport, _client=False)
345
351
        branch = RemoteBranch(bzrdir, None, _client=client)