cleaning up unit tests, some syntax

This commit is contained in:
Michael Skalka 2018-11-13 16:30:03 -05:00
parent e44c4dad87
commit a29d9cd21a
6 changed files with 92 additions and 41 deletions

8
.testr.conf Normal file
View File

@ -0,0 +1,8 @@
[DEFAULT]
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 ./ ./unit_tests $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -49,18 +49,18 @@ class PureStorageSubordinateContext(OSContextGenerator):
'iscsi': 'cinder.volume.drivers.pure.PureISCSIDriver',
'fc': 'cinder.volume.drivers.pure.PureFCIDriver',
}
service = charm_config['volume-backend-name'] or service_name()
service = config('volume-backend-name') or service_name()
ctxt.append(('volume_backend_name', service))
ctxt.append(('san_ip', config('san-ip')))
ctxt.append(('pure_api_token', config('pure-api-token')))
try:
ctxt.append(
('volume_driver', drivers[config('protocol').lower()]]))
('volume_driver', drivers[config('protocol').lower()]))
except KeyError:
raise ProtocolNotImplimented(config('protocol'),' is not an '
'implimented protocol driver, please choose between '
'`iscsi` and `fc`.')
raise ProtocolNotImplimented(
config('protocol'), ' is not an implimented protocol driver, '
'please choose between `iscsi` and `fc`.')
for rid in relation_ids(self.interfaces[0]):
log('Setting relation data for {}'.format(rid))

7
test-requirements.txt Normal file
View File

@ -0,0 +1,7 @@
# Unit test requirements
flake8>=2.2.4,<=2.4.1
os-testr>=0.4.1
charms.reactive
mock>=1.2
coverage>=3.6
git+https://github.com/openstack/charms.openstack#egg=charms.openstack

60
tox.ini Normal file
View File

@ -0,0 +1,60 @@
# Source charm: ./tox.ini
# This file is managed centrally by release-tools and should not be modified
# within individual charm repos.
[tox]
skipsdist = True
envlist = pep8,py34,py35
skip_missing_interpreters = True
[testenv]
setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0
TERM=linux
LAYER_PATH={toxinidir}/layers
INTERFACE_PATH={toxinidir}/interfaces
JUJU_REPOSITORY={toxinidir}/build
passenv = http_proxy https_proxy USER
install_command =
pip install {opts} {packages}
deps =
-r{toxinidir}/requirements.txt
[testenv:build]
basepython = python2.7
commands =
charm-build --log-level DEBUG -o {toxinidir}/build src {posargs}
[testenv:py27]
basepython = python2.7
# Reactive source charms are Python3-only, but a py27 unit test target
# is required by OpenStack Governance. Remove this shim as soon as
# permitted. http://governance.openstack.org/reference/cti/python_cti.html
whitelist_externals = true
commands = true
[testenv:py34]
basepython = python3.4
deps = -r{toxinidir}/test-requirements.txt
commands = ostestr {posargs}
[testenv:py35]
basepython = python3.5
deps = -r{toxinidir}/test-requirements.txt
commands = ostestr {posargs}
[testenv:py36]
basepython = python3.6
deps = -r{toxinidir}/test-requirements.txt
commands = ostestr {posargs}
[testenv:pep8]
basepython = python3.5
deps = -r{toxinidir}/test-requirements.txt
commands = flake8 {posargs} src unit_tests
[testenv:venv]
commands = {posargs}
[flake8]
# E402 ignore necessary for path append before sys module import in actions
ignore = E402

View File

@ -20,7 +20,7 @@ import unittest
import mock
import reactive.designate_bind_handlers as handlers
import reactive.cinder_purestorage_handlers as handlers
_when_args = {}
@ -101,47 +101,23 @@ class TestCinderPureStorageHandlers(unittest.TestCase):
# test that the hooks actually registered the relation expressions that
# are meaningful for this interface: this is to handle regressions.
# The keys are the function names that the hook attaches to.
when_any_patterns = {
'storage_backend': [
('storage-backend.joined', 'storage-backend.changed')],
}
when_patterns = {
'setup_sync_target_alone': [('installed', )],
'send_info': [
('dns-backend.related', ),
('rndckey.available', ),
],
'config_changed': [
('dns-backend.related', ),
('rndckey.available', ),
],
'update_zones_from_peer': [
('cluster.connected', ),
('sync.request.sent', ),
],
'check_zone_status': [
('cluster.connected', ),
('installed', ),
],
'process_sync_requests': [
('cluster.connected', ),
('zones.initialised', ),
],
'assess_status': [('zones.initialised', )],
'update_config': [
('config.changed', )],
}
when_not_patterns = {
'install_packages': [('installed', )],
'setup_secret': [('rndckey.available', )],
'update_zones_from_peer': [('zones.initialised', )],
'setup_sync_target_alone': [
('cluster.connected', ),
('zones.initialised', ),
('sync.request.sent', ),
],
'check_zone_status': [
('zones.initialised', ),
('sync.request.sent', ),
],
'storage_backend': [('storage-backend.available', )],
}
# check the when hooks are attached to the expected functions
for t, p in [(_when_args, when_patterns),
(_when_not_args, when_not_patterns)]:
for t, p in [(_when_args, when_any_patterns),
(_when_not_args, when_not_patterns),
(_when_args, when_patterns),
]:
for f, args in t.items():
# check that function is in patterns
print(f)