1
from argparse import Namespace
3
from unittest import TestCase
10
from schedule_chaos_tests import(
15
from test_utility import (
19
from utility import temp_dir
22
class TestParseArgs(TestCase):
24
def test_parse_args(self):
25
args = parse_args(['--user', 'me', '--password', 'pw',
26
'chaos', '/foo/bar', '7'])
27
self.assertEqual(args, Namespace(all=False, count=7, job='chaos',
28
password='pw', root_dir='/foo/bar',
32
def test_parse_args_missing_user(self, *args):
33
with self.assertRaises(SystemExit) as am:
34
parse_args(['--password', 'pw', 'chaos', '/foo/bar', '7'])
35
exception = am.exception
36
self.assertEqual(exception.code, 2)
39
def test_parse_args_missing_password(self, *args):
40
with self.assertRaises(SystemExit) as am:
41
parse_args(['--user', 'me', 'chaos', '/foo/bar', '7'])
42
exception = am.exception
43
self.assertEqual(exception.code, 2)
46
class TestStartJob(TestCase):
48
@patch('schedule_chaos_tests.Jenkins')
49
def test_start_job(self, j_mock):
50
with temp_dir() as root:
51
write_config(root, 'foo', 'token_str')
52
start_job(root, 'foo', '/some/path', 'me', 'pw', 1)
53
j_mock.assert_called_once_with('http://localhost:8080', 'me', 'pw')
54
calls = j_mock.return_value.build_job.mock_calls
55
expected = [call('foo', {'juju_bin': '/some/path',
56
'sequence_number': 1},
58
self.assertEqual(calls, expected)
61
class TestScheduleChaos(TestCase):
63
@patch('schedule_chaos_tests.start_job')
64
def test_schedule_chaos_tests(self, s_mock):
65
with temp_dir() as root:
66
make_candidate_dir(root, 'branch')
67
main(['--user', 'me', '--password', 'pw', 'chaos', root, '3'])
68
calls = s_mock.mock_calls
69
juju_bin = os.path.join(root,
70
'candidate', 'branch', 'usr', 'foo', 'juju')
72
call(root, 'chaos', juju_bin, 'me', 'pw', 0),
73
call(root, 'chaos', juju_bin, 'me', 'pw', 1),
74
call(root, 'chaos', juju_bin, 'me', 'pw', 2)]
75
self.assertEqual(calls, expected)