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

« back to all changes in this revision

Viewing changes to tests/test_schedule_chaos_tests.py

  • Committer: John George
  • Date: 2015-01-14 22:03:47 UTC
  • mto: This revision was merged to the branch mainline in revision 798.
  • Revision ID: john.george@canonical.com-20150114220347-e8q5wezs1qg9a00u
Added support for setting the juju path, series and agent_url.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from argparse import Namespace
2
 
import os
3
 
from unittest import TestCase
4
 
 
5
 
from mock import (
6
 
    call,
7
 
    patch,
8
 
    )
9
 
 
10
 
from schedule_chaos_tests import(
11
 
    parse_args,
12
 
    main,
13
 
    start_job,
14
 
    )
15
 
from test_utility import (
16
 
    make_candidate_dir,
17
 
    write_config,
18
 
    )
19
 
from utility import temp_dir
20
 
 
21
 
 
22
 
class TestParseArgs(TestCase):
23
 
 
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',
29
 
                                         user='me'))
30
 
 
31
 
    @patch('sys.stderr')
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)
37
 
 
38
 
    @patch('sys.stderr')
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)
44
 
 
45
 
 
46
 
class TestStartJob(TestCase):
47
 
 
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},
57
 
                    token='token_str')]
58
 
        self.assertEqual(calls, expected)
59
 
 
60
 
 
61
 
class TestScheduleChaos(TestCase):
62
 
 
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')
71
 
        expected = [
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)