Fix tests

Change-Id: I8c6a1c4bc4dec052fbb5f2544f519253bc8be143
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou
2012-12-06 13:37:12 +01:00
parent 956259fbf8
commit 39e98f8a39
8 changed files with 18 additions and 326 deletions

View File

@@ -11,7 +11,7 @@
# under the License.
"""
Command-line interface to the OpenStack Metrices API.
Command-line interface to the OpenStack Metering API.
"""
import argparse

View File

@@ -15,6 +15,7 @@
from ceilometerclient.common import base
class User(base.Resource):
def __init__(self, manager, info, loaded=False):
_d = {unicode('user_id'): info}

View File

@@ -42,7 +42,8 @@ def do_sample_list(cc, args):
raise exc.CommandError('Samples not found: %s' % args.counter_name)
else:
field_labels = ['Resource ID', 'Name', 'Type', 'Volume', 'Timestamp']
fields = ['resource_id', 'counter_name', 'counter_type','counter_volume', 'timestamp']
fields = ['resource_id', 'counter_name', 'counter_type',
'counter_volume', 'timestamp']
utils.print_list(samples, fields, field_labels,
sortby=0)
@@ -63,7 +64,8 @@ def do_meter_list(cc, args={}):
'source': args.source}
meters = cc.meters.list(**fields)
field_labels = ['Name', 'Type', 'Resource ID', 'User ID', 'Project ID']
fields = ['counter_name', 'counter_type', 'resource_id', 'user_id', 'project_id']
fields = ['counter_name', 'counter_type', 'resource_id',
'user_id', 'project_id']
utils.print_list(meters, fields, field_labels,
sortby=0)

View File

@@ -15,5 +15,7 @@
from ceilometerclient.openstack.common import version as common_version
version_info = common_version.VersionInfo('ceilometerclient',
python_package='python-ceilometerclient')
version_info = common_version.VersionInfo(
'ceilometerclient',
python_package='python-ceilometerclient'
)

View File

