bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
1 |
# Copyright (C) 2006, 2007 Canonical Ltd
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
2 |
#
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Tests for remote bzrdir/branch/repo/etc
|
|
18 |
||
19 |
These are proxy objects which act on remote objects by sending messages
|
|
20 |
through a smart client. The proxies are to be created when attempting to open
|
|
21 |
the object given a transport that supports smartserver rpc operations.
|
|
22 |
"""
|
|
23 |
||
24 |
from bzrlib import bzrdir, remote, tests |
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
25 |
from bzrlib.branch import Branch |
26 |
from bzrlib.bzrdir import BzrDir, BzrDirFormat |
|
27 |
from bzrlib.remote import ( |
|
28 |
RemoteBranch, |
|
29 |
RemoteBzrDir, |
|
30 |
RemoteBzrDirFormat, |
|
31 |
)
|
|
32 |
from bzrlib.revision import NULL_REVISION |
|
33 |
from bzrlib.smart import server |
|
34 |
from bzrlib.smart.client import SmartClient |
|
|
2018.5.20
by Andrew Bennetts
Move bzrlib/transport/smart/_smart.py to bzrlib/transport/remote.py and rename SmartTransport to RemoteTransport (Robert Collins, Andrew Bennetts) |
35 |
from bzrlib.transport import remote as remote_transport |
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
36 |
from bzrlib.transport.memory import MemoryTransport |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
37 |
|
|
2018.5.24
by Andrew Bennetts
Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts) |
38 |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
39 |
class BasicRemoteObjectTests(tests.TestCaseWithTransport): |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
40 |
|
41 |
def setUp(self): |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
42 |
super(BasicRemoteObjectTests, self).setUp() |
43 |
self.transport_server = server.SmartTCPServer_for_testing |
|
44 |
self.transport = self.get_transport() |
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
45 |
self.client = self.transport.get_smart_client() |
46 |
# make a branch that can be opened over the smart transport
|
|
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
47 |
self.local_wt = BzrDir.create_standalone_workingtree('.') |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
48 |
|
49 |
def test_create_remote_bzrdir(self): |
|
50 |
b = remote.RemoteBzrDir(self.transport) |
|
51 |
self.assertIsInstance(b, BzrDir) |
|
52 |
||
53 |
def test_open_remote_branch(self): |
|
|
2018.6.1
by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS. |
54 |
# open a standalone branch in the working directory
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
55 |
b = remote.RemoteBzrDir(self.transport) |
56 |
branch = b.open_branch() |
|
57 |
||
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
58 |
def test_remote_repository(self): |
59 |
b = BzrDir.open_from_transport(self.transport) |
|
60 |
repo = b.open_repository() |
|
|
2018.5.40
by Robert Collins
Implement a remote Repository.has_revision method. |
61 |
revid = u'\xc823123123' |
62 |
self.assertFalse(repo.has_revision(revid)) |
|
63 |
self.local_wt.commit(message='test commit', rev_id=revid) |
|
64 |
self.assertTrue(repo.has_revision(revid)) |
|
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
65 |
|
66 |
def test_remote_branch_revision_history(self): |
|
67 |
b = BzrDir.open_from_transport(self.transport).open_branch() |
|
|
2018.5.38
by Robert Collins
Implement RemoteBranch.revision_history(). |
68 |
self.assertEqual([], b.revision_history()) |
69 |
r1 = self.local_wt.commit('1st commit') |
|
70 |
r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8') |
|
71 |
self.assertEqual([r1, r2], b.revision_history()) |
|
|
1752.2.31
by Martin Pool
[broken] some support for write operations over hpss |
72 |
|
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
73 |
def test_find_correct_format(self): |
|
2018.5.20
by Andrew Bennetts
Move bzrlib/transport/smart/_smart.py to bzrlib/transport/remote.py and rename SmartTransport to RemoteTransport (Robert Collins, Andrew Bennetts) |
74 |
"""Should open a RemoteBzrDir over a RemoteTransport""" |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
75 |
fmt = BzrDirFormat.find_format(self.transport) |
|
2018.5.25
by Andrew Bennetts
Make sure RemoteBzrDirFormat is always registered (John Arbash Meinel, Robert Collins, Andrew Bennetts). |
76 |
self.assertTrue(RemoteBzrDirFormat in BzrDirFormat._control_formats) |
|
1752.2.30
by Martin Pool
Start adding a RemoteBzrDir, etc |
77 |
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat) |
78 |
||
79 |
def test_open_detected_smart_format(self): |
|
80 |
fmt = BzrDirFormat.find_format(self.transport) |
|
81 |
d = fmt.open(self.transport) |
|
82 |
self.assertIsInstance(d, BzrDir) |
|
|
2018.5.51
by Wouter van Heyst
Test and implement RemoteBranch.last_revision_info() |
83 |
|
84 |
||
85 |
class FakeClient(SmartClient): |
|
86 |
"""Lookalike for SmartClient allowing testing.""" |
|
87 |
||
88 |
def __init__(self, responses): |
|
89 |
# We don't call the super init because there is no medium.
|
|
90 |
self.responses = responses |
|
91 |
self._calls = [] |
|
92 |
||
93 |
def call(self, method, *args): |
|
94 |
self._calls.append(('call', method, args)) |
|
95 |
return self.responses.pop(0) |
|
96 |
||
97 |
||
98 |
class TestBranchLastRevisionInfo(tests.TestCase): |
|
99 |
||
100 |
def test_empty_branch(self): |
|
101 |
# in an empty branch we decode the response properly
|
|
102 |
client = FakeClient([('ok', '0', '')]) |
|
103 |
transport = MemoryTransport() |
|
104 |
transport.mkdir('quack') |
|
105 |
transport = transport.clone('quack') |
|
106 |
# we do not want bzrdir to make any remote calls
|
|
107 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
108 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
109 |
result = branch.last_revision_info() |
|
110 |
||
111 |
self.assertEqual( |
|
112 |
[('call', 'Branch.last_revision_info', ('///quack/',))], |
|
113 |
client._calls) |
|
114 |
self.assertEqual((0, NULL_REVISION), result) |
|
115 |
||
116 |
def test_non_empty_branch(self): |
|
117 |
# in a non-empty branch we also decode the response properly
|
|
118 |
||
119 |
client = FakeClient([('ok', '2', u'\xc8'.encode('utf8'))]) |
|
120 |
transport = MemoryTransport() |
|
121 |
transport.mkdir('kwaak') |
|
122 |
transport = transport.clone('kwaak') |
|
123 |
# we do not want bzrdir to make any remote calls
|
|
124 |
bzrdir = RemoteBzrDir(transport, _client=False) |
|
125 |
branch = RemoteBranch(bzrdir, None, _client=client) |
|
126 |
result = branch.last_revision_info() |
|
127 |
||
128 |
self.assertEqual( |
|
129 |
[('call', 'Branch.last_revision_info', ('///kwaak/',))], |
|
130 |
client._calls) |
|
131 |
self.assertEqual((2, u'\xc8'), result) |