1
from argparse import Namespace
2
from contextlib import contextmanager
3
from unittest import TestCase
10
from industrial_test import (
15
from jujuci import Credentials
16
from schedule_reliability_tests import (
21
from test_utility import (
24
from tests import parse_error
25
from utility import temp_dir
28
class TestParseArgs(TestCase):
30
def test_parse_args(self):
31
args, credentials = parse_args([
32
'foo', '--user', 'jrandom', '--password', 'password1'])
35
Namespace(root_dir='foo', suite=[], jobs=None, user='jrandom',
36
password='password1'))
37
self.assertEqual(credentials,
38
Credentials(user='jrandom', password='password1'))
40
def test_parse_args_suite_supports_known_suites(self):
41
for suite in suites.keys():
44
'foo', '--suite', suite, '--user', 'u', '--password',
46
Namespace(root_dir='foo', suite=[suite], jobs=None,
47
user='u', password='p'))
49
def test_parse_args_bad_suite(self):
50
with parse_error(self) as stderr:
51
parse_args(['foo', '--suite', 'foo'])
52
self.assertRegexpMatches(stderr.getvalue(),
53
".*invalid choice: 'foo'.*")
55
def test_parse_args_multi_suite(self):
56
args = parse_args(['foo', '--suite', FULL, '--suite', UPGRADE,
57
'--user=u', '--password=p'])[0]
58
self.assertEqual(args.suite, [FULL, UPGRADE])
60
def test_parse_jobs(self):
62
parse_args(['foo', 'bar', '--user', 'jrandom', '--password',
64
Namespace(root_dir='foo', suite=[], jobs=['bar'], user='jrandom',
65
password='password1'))
67
parse_args(['foo', 'bar', 'baz', '--user', 'jrandom',
68
'--password', 'password1'])[0],
69
Namespace(root_dir='foo', suite=[], jobs=['bar', 'baz'],
70
user='jrandom', password='password1'))
73
class TestBuildJob(TestCase):
75
def test_build_job(self):
76
jenkins_cxt = patch('schedule_reliability_tests.Jenkins')
77
with jenkins_cxt as jenkins_mock, temp_dir() as root:
78
build_job(Credentials('jrandom', 'password1'), root, 'foo',
79
[('bar', 1), ('baz', 2)], ['qux'])
80
jenkins_mock.assert_called_once_with(
81
'http://juju-ci.vapour.ws:8080', 'jrandom', 'password1')
82
calls = jenkins_mock.return_value.build_job.mock_calls
87
'revision_build': '1',
95
self.assertEqual(calls, expected)
97
def test_build_job_multi_suite(self):
98
jenkins_cxt = patch('schedule_reliability_tests.Jenkins')
99
with jenkins_cxt as jenkins_mock, temp_dir() as root:
100
build_job(Credentials('jrandom', 'password1'), root, 'foo',
101
[('baz', 1)], ['qux', 'quxx'])
102
jenkins_mock.return_value.build_job.assert_called_once_with(
106
'revision_build': '1',
110
class TestMain(TestCase):
113
def build_job_context(self):
114
with temp_dir() as root:
117
def run_main(self, root):
118
with patch('jenkins.Jenkins.build_job') as build_job_mock:
119
main([root, 'foo', '--user', 'bar', '--password', 'baz'])
120
return build_job_mock
122
def test_selects_newest_candidate(self):
123
with self.build_job_context() as root:
124
make_candidate_dir(root, '1234-artifacts', 'mybranch', '1234')
125
make_candidate_dir(root, '1233', 'mybranch', '1233')
126
build_job_mock = self.run_main(root)
127
build_job_mock.assert_called_once_with('foo', {
130
'revision_build': '1234',
133
def test_limit_3(self):
134
# Even though it's only testing the latest, it should only test 3,
135
# even if there are more than 3 latest.
136
with self.build_job_context() as root:
138
root, 'branch1-artifacts', 'mybranch1')
140
root, 'branch2-artifacts', 'mybranch2')
142
root, 'branch3-artifacts', 'mybranch3')
144
root, 'branch4-artifacts', 'mybranch4')
145
build_job_mock = self.run_main(root)
146
self.assertEqual(build_job_mock.call_count, 3)