@@ -5,6 +5,7 @@ import sys
import mox
import unittest
import unittest2
try:
import json
except ImportError:
@@ -14,97 +15,10 @@ from keystoneclient.v2_0 import client as ksclient
from ceilometerclient import exc
from ceilometerclient.v1 import client as v1client
import ceilometerclient.shell
import fakes
TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'var'))
class ShellValidationTest(unittest.TestCase):
def test_missing_auth(self):
_old_env, os.environ = os.environ, {
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where',
}
self.shell_error('list', 'You must provide a username')
os.environ = _old_env
_old_env, os.environ = os.environ, {
'OS_USERNAME': 'username',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where',
}
self.shell_error('list', 'You must provide a password')
os.environ = _old_env
_old_env, os.environ = os.environ, {
'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_AUTH_URL': 'http://no.where',
}
self.shell_error('list', 'You must provide a tenant_id')
os.environ = _old_env
_old_env, os.environ = os.environ, {
'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
}
self.shell_error('list', 'You must provide an auth url')
os.environ = _old_env
def test_failed_auth(self):
m = mox.Mox()
m.StubOutWithMock(ksclient, 'Client')
m.StubOutWithMock(v1client.Client, 'json_request')
fakes.script_keystone_client()
v1client.Client.json_request('GET',
'/stacks?limit=20').AndRaise(exc.Unauthorized)
m.ReplayAll()
_old_env, os.environ = os.environ, {
'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where',
}
self.shell_error('list', 'Invalid OpenStack Identity credentials.')
m.VerifyAll()
os.environ = _old_env
m.UnsetStubs()
def test_create_validation(self):
m = mox.Mox()
m.StubOutWithMock(ksclient, 'Client')
m.StubOutWithMock(v1client.Client, 'json_request')
fakes.script_keystone_client()
m.ReplayAll()
_old_env, os.environ = os.environ, {
'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where',
}
self.shell_error('create teststack '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17"',
'Need to specify exactly one of')
m.VerifyAll()
os.environ = _old_env
m.UnsetStubs()
def shell_error(self, argstr, error_match):
orig = sys.stderr
try:
@@ -122,7 +36,7 @@ class ShellValidationTest(unittest.TestCase):
return err
class ShellTest(unittest.TestCase):
class ShellTest(unittest2.TestCase):
# Patch os.environ to avoid required auth info.
def setUp(self):
@@ -171,8 +85,8 @@ class ShellTest(unittest.TestCase):
def test_help(self):
required = [
'^usage: heat',
'(?m)^See "heat help COMMAND" for help on a specific command',
'^usage: ceilometer',
'(?m)^See "ceilometer help COMMAND" for help on a specific command',
]
for argstr in ['--help', 'help']:
help_text = self.shell(argstr)
@@ -181,210 +95,13 @@ class ShellTest(unittest.TestCase):
def test_help_on_subcommand(self):
required = [
'^usage: heat list',
"(?m)^List the user's stacks",
'^usage: ceilometer meter-list',
"(?m)^List the user's meter",
]
argstrings = [
'help list',
'help meter-list',
]
for argstr in argstrings:
help_text = self.shell(argstr)
for r in required:
self.assertRegexpMatches(help_text, r)
def test_list(self):
fakes.script_keystone_client()
fakes.script_heat_list()
self.m.ReplayAll()
list_text = self.shell('list')
required = [
'ID',
'Status',
'Created',
'teststack/1',
'CREATE_COMPLETE',
'IN_PROGRESS',
]
for r in required:
self.assertRegexpMatches(list_text, r)
self.m.VerifyAll()
def test_describe(self):
fakes.script_keystone_client()
resp_dict = {"stack": {
"id": "1",
"stack_name": "teststack",
"stack_status": 'CREATE_COMPLETE',
"creation_time": "2012-10-25T01:58:47Z"
}
}
resp = fakes.FakeHTTPResponse(200,
'OK',
{'content-type': 'application/json'},
json.dumps(resp_dict))
v1client.Client.json_request('GET',
'/stacks/teststack/1').AndReturn((resp, resp_dict))
self.m.ReplayAll()
list_text = self.shell('describe teststack/1')
required = [
'id',
'stack_name',
'stack_status',
'creation_time',
'teststack',
'CREATE_COMPLETE',
'2012-10-25T01:58:47Z'
]
for r in required:
self.assertRegexpMatches(list_text, r)
self.m.VerifyAll()
def test_create(self):
fakes.script_keystone_client()
resp = fakes.FakeHTTPResponse(201,
'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
v1client.Client.json_request('POST', '/stacks',
body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
create_text = self.shell('create teststack '
'--template-file=%s '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17"' % template_file)
required = [
'Name/ID',
'teststack/1'
]
for r in required:
self.assertRegexpMatches(create_text, r)
self.m.VerifyAll()
def test_create_url(self):
fakes.script_keystone_client()
resp = fakes.FakeHTTPResponse(201,
'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
v1client.Client.json_request('POST', '/stacks',
body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
create_text = self.shell('create teststack '
'--template-url=http://no.where/minimal.template '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17"')
required = [
'Name/ID',
'teststack2/2'
]
for r in required:
self.assertRegexpMatches(create_text, r)
self.m.VerifyAll()
def test_create_object(self):
fakes.script_keystone_client()
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
template_data = open(template_file).read()
v1client.Client.raw_request('GET',
'http://no.where/container/minimal.template',
).AndReturn(template_data)
resp = fakes.FakeHTTPResponse(201,
'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None)
v1client.Client.json_request('POST', '/stacks',
body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
create_text = self.shell('create teststack2 '
'--template-object=http://no.where/container/minimal.template '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17"')
required = [
'Name/ID',
'teststack2/2'
]
for r in required:
self.assertRegexpMatches(create_text, r)
self.m.VerifyAll()
def test_update(self):
fakes.script_keystone_client()
resp = fakes.FakeHTTPResponse(202,
'Accepted',
{},
'The request is accepted for processing.')
v1client.Client.json_request('PUT', '/stacks/teststack2/2',
body=mox.IgnoreArg()).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
create_text = self.shell('update teststack2/2 '
'--template-file=%s '
'--parameters="InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17"' % template_file)
required = [
'Name/ID',
'teststack/1'
]
for r in required:
self.assertRegexpMatches(create_text, r)
self.m.VerifyAll()
def test_delete(self):
fakes.script_keystone_client()
resp = fakes.FakeHTTPResponse(204,
'No Content',
{},
None)
v1client.Client.raw_request('DELETE', '/stacks/teststack2/2',
).AndReturn((resp, None))
fakes.script_heat_list()
self.m.ReplayAll()
create_text = self.shell('delete teststack2/2')
required = [
'Name/ID',
'teststack/1'
]
for r in required:
self.assertRegexpMatches(create_text, r)
self.m.VerifyAll()

View File

View File

@@ -1,31 +0,0 @@
# Copyright 2012 OpenStack LLC.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
import ceilometerclient.v1.shell as shell
class shellTest(unittest.TestCase):
def test_format_parameters(self):
p = shell.format_parameters('InstanceType=m1.large;DBUsername=wp;'
'DBPassword=verybadpassword;KeyName=heat_key;'
'LinuxDistribution=F17')
self.assertEqual({'InstanceType': 'm1.large',
'DBUsername': 'wp',
'DBPassword': 'verybadpassword',
'KeyName': 'heat_key',
'LinuxDistribution': 'F17'
}, p)
self.assertEqual({}, shell.format_parameters(None))

View File

@@ -9,3 +9,4 @@ nosehtmloutput
pep8==1.2
setuptools-git>=0.4
sphinx>=1.1.2
unittest2