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

« back to all changes in this revision

Viewing changes to test_openstack_basic_check.py

  • Committer: John George
  • Date: 2015-06-30 07:22:09 UTC
  • mto: This revision was merged to the branch mainline in revision 1013.
  • Revision ID: john.george@canonical.com-20150630072209-cjredkcw9cd2gm9q
Add juju-ci-openstack-check.sh and move run_deployer() out of deploy_stack.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
__metaclass__ = type
 
2
from argparse import Namespace
 
3
from contextlib import contextmanager
 
4
import os
 
5
from unittest import TestCase
 
6
 
 
7
 
 
8
from openstack_basic_check import (
 
9
    get_args,
 
10
    set_environ,
 
11
    )
 
12
 
 
13
 
 
14
class TestGetArgs(TestCase):
 
15
 
 
16
    def test_get_args_defaults(self):
 
17
        args = get_args(
 
18
            ['--user', 'admin', '--password', 'password', '--tenant', 'foo',
 
19
             '--region', 'bar', '--auth-url', 'http://example.com'])
 
20
        self.assertEqual('admin', args.user)
 
21
        self.assertEqual('password', args.password)
 
22
        self.assertEqual('foo', args.tenant)
 
23
        self.assertEqual('bar', args.region)
 
24
        self.assertEqual('http://example.com', args.auth_url)
 
25
 
 
26
    def test_get_args_raises_without_user(self):
 
27
        with self.assertRaisesRegexp(
 
28
                Exception, 'User must be provided'):
 
29
            get_args(
 
30
                ['--password', 'password', '--tenant', 'foo',
 
31
                 '--region', 'bar', '--auth-url', 'http://example.com'])
 
32
 
 
33
    def test_get_args_raises_without_password(self):
 
34
        with self.assertRaisesRegexp(
 
35
                Exception, 'Password must be provided'):
 
36
            get_args(
 
37
                ['--user', 'admin', '--tenant', 'foo',
 
38
                 '--region', 'bar', '--auth-url', 'http://example.com'])
 
39
 
 
40
    def test_get_args_raises_without_tenant(self):
 
41
        with self.assertRaisesRegexp(
 
42
                Exception, 'Tenant must be provided'):
 
43
            get_args(
 
44
                ['--user', 'admin', '--password', 'password',
 
45
                 '--region', 'bar', '--auth-url', 'http://example.com'])
 
46
 
 
47
    def test_get_args_raises_without_region(self):
 
48
        with self.assertRaisesRegexp(
 
49
                Exception, 'Region must be provided'):
 
50
            get_args(
 
51
                ['--user', 'admin', '--password', 'password', '--tenant',
 
52
                 'foo', '--auth-url', 'http://example.com'])
 
53
 
 
54
    def test_get_args_raises_without_auth_url(self):
 
55
        with self.assertRaisesRegexp(
 
56
                Exception, 'auth-url must be provided'):
 
57
            get_args(
 
58
                ['--user', 'admin', '--password', 'password', '--tenant',
 
59
                 'foo', '--region', 'bar'])
 
60
 
 
61
 
 
62
@contextmanager
 
63
def saved_env():
 
64
    old_environ = dict(os.environ)
 
65
    try:
 
66
        yield
 
67
    finally:
 
68
        os.environ.clear()
 
69
        os.environ.update(old_environ)
 
70
 
 
71
 
 
72
class TestSetEnviron(TestCase):
 
73
 
 
74
    def test_set_environ(self):
 
75
        with saved_env():
 
76
            set_environ(Namespace(user='admin', password='passwd',
 
77
                        tenant='bar', region='foo',
 
78
                        auth_url='http://a.com:5000/v2.0'))
 
79
            self.assertEqual(os.environ['OS_USERNAME'], 'admin')
 
80
            self.assertEqual(os.environ['OS_PASSWORD'], 'passwd')
 
81
            self.assertEqual(os.environ['OS_TENANT_NAME'], 'bar')
 
82
            self.assertEqual(os.environ['OS_REGION_NAME'], 'foo')
 
83
            self.assertEqual(os.environ['OS_AUTH_URL'],
 
84
                             'http://a.com:5000/v2.0')