~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to test_schedule_reliability_tests.py

  • Committer: Curtis Hovey
  • Date: 2015-06-11 19:35:22 UTC
  • mto: This revision was merged to the branch mainline in revision 983.
  • Revision ID: curtis@canonical.com-20150611193522-o2nqkqb04o2i75wv
Remove euca_dump_logs because it has not been used this year.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from unittest import TestCase
1
2
from argparse import Namespace
2
 
from contextlib import contextmanager
3
 
from unittest import TestCase
4
3
 
5
4
from mock import (
6
5
    call,
16
15
from schedule_reliability_tests import (
17
16
    build_job,
18
17
    parse_args,
19
 
    main,
20
18
    )
21
19
from test_utility import (
22
 
    make_candidate_dir,
 
20
    parse_error,
 
21
    write_config,
23
22
    )
24
 
from tests import parse_error
25
23
from utility import temp_dir
26
24
 
27
25
 
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
83
82
        expected = [
84
 
            call('foo', {
85
 
                'suite': 'qux',
86
 
                'attempts': '10',
87
 
                'revision_build': '1',
88
 
                }),
89
 
            call('foo', {
90
 
                'suite': 'qux',
91
 
                'attempts': '10',
92
 
                'revision_build': '2'
93
 
                }),
 
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'),
94
87
            ]
95
88
        self.assertEqual(calls, expected)
96
89
 
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(
103
 
            'foo', {
104
 
                'suite': 'qux,quxx',
105
 
                'attempts': '10',
106
 
                'revision_build': '1',
107
 
                })
108
 
 
109
 
 
110
 
class TestMain(TestCase):
111
 
 
112
 
    @contextmanager
113
 
    def build_job_context(self):
114
 
        with temp_dir() as root:
115
 
            yield root
116
 
 
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
121
 
 
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', {
128
 
            'attempts': '10',
129
 
            'suite': 'full',
130
 
            'revision_build': '1234',
131
 
            })
132
 
 
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:
137
 
            make_candidate_dir(
138
 
                root, 'branch1-artifacts', 'mybranch1')
139
 
            make_candidate_dir(
140
 
                root, 'branch2-artifacts', 'mybranch2')
141
 
            make_candidate_dir(
142
 
                root, 'branch3-artifacts', 'mybranch3')
143
 
            make_candidate_dir(
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')