2
from argparse import Namespace
3
from contextlib import contextmanager
5
from unittest import TestCase
8
from openstack_basic_check import (
14
class TestGetArgs(TestCase):
16
def test_get_args_defaults(self):
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)
26
def test_get_args_raises_without_user(self):
27
with self.assertRaisesRegexp(
28
Exception, 'User must be provided'):
30
['--password', 'password', '--tenant', 'foo',
31
'--region', 'bar', '--auth-url', 'http://example.com'])
33
def test_get_args_raises_without_password(self):
34
with self.assertRaisesRegexp(
35
Exception, 'Password must be provided'):
37
['--user', 'admin', '--tenant', 'foo',
38
'--region', 'bar', '--auth-url', 'http://example.com'])
40
def test_get_args_raises_without_tenant(self):
41
with self.assertRaisesRegexp(
42
Exception, 'Tenant must be provided'):
44
['--user', 'admin', '--password', 'password',
45
'--region', 'bar', '--auth-url', 'http://example.com'])
47
def test_get_args_raises_without_region(self):
48
with self.assertRaisesRegexp(
49
Exception, 'Region must be provided'):
51
['--user', 'admin', '--password', 'password', '--tenant',
52
'foo', '--auth-url', 'http://example.com'])
54
def test_get_args_raises_without_auth_url(self):
55
with self.assertRaisesRegexp(
56
Exception, 'auth-url must be provided'):
58
['--user', 'admin', '--password', 'password', '--tenant',
59
'foo', '--region', 'bar'])
64
old_environ = dict(os.environ)
69
os.environ.update(old_environ)
72
class TestSetEnviron(TestCase):
74
def test_set_environ(self):
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')