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
(cherry pick from commit 19bca99ccf)
Closes-Bug: #1608412
This commit is contained in:
Shu Muto 2016-09-12 15:51:42 +09:00 committed by Tony Breeds
parent 6ed5bfc0eb
commit 738683ab03
10 changed files with 162 additions and 22 deletions

View File

@ -22,3 +22,9 @@ classifier =
[files]
packages =
zaqar_ui
[build_sphinx]
all_files = 1
build-dir = doc/build
source-dir = doc/source

30
tox.ini
View File

@ -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]

View File

View File

View File

View File

@ -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

39
zaqar_ui/test/helpers.py Normal file
View File

@ -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

37
zaqar_ui/test/settings.py Normal file
View File

@ -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))

View File

@ -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)