diff --git a/.testr.conf b/.testr.conf index 6d83b3c..2476587 100644 --- a/.testr.conf +++ b/.testr.conf @@ -2,6 +2,6 @@ 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 -t ./ . $LISTOPT $IDOPTION + ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./gnocchiclient/tests/unit} $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/gnocchiclient/tests/base.py b/gnocchiclient/tests/base.py deleted file mode 100644 index 1c30cdb..0000000 --- a/gnocchiclient/tests/base.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2010-2011 OpenStack Foundation -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# 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. - -from oslotest import base - - -class TestCase(base.BaseTestCase): - - """Test case base class for all unit tests.""" diff --git a/gnocchiclient/tests/functional/__init__.py b/gnocchiclient/tests/functional/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gnocchiclient/tests/functional/base.py b/gnocchiclient/tests/functional/base.py new file mode 100644 index 0000000..233e258 --- /dev/null +++ b/gnocchiclient/tests/functional/base.py @@ -0,0 +1,35 @@ +# 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 os + +from tempest_lib.cli import base + + +class ClientTestBase(base.ClientTestBase): + """Base class for gnocchiclient tests. + + Establishes the gnocchi client and retrieves the essential environment + information. + """ + + def _get_clients(self): + cli_dir = os.environ.get('OS_GNOCCHI_CLIENT_EXEC_DIR') + return base.CLIClient( + username=os.environ.get('OS_USERNAME'), + password=os.environ.get('OS_PASSWORD'), + tenant_name=os.environ.get('OS_TENANT_NAME'), + uri=os.environ.get('OS_AUTH_URL'), + cli_dir=cli_dir) + + def gnocchi(self, *args, **kwargs): + return self.clients.cmd_with_auth('gnocchi', *args, **kwargs) diff --git a/gnocchiclient/tests/functional/test_resource.py b/gnocchiclient/tests/functional/test_resource.py new file mode 100644 index 0000000..6d1097b --- /dev/null +++ b/gnocchiclient/tests/functional/test_resource.py @@ -0,0 +1,105 @@ +# 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 uuid + +from tempest_lib import exceptions + +from gnocchiclient.tests.functional import base + + +class ResourceClientTest(base.ClientTestBase): + RESOURCE_ID = str(uuid.uuid4()) + PROJECT_ID = str(uuid.uuid4()) + + def details_multiple(self, output_lines, with_label=False): + """Return list of dicts with item details from cli output tables. + If with_label is True, key '__label' is added to each items dict. + For more about 'label' see OutputParser.tables(). + + NOTE(sileht): come from tempest-lib just because cliff use + Field instead of Property as first columun header. + """ + items = [] + tables_ = self.parser.tables(output_lines) + for table_ in tables_: + if ('Field' not in table_['headers'] + or 'Value' not in table_['headers']): + raise exceptions.InvalidStructure() + item = {} + for value in table_['values']: + item[value[0]] = value[1] + if with_label: + item['__label'] = table_['label'] + items.append(item) + return items + + def test_resource_scenario(self): + # CREATE + result = self.gnocchi( + 'resource', params="create generic -a id:%s" % self.RESOURCE_ID) + resource = self.details_multiple(result)[0] + self.assertEqual(self.RESOURCE_ID, resource["id"]) + self.assertEqual('None', resource["project_id"]) + self.assertNotEqual('None', resource["started_at"]) + + # UPDATE + result = self.gnocchi( + 'resource', params=("update generic %s -a project_id:%s" % + (self.RESOURCE_ID, self.PROJECT_ID))) + resource_updated = self.details_multiple(result)[0] + self.assertEqual(self.RESOURCE_ID, resource_updated["id"]) + self.assertEqual(self.PROJECT_ID, resource_updated["project_id"]) + self.assertEqual(resource["started_at"], + resource_updated["started_at"]) + + # GET + result = self.gnocchi( + 'resource', params="show generic %s" % self.RESOURCE_ID) + resource_got = self.details_multiple(result)[0] + self.assertEqual(self.RESOURCE_ID, resource_got["id"]) + self.assertEqual(self.PROJECT_ID, resource_got["project_id"]) + self.assertEqual(resource["started_at"], resource_got["started_at"]) + + # LIST + result = self.gnocchi('resource', params="list generic") + self.assertIn(self.RESOURCE_ID, + [r['id'] for r in self.parser.listing(result)]) + resource_list = [r for r in self.parser.listing(result) + if r['id'] == self.RESOURCE_ID][0] + self.assertEqual(self.RESOURCE_ID, resource_list["id"]) + self.assertEqual(self.PROJECT_ID, resource_list["project_id"]) + self.assertEqual(resource["started_at"], resource_list["started_at"]) + + # DELETE + result = self.gnocchi('resource', + params="delete %s" % self.RESOURCE_ID) + self.assertEqual("", result) + + # GET FAIL + result = self.gnocchi('resource', + params="show generic %s" % self.RESOURCE_ID, + fail_ok=True, merge_stderr=True) + self.assertFirstLineStartsWith(result.split('\n'), + "Not Found (HTTP 404)") + + # DELETE FAIL + result = self.gnocchi('resource', + params="delete %s" % self.RESOURCE_ID, + fail_ok=True, merge_stderr=True) + self.assertFirstLineStartsWith(result.split('\n'), + "Not Found (HTTP 404)") + + # LIST EMPTY + result = self.gnocchi('resource', params="list generic") + self.assertNotIn(self.RESOURCE_ID, + [r['id'] for r in self.parser.listing(result)]) diff --git a/gnocchiclient/tests/test_gnocchiclient.py b/gnocchiclient/tests/test_gnocchiclient.py deleted file mode 100644 index 9344353..0000000 --- a/gnocchiclient/tests/test_gnocchiclient.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- - -# 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. - -""" -test_gnocchiclient ----------------------------------- - -Tests for `gnocchiclient` module. -""" - -from gnocchiclient.tests import base - - -class TestGnocchiclient(base.TestCase): - - def test_something(self): - pass diff --git a/gnocchiclient/tests/unit/__init__.py b/gnocchiclient/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test-requirements.txt b/test-requirements.txt index 0c885d3..485d2ec 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,6 +10,7 @@ python-subunit>=0.0.18 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 oslosphinx>=2.5.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 +tempest-lib>=0.6.1 testrepository>=0.0.18 testscenarios>=0.4 testtools>=1.4.0 diff --git a/tox.ini b/tox.ini index 54fdd6a..97a364f 100644 --- a/tox.ini +++ b/tox.ini @@ -26,6 +26,18 @@ commands = python setup.py build_sphinx [testenv:debug] commands = oslo_debug_helper {posargs} +[testenv:py27-functional] +setenv = + OS_TEST_PATH=./gnocchiclient/tests/functional + OS_GNOCCHI_CLIENT_EXEC_DIR={envdir}/bin +passenv = OS_* + +[testenv:py34-functional] +setenv = + OS_TEST_PATH=./gnocchiclient/tests/functional + OS_GNOCCHI_CLIENT_EXEC_DIR={envdir}/bin +passenv = OS_* + [flake8] # E123, E125 skipped as they are invalid PEP-8.