From 19bca99ccf6130766c5317eb8891db38d51388eb Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Mon, 12 Sep 2016 15:51:42 +0900 Subject: [PATCH] Setup python test environment This patch adds python test environment and test skeleton. Also need to set sphinx output to make the docs job pass at the same time. Change-Id: Icf5f2a210b7b02e90eb98dc285223ba4f7377a66 Closes-Bug: #1608412 --- setup.cfg | 6 +++ tox.ini | 30 ++++--------- zaqar_ui/enabled/__init__.py | 0 zaqar_ui/test/__init__.py | 0 zaqar_ui/test/api_tests/__init__.py | 0 zaqar_ui/test/api_tests/rest_api_tests.py | 48 +++++++++++++++++++++ zaqar_ui/test/helpers.py | 39 +++++++++++++++++ zaqar_ui/test/integration_tests/__init__.py | 0 zaqar_ui/test/settings.py | 37 ++++++++++++++++ zaqar_ui/test/test_data.py | 24 +++++++++++ 10 files changed, 162 insertions(+), 22 deletions(-) create mode 100644 zaqar_ui/enabled/__init__.py create mode 100644 zaqar_ui/test/__init__.py create mode 100644 zaqar_ui/test/api_tests/__init__.py create mode 100644 zaqar_ui/test/api_tests/rest_api_tests.py create mode 100644 zaqar_ui/test/helpers.py create mode 100644 zaqar_ui/test/integration_tests/__init__.py create mode 100644 zaqar_ui/test/settings.py create mode 100644 zaqar_ui/test/test_data.py diff --git a/setup.cfg b/setup.cfg index d3f2724..c9fe006 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,3 +22,9 @@ classifier = [files] packages = zaqar_ui + +[build_sphinx] +all_files = 1 +build-dir = doc/build +source-dir = doc/source + diff --git a/tox.ini b/tox.ini index 3af6c26..d5aa5ff 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py27dj18,pep834 +envlist = py27,py27dj18,pep8,py34 minversion = 1.6 skipsdist = True @@ -11,42 +11,28 @@ setenv = VIRTUAL_ENV={envdir} NOSE_OPENSTACK_RED=0.05 NOSE_OPENSTACK_YELLOW=0.025 NOSE_OPENSTACK_SHOW_ELAPSED=1 -# Note the hash seed is set to 0 until horizon can be tested with a -# random hash seed successfully. - PYTHONHASHSEED=0 + DJANGO_SETTINGS_MODULE=zaqar_ui.test.settings install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -U {opts} {packages} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt -commands = /bin/bash run_tests.sh -N --no-pep8 {posargs} +commands = python manage.py test {posargs} [testenv:pep8] -commands = - /bin/bash run_tests.sh -N --pep8 - /bin/bash run_tests.sh -N --makemessages --check-only +commands = flake8 {posargs} [testenv:venv] commands = {posargs} [testenv:cover] -commands = /bin/bash run_tests.sh -N --no-pep8 --coverage {posargs} +commands = python setup.py test --coverage --testr-args='{posargs}' [testenv:py27dj18] basepython = python2.7 -commands = pip install django>=1.8,<1.9 - /bin/bash run_tests.sh -N --no-pep8 {posargs} - -[testenv:py27integration] -basepython = python2.7 -commands = /bin/bash run_tests.sh -N --integration --selenium-headless {posargs} - -[testenv:eslint] -passenv = * -commands = nodeenv -p - npm install - /bin/bash run_tests.sh -N --eslint +commands = + pip install django>=1.8,<1.9 + python manage.py test {posargs} [testenv:docs] -setenv = DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings commands = python setup.py build_sphinx [flake8] diff --git a/zaqar_ui/enabled/__init__.py b/zaqar_ui/enabled/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zaqar_ui/test/__init__.py b/zaqar_ui/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zaqar_ui/test/api_tests/__init__.py b/zaqar_ui/test/api_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zaqar_ui/test/api_tests/rest_api_tests.py b/zaqar_ui/test/api_tests/rest_api_tests.py new file mode 100644 index 0000000..d889214 --- /dev/null +++ b/zaqar_ui/test/api_tests/rest_api_tests.py @@ -0,0 +1,48 @@ +# 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 mock + +from openstack_dashboard.test import helpers as test +from openstack_dashboard.test.test_data.utils import TestData +from zaqar_ui.api.rest import zaqar +from zaqar_ui.test import test_data + +TEST = TestData(test_data.data) + + +class ZaqarRestTestCase(test.TestCase): + + # Queues + @mock.patch.object(zaqar, 'zaqar') + def test_queue_get(self, client): + # for check test env + self.assertTrue(1 * 1 == 1) + + @mock.patch.object(zaqar, 'zaqar') + def test_queue_create(self, client): + # for check test env + self.assertTrue(1 + 1 == 2) + + @mock.patch.object(zaqar, 'zaqar') + def test_queue_delete(self, client): + # for check test env + self.assertTrue(1 - 1 == 0) + + +def mock_resource(resource): + """Utility function to make mocking more DRY""" + + mocked_data = \ + [mock.Mock(**{'to_dict.return_value': item}) for item in resource] + + return mocked_data diff --git a/zaqar_ui/test/helpers.py b/zaqar_ui/test/helpers.py new file mode 100644 index 0000000..64ce781 --- /dev/null +++ b/zaqar_ui/test/helpers.py @@ -0,0 +1,39 @@ +# 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 openstack_dashboard.test import helpers +from zaqar_ui import api +from zaqar_ui.test import test_data +from zaqarclient.queues.v2 import client as zaqar_client + + +class APITestCase(helpers.APITestCase): + """Extends the base Horizon APITestCase for zaqarclient""" + + def setUp(self): + super(APITestCase, self).setUp() + self._original_magnumclient = api.zaqar.zaqarclient + api.zaqar.zaqarclient = lambda request: self.stub_zaqarclient() + + def _setup_test_data(self): + super(APITestCase, self)._setup_test_data() + test_data.data(self) + + def tearDown(self): + super(APITestCase, self).tearDown() + api.zaqar.zaqarclient = self._original_zaqarclient + + def stub_zaqarclient(self): + if not hasattr(self, "zaqarclient"): + self.mox.StubOutWithMock(zaqar_client, 'Client') + self.zaqarclient = self.mox.CreateMock(zaqar_client.Client) + return self.zaqarclient diff --git a/zaqar_ui/test/integration_tests/__init__.py b/zaqar_ui/test/integration_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zaqar_ui/test/settings.py b/zaqar_ui/test/settings.py new file mode 100644 index 0000000..b33d753 --- /dev/null +++ b/zaqar_ui/test/settings.py @@ -0,0 +1,37 @@ +# 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. + +# Default to Horizons test settings to avoid any missing keys +from horizon.test.settings import * # noqa +from openstack_dashboard.test.settings import * # noqa + +# pop these keys to avoid log warnings about deprecation +# update_dashboards will populate them anyway +HORIZON_CONFIG.pop('dashboards', None) +HORIZON_CONFIG.pop('default_dashboard', None) + +# Update the dashboards with zaqar_ui +import openstack_dashboard.enabled +from openstack_dashboard.utils import settings +import zaqar_ui.enabled + +settings.update_dashboards( + [ + zaqar_ui.enabled, + openstack_dashboard.enabled, + ], + HORIZON_CONFIG, + INSTALLED_APPS +) + +# Ensure any duplicate apps are removed after the update_dashboards call +INSTALLED_APPS = list(set(INSTALLED_APPS)) diff --git a/zaqar_ui/test/test_data.py b/zaqar_ui/test/test_data.py new file mode 100644 index 0000000..87d3343 --- /dev/null +++ b/zaqar_ui/test/test_data.py @@ -0,0 +1,24 @@ +# 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 openstack_dashboard.test.test_data import utils + + +def data(TEST): + # Test Data Container in Horizon + TEST.queues = utils.TestDataContainer() + + # Queues + queue_dict_1 = {"uuid": 1, + "name": "test1"} + + TEST.queues.add(queue_dict_1)