1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# Copyright (C) 2006, 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for remote bzrdir/branch/repo/etc
These are proxy objects which act on remote objects by sending messages
through a smart client. The proxies are to be created when attempting to open
the object given a transport that supports smartserver rpc operations.
"""
from bzrlib import bzrdir, remote, tests
from bzrlib.branch import Branch
from bzrlib.bzrdir import BzrDir, BzrDirFormat
from bzrlib.remote import (
RemoteBranch,
RemoteBzrDir,
RemoteBzrDirFormat,
)
from bzrlib.revision import NULL_REVISION
from bzrlib.smart import server
from bzrlib.smart.client import SmartClient
from bzrlib.transport import remote as remote_transport
from bzrlib.transport.memory import MemoryTransport
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
def setUp(self):
super(BasicRemoteObjectTests, self).setUp()
self.transport_server = server.SmartTCPServer_for_testing
self.transport = self.get_transport()
self.client = self.transport.get_smart_client()
# make a branch that can be opened over the smart transport
self.local_wt = BzrDir.create_standalone_workingtree('.')
def test_create_remote_bzrdir(self):
b = remote.RemoteBzrDir(self.transport)
self.assertIsInstance(b, BzrDir)
def test_open_remote_branch(self):
# open a standalone branch in the working directory
b = remote.RemoteBzrDir(self.transport)
branch = b.open_branch()
def test_remote_repository(self):
b = BzrDir.open_from_transport(self.transport)
repo = b.open_repository()
revid = u'\xc823123123'
self.assertFalse(repo.has_revision(revid))
self.local_wt.commit(message='test commit', rev_id=revid)
self.assertTrue(repo.has_revision(revid))
def test_remote_branch_revision_history(self):
b = BzrDir.open_from_transport(self.transport).open_branch()
self.assertEqual([], b.revision_history())
r1 = self.local_wt.commit('1st commit')
r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8')
self.assertEqual([r1, r2], b.revision_history())
def test_find_correct_format(self):
"""Should open a RemoteBzrDir over a RemoteTransport"""
fmt = BzrDirFormat.find_format(self.transport)
self.assertTrue(RemoteBzrDirFormat in BzrDirFormat._control_formats)
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
def test_open_detected_smart_format(self):
fmt = BzrDirFormat.find_format(self.transport)
d = fmt.open(self.transport)
self.assertIsInstance(d, BzrDir)
class FakeClient(SmartClient):
"""Lookalike for SmartClient allowing testing."""
def __init__(self, responses):
# We don't call the super init because there is no medium.
self.responses = responses
self._calls = []
def call(self, method, *args):
self._calls.append(('call', method, args))
return self.responses.pop(0)
class TestBranchLastRevisionInfo(tests.TestCase):
def test_empty_branch(self):
# in an empty branch we decode the response properly
client = FakeClient([('ok', '0', '')])
transport = MemoryTransport()
transport.mkdir('quack')
transport = transport.clone('quack')
# we do not want bzrdir to make any remote calls
bzrdir = RemoteBzrDir(transport, _client=False)
branch = RemoteBranch(bzrdir, None, _client=client)
result = branch.last_revision_info()
self.assertEqual(
[('call', 'Branch.last_revision_info', ('///quack/',))],
client._calls)
self.assertEqual((0, NULL_REVISION), result)
def test_non_empty_branch(self):
# in a non-empty branch we also decode the response properly
client = FakeClient([('ok', '2', u'\xc8'.encode('utf8'))])
transport = MemoryTransport()
transport.mkdir('kwaak')
transport = transport.clone('kwaak')
# we do not want bzrdir to make any remote calls
bzrdir = RemoteBzrDir(transport, _client=False)
branch = RemoteBranch(bzrdir, None, _client=client)
result = branch.last_revision_info()
self.assertEqual(
[('call', 'Branch.last_revision_info', ('///kwaak/',))],
client._calls)
self.assertEqual((2, u'\xc8'), result)
|