109
105
class TestFindCandidates(TestCase):
111
def test__find_candidates_artifacts_default(self):
112
with temp_dir() as root:
113
make_candidate_dir(root, 'master-artifacts')
114
make_candidate_dir(root, '1.25')
115
candidate = os.path.join(root, 'candidate', '1.25')
116
self.assertEqual(list(_find_candidates(root)), [
117
(candidate, os.path.join(candidate, 'buildvars.json'))])
119
def test__find_candidates_artifacts_enabled(self):
120
with temp_dir() as root:
121
make_candidate_dir(root, 'master-artifacts')
122
make_candidate_dir(root, '1.25')
123
candidate = os.path.join(root, 'candidate', 'master-artifacts')
124
self.assertEqual(list(_find_candidates(root, artifacts=True)), [
125
(candidate, os.path.join(candidate, 'buildvars.json'))])
127
107
def test_find_candidates(self):
128
108
with temp_dir() as root:
129
109
master_path = make_candidate_dir(root, 'master')
176
156
def test_find_latest_branch_candidates(self):
177
157
with temp_dir() as root:
178
master_path = make_candidate_dir(root, 'master-artifacts')
158
master_path = make_candidate_dir(root, 'master')
179
159
self.assertEqual(find_latest_branch_candidates(root),
180
[(master_path, 1234)])
182
162
def test_find_latest_branch_candidates_old_buildvars(self):
183
163
with temp_dir() as root:
184
164
a_week_ago = time() - timedelta(days=7, seconds=1).total_seconds()
185
make_candidate_dir(root, 'master-artifacts', modified=a_week_ago)
165
make_candidate_dir(root, 'master', modified=a_week_ago)
186
166
self.assertEqual(find_latest_branch_candidates(root), [])
188
168
def test_ignore_older_revision_build(self):
189
169
with temp_dir() as root:
190
170
path_1234 = make_candidate_dir(
191
root, '1234-artifacts', 'mybranch', '1234')
171
root, '1234', 'mybranch', '1234')
192
172
make_candidate_dir(root, '1233', 'mybranch', '1233')
193
self.assertEqual(find_latest_branch_candidates(root), [
173
self.assertEqual(find_latest_branch_candidates(root), [path_1234])
196
175
def test_include_older_revision_build_different_branch(self):
197
176
with temp_dir() as root:
198
177
path_1234 = make_candidate_dir(
199
root, '1234-artifacts', 'branch_foo', '1234')
178
root, '1234', 'branch_foo', '1234')
200
179
path_1233 = make_candidate_dir(
201
root, '1233-artifacts', 'branch_bar', '1233')
180
root, '1233', 'branch_bar', '1233')
202
181
self.assertItemsEqual(
203
find_latest_branch_candidates(root), [
204
(path_1233, 1233), (path_1234, 1234)])
182
find_latest_branch_candidates(root), [path_1233, path_1234])
207
185
class TestAsLiteralAddress(TestCase):
235
213
self.assertIs(False, result)
238
class TestSplitAddressPort(TestCase):
240
def test_hostname(self):
242
("name.testing", None), split_address_port("name.testing"))
246
("127.0.0.2", "17017"), split_address_port("127.0.0.2:17017"))
250
("2001:db8::7", "17017"), split_address_port("2001:db8::7:17017"))
253
216
class TestWaitForPort(TestCase):
255
218
def test_wait_for_port_0000_closed(self):
384
347
args = parser.parse_args(cmd_line)
385
348
self.assertEqual(args.juju_bin, 'c:\\juju.exe')
387
def test_warns_on_dirty_logs(self):
388
with warnings.catch_warnings(record=True) as warned:
389
with temp_dir() as log_dir:
390
open(os.path.join(log_dir, "existing.log"), "w").close()
391
cmd_line = ['local', '/a/juju', log_dir, 'testtest']
392
parser = add_basic_testing_arguments(ArgumentParser())
393
parser.parse_args(cmd_line)
394
self.assertEqual(len(warned), 1)
395
self.assertRegexpMatches(
396
str(warned[0].message),
397
r"^Directory '.*' has existing contents.$")
398
self.assertEqual("", self.log_stream.getvalue())
350
def test_positional_args_raises_ErrJujuPath(self):
351
cmd_line = ['local', '/foo', '/tmp/logs', 'testtest']
352
parser = add_basic_testing_arguments(ArgumentParser())
353
with self.assertRaises(ErrJujuPath):
354
parser.parse_args(cmd_line)
400
def test_no_warn_on_empty_logs(self):
401
"""Special case a file named 'empty' doesn't make log dir dirty"""
402
with warnings.catch_warnings(record=True) as warned:
403
with temp_dir() as log_dir:
404
open(os.path.join(log_dir, "empty"), "w").close()
405
cmd_line = ['local', '/a/juju', log_dir, 'testtest']
406
parser = add_basic_testing_arguments(ArgumentParser())
407
parser.parse_args(cmd_line)
408
self.assertEqual(warned, [])
409
self.assertEqual("", self.log_stream.getvalue())
356
def test_positional_args_juju_bin_empty(self):
357
cmd_line = ['local', '', '/tmp/logs', 'testtest']
358
parser = add_basic_testing_arguments(ArgumentParser())
359
with self.assertRaises(ErrJujuPath):
360
parser.parse_args(cmd_line)
411
362
def test_debug(self):
412
363
cmd_line = ['local', '/foo/juju', '/tmp/logs', 'testtest', '--debug']