75
73
def test_build_job(self):
76
74
jenkins_cxt = patch('schedule_reliability_tests.Jenkins')
77
75
with jenkins_cxt as jenkins_mock, temp_dir() as root:
76
write_config(root, 'foo', 'quxxx')
78
77
build_job(Credentials('jrandom', 'password1'), root, 'foo',
79
[('bar', 1), ('baz', 2)], ['qux'])
78
['bar', 'baz'], ['qux'])
80
79
jenkins_mock.assert_called_once_with(
81
'http://juju-ci.vapour.ws:8080', 'jrandom', 'password1')
80
'http://localhost:8080', 'jrandom', 'password1')
82
81
calls = jenkins_mock.return_value.build_job.mock_calls
87
'revision_build': '1',
83
call('foo', {'suite': 'qux', 'attempts': '10',
84
'new_juju_dir': 'bar'}, token='quxxx'),
85
call('foo', {'suite': 'qux', 'attempts': '10',
86
'new_juju_dir': 'baz'}, token='quxxx'),
95
88
self.assertEqual(calls, expected)
97
90
def test_build_job_multi_suite(self):
98
91
jenkins_cxt = patch('schedule_reliability_tests.Jenkins')
99
92
with jenkins_cxt as jenkins_mock, temp_dir() as root:
93
write_config(root, 'foo', 'bar')
100
94
build_job(Credentials('jrandom', 'password1'), root, 'foo',
101
[('baz', 1)], ['qux', 'quxx'])
95
['baz'], ['qux', 'quxx'])
102
96
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)
97
'foo', {'suite': 'qux,quxx', 'attempts': '10',
98
'new_juju_dir': 'baz'}, token='bar')