Browse Source
This adds in the unit_test framework but there is a name collision between charm.openstack as a module, and charm.openstack here which the package loader can't resolve. Therefore, going to change the charm.openstack package to charms.openstack to avoid the collision.changes/57/350257/1
13 changed files with 157 additions and 20 deletions
@ -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 |
@ -0,0 +1,7 @@
|
||||
flake8>=2.2.4,<=2.4.1 |
||||
os-testr>=0.4.1 |
||||
charm-tools>=2.0.0 |
||||
charms.reactive |
||||
mock>=1.2 |
||||
coverage>=3.6 |
||||
https://github.com/ajkavanagh/charm.openstack/zipball/master |
@ -0,0 +1,24 @@
|
||||
import sys |
||||
import mock |
||||
|
||||
|
||||
charmhelpers = mock.MagicMock() |
||||
sys.modules['charmhelpers'] = charmhelpers |
||||
sys.modules['charmhelpers.core'] = charmhelpers.core |
||||
sys.modules['charmhelpers.core.hookenv'] = charmhelpers.core.hookenv |
||||
sys.modules['charmhelpers.core.host'] = charmhelpers.core.host |
||||
sys.modules['charmhelpers.core.templating'] = charmhelpers.core.templating |
||||
sys.modules['charmhelpers.contrib'] = charmhelpers.contrib |
||||
sys.modules['charmhelpers.contrib.openstack'] = charmhelpers.contrib.openstack |
||||
sys.modules['charmhelpers.contrib.openstack.utils'] = ( |
||||
charmhelpers.contrib.openstack.utils) |
||||
sys.modules['charmhelpers.contrib.openstack.templating'] = ( |
||||
charmhelpers.contrib.openstack.templating) |
||||
sys.modules['charmhelpers.contrib.network'] = charmhelpers.contrib.network |
||||
sys.modules['charmhelpers.contrib.network.ip'] = ( |
||||
charmhelpers.contrib.network.ip) |
||||
sys.modules['charmhelpers.fetch'] = charmhelpers.fetch |
||||
sys.modules['charmhelpers.cli'] = charmhelpers.cli |
||||
sys.modules['charmhelpers.contrib.hahelpers'] = charmhelpers.contrib.hahelpers |
||||
sys.modules['charmhelpers.contrib.hahelpers.cluster'] = ( |
||||
charmhelpers.contrib.hahelpers.cluster) |
@ -0,0 +1,63 @@
|
||||
from __future__ import absolute_import |
||||
from __future__ import print_function |
||||
|
||||
import sys |
||||
import unittest |
||||
|
||||
import mock |
||||
|
||||
sys.path.append('src') |
||||
sys.path.append('src/lib') |
||||
import reactive.barbican_handlers as handlers |
||||
|
||||
|
||||
_hook_args = {} |
||||
|
||||
|
||||
def mock_hook(*args, **kwargs): |
||||
|
||||
def inner(f): |
||||
# remember what we were passed. Note that we can't actually determine |
||||
# the class we're attached to, as the decorator only gets the function. |
||||
_hook_args[f.__name__] = dict(args=args, kwargs=kwargs) |
||||
return f |
||||
return inner |
||||
|
||||
|
||||
class TestBarbicanHandlers(unittest.TestCase): |
||||
|
||||
@classmethod |
||||
def setUpClass(cls): |
||||
cls._patched_hook = mock.patch('charms.reactive.hook', mock_hook) |
||||
cls._patched_hook_started = cls._patched_hook.start() |
||||
# force requires to rerun the mock_hook decorator: |
||||
reload(requires) |
||||
|
||||
@classmethod |
||||
def tearDownClass(cls): |
||||
cls._patched_hook.stop() |
||||
cls._patched_hook_started = None |
||||
cls._patched_hook = None |
||||
# and fix any breakage we did to the module |
||||
reload(requires) |
||||
|
||||
def patch(self, attr, return_value=None): |
||||
mocked = mock.patch.object(self.kr, attr) |
||||
self._patches[attr] = mocked |
||||
started = mocked.start() |
||||
started.return_value = return_value |
||||
self._patches_start[attr] = started |
||||
setattr(self, attr, started) |
||||
|
||||
def test_registered_hooks(self): |
||||
# 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. |
||||
hook_patterns = { |
||||
'joined': ('{requires:keystone}-relation-joined', ), |
||||
'changed': ('{requires:keystone}-relation-changed', ), |
||||
'departed': ('{requires:keystone}-relation-{broken,departed}', ), |
||||
} |
||||
print(_hook_args) |
||||
# for k, v in _hook_args.items(): |
||||
# self.assertEqual(hook_patterns[k], v['args']) |
Loading…
Reference in new issue