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

« back to all changes in this revision

Viewing changes to tests/test_build_juju.py

  • Committer: Curtis Hovey
  • Date: 2014-08-12 20:35:41 UTC
  • mto: This revision was merged to the branch mainline in revision 623.
  • Revision ID: curtis@canonical.com-20140812203541-ebdge5usoltynmk1
Strip the /tools dir from from the tools-metadata-url because s3 will return a 404
for a dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from mock import patch
2
 
import os
3
 
from unittest import TestCase
4
 
 
5
 
from jujuci import (
6
 
    Artifact,
7
 
    Credentials,
8
 
    )
9
 
from build_juju import (
10
 
    build_juju,
11
 
    get_script,
12
 
    main,
13
 
)
14
 
from utility import temp_dir
15
 
 
16
 
 
17
 
class JujuBuildTestCase(TestCase):
18
 
 
19
 
    def test_main_options(self):
20
 
        with patch('build_juju.build_juju', autospec=True) as mock:
21
 
            main(['-d', '-v', '-b', '1234', 'win-client', './foo',
22
 
                  '--user', 'jrandom', '--password', 'password1'])
23
 
            args, kwargs = mock.call_args
24
 
            self.assertEqual(
25
 
                (Credentials('jrandom', 'password1'), 'win-client', './foo',
26
 
                 '1234'), args)
27
 
            self.assertTrue(kwargs['dry_run'])
28
 
            self.assertTrue(kwargs['verbose'])
29
 
 
30
 
    def test_build_juju(self):
31
 
        credentials = Credentials('jrandom', 'password1')
32
 
        with temp_dir() as base_dir:
33
 
            work_dir = os.path.join(base_dir, 'workspace')
34
 
            with patch('build_juju.setup_workspace', autospec=True) as sw_mock:
35
 
                artifacts = [
36
 
                    Artifact('juju-core_1.2.3.tar.gz', 'http:...')]
37
 
                with patch('build_juju.get_artifacts',
38
 
                           return_value=artifacts, autospec=True) as ga_mock:
39
 
                    with patch('build_juju.run_command') as rc_mock:
40
 
                        with patch('build_juju.add_artifacts', autospec=True
41
 
                                   ) as aa_mock:
42
 
                            build_juju(
43
 
                                credentials, 'win-client', work_dir,
44
 
                                'lastSucessful', dry_run=True, verbose=True)
45
 
        self.assertEqual((work_dir, ), sw_mock.call_args[0])
46
 
        self.assertEqual(
47
 
            {'dry_run': True, 'verbose': True}, sw_mock.call_args[1])
48
 
        self.assertEqual(
49
 
            (credentials, 'build-revision', 'lastSucessful',
50
 
             'juju-core_*.tar.gz', work_dir,),
51
 
            ga_mock.call_args[0])
52
 
        self.assertEqual(
53
 
            {'archive': False, 'dry_run': True, 'verbose': True},
54
 
            ga_mock.call_args[1])
55
 
        crossbuild = get_script()
56
 
        self.assertEqual(
57
 
            ([crossbuild, 'win-client', '-b', '~/crossbuild',
58
 
              'juju-core_1.2.3.tar.gz'], ),
59
 
            rc_mock.call_args[0])
60
 
        self.assertEqual(
61
 
            {'dry_run': True, 'verbose': True}, rc_mock.call_args[1])
62
 
        globs = [
63
 
            'juju-setup-*.exe', 'juju-*-win2012-amd64.tgz',
64
 
            'juju-*-osx.tar.gz', 'juju-*-centos7-amd64.tgz',
65
 
            'juju-*-centos7.tar.gz']
66
 
        self.assertEqual((work_dir, globs), aa_mock.call_args[0])
67
 
        self.assertEqual(
68
 
            {'dry_run': True, 'verbose': True}, aa_mock.call_args[1])
69
 
 
70
 
    def test_get_script(self):
71
 
        self.assertEqual(
72
 
            '/foo/juju-release-tools/crossbuild.py',
73
 
            get_script('/foo/juju-release-tools'))
74
 
        parent_dir = os.path.realpath(
75
 
            os.path.join(__file__, '..', '..', '..'))
76
 
        self.assertEqual(
77
 
            os.path.join(parent_dir, 'juju-release-tools', 'crossbuild.py'),
78
 
            get_script())