more tests, more coverage
This commit is contained in:
parent
d8ab9cf359
commit
8547c93f3f
1
.bzrignore
Normal file
1
.bzrignore
Normal file
@ -0,0 +1 @@
|
||||
.coverage
|
@ -42,10 +42,14 @@ class NeutronCCContext(context.NeutronContext):
|
||||
ctxt['verbose'] = config('verbose')
|
||||
ctxt['debug'] = config('debug')
|
||||
for rid in relation_ids('neutron-api'):
|
||||
print "rid"
|
||||
for unit in related_units(rid):
|
||||
print "unit"
|
||||
ctxt['nova_url'] = relation_get(attribute='nova_url',
|
||||
rid=rid,
|
||||
unit=unit)
|
||||
if ctxt['nova_url']:
|
||||
print "Ive set nova_url"
|
||||
return ctxt
|
||||
print "Ive not set nova_url"
|
||||
return ctxt
|
||||
|
@ -1,7 +1,7 @@
|
||||
from test_utils import CharmTestCase
|
||||
from mock import patch
|
||||
import neutron_api_context as context
|
||||
|
||||
import charmhelpers
|
||||
TO_PATCH = [
|
||||
'relation_get',
|
||||
'relation_ids',
|
||||
@ -10,6 +10,42 @@ TO_PATCH = [
|
||||
]
|
||||
|
||||
|
||||
class IdentityServiceContext(CharmTestCase):
|
||||
def setUp(self):
|
||||
super(IdentityServiceContext, self).setUp(context, TO_PATCH)
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.test_config.set('region', 'region457')
|
||||
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'context_complete')
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get')
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'related_units')
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'log')
|
||||
def test_ids_ctxt(self, _log, _rids, _runits, _rget, _ctxt_comp):
|
||||
_rids.return_value = 'rid1'
|
||||
_runits.return_value = 'runit'
|
||||
_ctxt_comp.return_value = True
|
||||
id_data = {
|
||||
'service_port': 9876,
|
||||
'service_host': '127.0.0.4',
|
||||
'auth_host': '127.0.0.5',
|
||||
'auth_port': 5432,
|
||||
'service_tenant': 'ten',
|
||||
'service_username': 'admin',
|
||||
'service_password': 'adminpass',
|
||||
}
|
||||
_rget.return_value = id_data
|
||||
ids_ctxt = context.IdentityServiceContext()
|
||||
self.assertEquals(ids_ctxt()['region'], 'region457')
|
||||
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids')
|
||||
@patch.object(charmhelpers.contrib.openstack.context, 'log')
|
||||
def test_ids_ctxt_no_rels(self, _log, _rids):
|
||||
_rids.return_value = []
|
||||
ids_ctxt = context.IdentityServiceContext()
|
||||
self.assertEquals(ids_ctxt(), None)
|
||||
|
||||
class NeutronAPIContextsTest(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -27,7 +63,7 @@ class NeutronAPIContextsTest(CharmTestCase):
|
||||
|
||||
@patch.object(context.NeutronCCContext, 'network_manager')
|
||||
@patch.object(context.NeutronCCContext, 'plugin')
|
||||
def test_quantum_plugin_context_no_setting(self, plugin, nm):
|
||||
def test_neutroncc_context_no_setting(self, plugin, nm):
|
||||
plugin.return_value = None
|
||||
napi_ctxt = context.NeutronCCContext()
|
||||
ctxt_data = {
|
||||
@ -38,13 +74,24 @@ class NeutronAPIContextsTest(CharmTestCase):
|
||||
with patch.object(napi_ctxt, '_ensure_packages'):
|
||||
self.assertEquals(ctxt_data, napi_ctxt())
|
||||
|
||||
def test_quantum_plugin_context_manager(self):
|
||||
@patch.object(context.NeutronCCContext, 'network_manager')
|
||||
@patch.object(context.NeutronCCContext, 'plugin')
|
||||
def test_neutroncc_context_api_rel(self, plugin, nm):
|
||||
nova_url = 'http://127.0.0.10'
|
||||
plugin.return_value = None
|
||||
self.related_units.return_value = ['unit1']
|
||||
self.relation_ids.return_value = ['rid2']
|
||||
self.test_relation.set({'nova_url': nova_url})
|
||||
napi_ctxt = context.NeutronCCContext()
|
||||
self.assertEquals(nova_url, napi_ctxt()['nova_url'])
|
||||
|
||||
def test_neutroncc_context_manager(self):
|
||||
napi_ctxt = context.NeutronCCContext()
|
||||
self.assertEquals(napi_ctxt.network_manager, 'neutron')
|
||||
self.assertEquals(napi_ctxt.plugin, 'ovs')
|
||||
self.assertEquals(napi_ctxt.neutron_security_groups, True)
|
||||
|
||||
def test_quantum_plugin_context_manager_pkgs(self):
|
||||
def test_neutroncc_context_manager_pkgs(self):
|
||||
napi_ctxt = context.NeutronCCContext()
|
||||
with patch.object(napi_ctxt, '_ensure_packages') as ep:
|
||||
napi_ctxt._ensure_packages()
|
||||
|
@ -95,11 +95,11 @@ class TestRelation(object):
|
||||
def set(self, relation_data):
|
||||
self.relation_data = relation_data
|
||||
|
||||
def get(self, attr=None, unit=None, rid=None):
|
||||
if attr is None:
|
||||
def get(self, attribute=None, unit=None, rid=None):
|
||||
if attribute is None:
|
||||
return self.relation_data
|
||||
elif attr in self.relation_data:
|
||||
return self.relation_data[attr]
|
||||
elif attribute in self.relation_data:
|
||||
return self.relation_data[attribute]
|
||||
return None
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user