Added unit test for Versions resource

Change-Id: I5244e7da7f417819a8fab6f8b14145c4b38056ca
This commit is contained in:
Roland Hochmuth 2015-07-22 21:20:12 -06:00
parent 5f6227ce77
commit d4db585928
3 changed files with 72 additions and 4 deletions

View File

@ -2,7 +2,7 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover monasca $LISTOPT $IDOPTION
${PYTHON:-python} -m subunit.run discover monasca_api $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -0,0 +1,68 @@
# Copyright 2015 Hewlett-Packard
#
# 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 datetime
import falcon
import falcon.testing as testing
import json
from monasca_api.v2.reference import versions
class TestVersions(testing.TestBase):
def before(self):
self.versions_resource = versions.Versions()
self.api.add_route('/versions', self.versions_resource)
self.api.add_route('/versions/{version_id}', self.versions_resource)
def test_list_versions(self):
result = self.simulate_request('/versions')
self.assertEqual(self.srmock.status, falcon.HTTP_200)
response = json.loads(result[0])
self.assertTrue(isinstance(response, dict))
self.assertTrue(set(['links', 'elements']) ==
set(response))
links = response['links']
self.assertTrue(isinstance(links, list))
link = links[0]
self.assertTrue(set(['rel', 'href']) ==
set(link))
self.assertEqual(link['rel'], u'self')
self.assertTrue(link['href'].endswith('versions'))
def test_valid_version_id(self):
result = self.simulate_request('/versions/v2.0')
self.assertEqual(self.srmock.status, falcon.HTTP_200)
response = json.loads(result[0])
self.assertTrue(isinstance(response, dict))
version = response
self.assertTrue(set(['id', 'links', 'status', 'updated']) ==
set(version))
self.assertEqual(version['id'], u'v2.0')
self.assertEqual(version['status'], u'CURRENT')
date_object = datetime.datetime.strptime(version['updated'],
"%Y-%m-%dT%H:%M:%SZ")
self.assertTrue(isinstance(date_object, datetime.datetime))
links = response['links']
self.assertTrue(isinstance(links, list))
link = links[0]
self.assertTrue(set(['rel', 'href']) ==
set(link))
self.assertEqual(link['rel'], u'self')
self.assertTrue(link['href'].endswith('/versions/v2.0'))
def test_invalid_version_id(self):
self.simulate_request('/versions/v1.0')
self.assertEqual(self.srmock.status, falcon.HTTP_400)

View File

@ -30,7 +30,6 @@ commands = python setup.py build_sphinx
commands = {posargs}
[flake8]
max-line-length = 120
# TODO: ignored checks should be enabled in the future
# H201 no 'except:' at least use 'except Exception:'
# H302 import only modules
@ -39,9 +38,10 @@ max-line-length = 120
# H405 multi line docstring summary not separated with an empty line
# H904 Wrap long lines in parentheses instead of a backslash
ignore = F821,H201,H302,H305,H307,H405,H904
max-complexity = 50
max-line-length = 120
builtins = _
exclude=.venv,.git,.tox,dist,doc,./monasca_api/openstack/common,*lib/python*,*egg,tools,build
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build
show-source = True
[hacking]