1
# Copyright (C) 2011 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
from bzrlib.tests import (
27
class TestRememberMixin(object):
28
"""--remember and --no-remember set locations or not."""
30
# the command to run (expecting additional arguments from the tests
32
# the dir where the command should be run (it should contain a branch for
33
# which the tested locations are/will be set)
35
# argument list for the first command invocation
37
# argument list for the next command invocation
40
def do_command(self, *args):
41
# We always expect the same result here and care only about the
42
# arguments used and their consequences on the remembered locations
43
out, err = self.run_bzr(self.command + list(args),
44
working_dir=self.working_dir)
46
def test_first_use_no_option(self):
47
self.do_command(*self.first_use_args)
48
self.assertLocations(self.first_use_args)
50
def test_first_use_remember(self):
51
self.do_command('--remember', *self.first_use_args)
52
self.assertLocations(self.first_use_args)
54
def test_first_use_no_remember(self):
55
self.do_command('--no-remember', *self.first_use_args)
56
self.assertLocations([])
58
def test_next_uses_no_option(self):
59
self.setup_next_uses()
60
self.do_command(*self.next_uses_args)
61
self.assertLocations(self.first_use_args)
63
def test_next_uses_remember(self):
64
self.setup_next_uses()
65
self.do_command('--remember', *self.next_uses_args)
66
self.assertLocations(self.next_uses_args)
68
def test_next_uses_no_remember(self):
69
self.setup_next_uses()
70
self.do_command('--no-remember', *self.next_uses_args)
71
self.assertLocations(self.first_use_args)
74
class TestSendRemember(script.TestCaseWithTransportAndScript,
78
command = ['send', '-o-',]
79
first_use_args = ['../parent', '../grand_parent',]
80
next_uses_args = ['../new_parent', '../new_grand_parent']
83
super(TestSendRemember, self).setUp()
85
$ bzr init grand_parent
87
$ echo grand_parent > file
89
$ bzr commit -m 'initial commit'
91
$ bzr branch grand_parent parent
94
$ bzr commit -m 'parent'
96
$ bzr branch parent %(working_dir)s
98
$ echo %(working_dir)s > file
99
$ bzr commit -m '%(working_dir)s'
101
''' % {'working_dir': self.working_dir},
102
null_output_matches_anything=True)
104
def setup_next_uses(self):
105
# Do a first send that remembers the locations
106
self.do_command(*self.first_use_args)
107
# Now create some new targets
109
$ bzr branch grand_parent new_grand_parent
110
$ bzr branch parent new_parent
112
null_output_matches_anything=True)
114
def assertLocations(self, expected_locations):
115
if not expected_locations:
116
expected_submit_branch, expected_public_branch = None, None
118
expected_submit_branch, expected_public_branch = expected_locations
119
br, _ = branch.Branch.open_containing(self.working_dir)
120
self.assertEquals(expected_submit_branch, br.get_submit_branch())
121
self.assertEquals(expected_public_branch, br.get_public_branch())
124
class TestPushRemember(script.TestCaseWithTransportAndScript,
129
first_use_args = ['../target',]
130
next_uses_args = ['../new_target']
133
super(TestPushRemember, self).setUp()
135
$ bzr init %(working_dir)s
137
$ echo some content > file
139
$ bzr commit -m 'initial commit'
141
''' % {'working_dir': self.working_dir},
142
null_output_matches_anything=True)
144
def setup_next_uses(self):
145
# Do a first push that remembers the location
146
self.do_command(*self.first_use_args)
147
# Now create some new content
150
$ echo new content > file
151
$ bzr commit -m 'new content'
153
''' % {'working_dir': self.working_dir},
154
null_output_matches_anything=True)
156
def assertLocations(self, expected_locations):
157
br, _ = branch.Branch.open_containing(self.working_dir)
158
if not expected_locations:
159
self.assertEquals(None, br.get_push_location())
161
expected_push_location = expected_locations[0]
162
push_location = urlutils.relative_url(br.base,
163
br.get_push_location())
164
self.assertIsSameRealPath(expected_push_location, push_location)
167
class TestPullRemember(script.TestCaseWithTransportAndScript,
172
first_use_args = ['../parent',]
173
next_uses_args = ['../new_parent']
176
super(TestPullRemember, self).setUp()
182
$ bzr commit -m 'initial commit'
184
$ bzr init %(working_dir)s
185
''' % {'working_dir': self.working_dir},
186
null_output_matches_anything=True)
188
def setup_next_uses(self):
189
# Do a first push that remembers the location
190
self.do_command(*self.first_use_args)
191
# Now create some new content
193
$ bzr branch parent new_parent
195
$ echo new parent > file
196
$ bzr commit -m 'new parent'
198
''' % {'working_dir': self.working_dir},
199
null_output_matches_anything=True)
201
def assertLocations(self, expected_locations):
202
br, _ = branch.Branch.open_containing(self.working_dir)
203
if not expected_locations:
204
self.assertEquals(None, br.get_parent())
206
expected_pull_location = expected_locations[0]
207
pull_location = urlutils.relative_url(br.base, br.get_parent())
208
self.assertIsSameRealPath(expected_pull_location, pull_location)