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

« back to all changes in this revision

Viewing changes to tests/test_utility.py

  • Committer: Aaron Bentley
  • Date: 2016-03-18 03:02:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1323.
  • Revision ID: aaron.bentley@canonical.com-20160318030201-ki8wfpaeawgh9oqz
assess_cs_staging pokes state server via admin model.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import os
13
13
import socket
14
14
from time import time
15
 
import warnings
16
15
 
17
16
from mock import (
18
17
    call,
19
18
    patch,
20
19
    )
21
20
 
22
 
from tests import (
23
 
    temp_os_env,
24
 
    TestCase,
25
 
)
 
21
from tests import TestCase
26
22
from utility import (
27
23
    add_basic_testing_arguments,
28
24
    as_literal_address,
35
31
    get_deb_arch,
36
32
    get_winrm_certs,
37
33
    is_ipv6_address,
38
 
    local_charm_path,
39
34
    quote,
40
35
    run_command,
41
36
    scoped_environ,
383
378
            parser.parse_args(cmd_line)
384
379
 
385
380
    def test_warns_on_dirty_logs(self):
386
 
        with warnings.catch_warnings(record=True) as warned:
387
 
            with temp_dir() as log_dir:
388
 
                open(os.path.join(log_dir, "existing.log"), "w").close()
389
 
                cmd_line = ['local', '/a/juju', log_dir, 'testtest']
390
 
                parser = add_basic_testing_arguments(ArgumentParser())
391
 
                parser.parse_args(cmd_line)
392
 
            self.assertEqual(len(warned), 1)
393
 
            self.assertRegexpMatches(
394
 
                str(warned[0].message),
395
 
                r"^Directory '.*' has existing contents.$")
396
 
        self.assertEqual("", self.log_stream.getvalue())
397
 
 
398
 
    def test_no_warn_on_empty_logs(self):
399
 
        """Special case a file named 'empty' doesn't make log dir dirty"""
400
 
        with warnings.catch_warnings(record=True) as warned:
401
 
            with temp_dir() as log_dir:
402
 
                open(os.path.join(log_dir, "empty"), "w").close()
403
 
                cmd_line = ['local', '/a/juju', log_dir, 'testtest']
404
 
                parser = add_basic_testing_arguments(ArgumentParser())
405
 
                parser.parse_args(cmd_line)
406
 
            self.assertEqual(warned, [])
407
 
        self.assertEqual("", self.log_stream.getvalue())
 
381
        with temp_dir() as log_dir:
 
382
            open(os.path.join(log_dir, "existing.log"), "w").close()
 
383
            cmd_line = ['local', '/a/juju', log_dir, 'testtest']
 
384
            parser = add_basic_testing_arguments(ArgumentParser())
 
385
            parser.parse_args(cmd_line)
 
386
        self.assertRegexpMatches(
 
387
            self.log_stream.getvalue(),
 
388
            r"^WARNING Directory '.*' has existing contents.$")
408
389
 
409
390
    def test_debug(self):
410
391
        cmd_line = ['local', '/foo/juju', '/tmp/logs', 'testtest', '--debug']
569
550
            self.assertTrue(os.path.exists(d))
570
551
            self.assertTrue(os.path.exists(os.path.join(d, "a-file")))
571
552
        self.assertFalse(os.path.exists(p))
572
 
 
573
 
 
574
 
class TestLocalCharm(TestCase):
575
 
 
576
 
    def test_make_local_charm_1x(self):
577
 
        charm = 'mysql'
578
 
        path = local_charm_path(charm, '1.25.0')
579
 
        self.assertEqual(path, 'local:mysql')
580
 
 
581
 
    def test_make_local_charm_1x_series(self):
582
 
        charm = 'mysql'
583
 
        path = local_charm_path(charm, '1.25.0', series='trusty')
584
 
        self.assertEqual(path, 'local:trusty/mysql')
585
 
 
586
 
    def test_make_local_charm_2x(self):
587
 
        charm = 'mysql'
588
 
        path = local_charm_path(charm, '2.0.0', repository='/tmp/charms')
589
 
        self.assertEqual(path, '/tmp/charms/mysql')
590
 
 
591
 
    def test_make_local_charm_2x_os_env(self):
592
 
        charm = 'mysql'
593
 
        with temp_os_env('JUJU_REPOSITORY', '/home/foo/repository'):
594
 
            path = local_charm_path(charm, '2.0.0')
595
 
        self.assertEqual(path, '/home/foo/repository/charms/mysql')
596
 
 
597
 
    def test_make_local_charm_2x_win(self):
598
 
        charm = 'mysql'
599
 
        with temp_os_env('JUJU_REPOSITORY', '/home/foo/repository'):
600
 
            path = local_charm_path(charm, '2.0.0', platform='win')
601
 
        self.assertEqual(path, '/home/foo/repository/charms-win/mysql')
602
 
 
603
 
    def test_make_local_charm_2x_centos(self):
604
 
        charm = 'mysql'
605
 
        with temp_os_env('JUJU_REPOSITORY', '/home/foo/repository'):
606
 
            path = local_charm_path(charm, '2.0.0', platform='centos')
607
 
        self.assertEqual(path, '/home/foo/repository/charms-centos/mysql')