Tidy lint and duplicated unit tests

This commit is contained in:
James Page 2013-11-08 09:34:39 +08:00
parent d0137c5863
commit bd7332ec0d
5 changed files with 48 additions and 90 deletions

View File

@ -1,8 +1,6 @@
from charmhelpers.core.hookenv import (
is_relation_made,
relation_ids,
related_units,
relation_get,
service_name,
)

View File

@ -15,6 +15,7 @@ TO_PATCH = [
class TestGlanceContexts(CharmTestCase):
def setUp(self):
super(TestGlanceContexts, self).setUp(contexts, TO_PATCH)

View File

@ -32,7 +32,7 @@ TO_PATCH = [
'apt_update',
'restart_on_change',
'service_stop',
#charmhelpers.contrib.openstack.utils
# charmhelpers.contrib.openstack.utils
'configure_installation_source',
'get_os_codename_package',
'openstack_upgrade_available',
@ -55,6 +55,7 @@ TO_PATCH = [
class GlanceRelationTests(CharmTestCase):
def setUp(self):
super(GlanceRelationTests, self).setUp(relations, TO_PATCH)
self.config.side_effect = self.test_config.get
@ -374,93 +375,6 @@ class GlanceRelationTests(CharmTestCase):
'ha_changed: hacluster subordinate is not fully clustered.'
)
@patch.object(relations, 'keystone_joined')
@patch.object(relations, 'CONFIGS')
def test_configure_https_enable_with_identity_service(self, configs, keystone_joined):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['https']
configs.write = MagicMock()
self.relation_ids.return_value = ['identity-service:0']
relations.configure_https()
cmd = ['a2ensite', 'openstack_https_frontend']
self.check_call.assert_called_with(cmd)
keystone_joined.assert_called_with(relation_id='identity-service:0')
@patch.object(relations, 'keystone_joined')
@patch.object(relations, 'CONFIGS')
def test_configure_https_disable_with_keystone_joined(self, configs, keystone_joined):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['']
configs.write = MagicMock()
self.relation_ids.return_value = ['identity-service:0']
relations.configure_https()
cmd = ['a2dissite', 'openstack_https_frontend']
self.check_call.assert_called_with(cmd)
keystone_joined.assert_called_with(relation_id='identity-service:0')
@patch.object(relations, 'image_service_joined')
@patch.object(relations, 'CONFIGS')
def test_configure_https_enable_with_image_service(self, configs, image_service_joined):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['https']
configs.write = MagicMock()
self.relation_ids.return_value = ['image-service:0']
relations.configure_https()
cmd = ['a2ensite', 'openstack_https_frontend']
self.check_call.assert_called_with(cmd)
image_service_joined.assert_called_with(relation_id='image-service:0')
@patch.object(relations, 'image_service_joined')
@patch.object(relations, 'CONFIGS')
def test_configure_https_disable_with_image_service(self, configs, image_service_joined):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['']
configs.write = MagicMock()
self.relation_ids.return_value = ['image-service:0']
relations.configure_https()
cmd = ['a2dissite', 'openstack_https_frontend']
self.check_call.assert_called_with(cmd)
image_service_joined.assert_called_with(relation_id='image-service:0')
def test_amqp_joined(self):
relations.amqp_joined()
self.relation_set.assert_called_with(username='glance', vhost='openstack')
@patch.object(relations, 'CONFIGS')
def test_amqp_changed_missing_relation_data(self, configs):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = []
relations.amqp_changed()
self.juju_log.assert_called()
@patch.object(relations, 'CONFIGS')
def test_amqp_changed_relation_data(self, configs):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['amqp']
configs.write = MagicMock()
relations.amqp_changed()
self.assertEquals([call('/etc/glance/glance-api.conf')],
configs.write.call_args_list)
self.assertFalse(self.juju_log.called)
@patch.object(relations, 'keystone_joined')
def test_ha_relation_changed_not_leader(self, joined):
self.relation_get.return_value = True
self.eligible_leader.return_value = False
relations.ha_relation_changed()
self.assertTrue(self.juju_log.called)
self.assertFalse(joined.called)
@patch.object(relations, 'image_service_joined')
@patch.object(relations, 'keystone_joined')
def test_ha_relation_changed_leader(self, ks_joined, image_joined):
self.relation_get.return_value = True
self.eligible_leader.return_value = True
self.relation_ids.side_effect = [['identity:0'], ['image:1']]
relations.ha_relation_changed()
ks_joined.assert_called_with('identity:0')
image_joined.assert_called_with('image:1')
@patch.object(relations, 'keystone_joined')
@patch.object(relations, 'CONFIGS')
def test_configure_https_enable_with_identity_service(
@ -513,6 +427,47 @@ class GlanceRelationTests(CharmTestCase):
self.check_call.assert_called_with(cmd)
image_service_joined.assert_called_with(relation_id='image-service:0')
def test_amqp_joined(self):
relations.amqp_joined()
self.relation_set.assert_called_with(
username='glance',
vhost='openstack')
@patch.object(relations, 'CONFIGS')
def test_amqp_changed_missing_relation_data(self, configs):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = []
relations.amqp_changed()
self.juju_log.assert_called()
@patch.object(relations, 'CONFIGS')
def test_amqp_changed_relation_data(self, configs):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['amqp']
configs.write = MagicMock()
relations.amqp_changed()
self.assertEquals([call('/etc/glance/glance-api.conf')],
configs.write.call_args_list)
self.assertFalse(self.juju_log.called)
@patch.object(relations, 'keystone_joined')
def test_ha_relation_changed_not_leader(self, joined):
self.relation_get.return_value = True
self.eligible_leader.return_value = False
relations.ha_relation_changed()
self.assertTrue(self.juju_log.called)
self.assertFalse(joined.called)
@patch.object(relations, 'image_service_joined')
@patch.object(relations, 'keystone_joined')
def test_ha_relation_changed_leader(self, ks_joined, image_joined):
self.relation_get.return_value = True
self.eligible_leader.return_value = True
self.relation_ids.side_effect = [['identity:0'], ['image:1']]
relations.ha_relation_changed()
ks_joined.assert_called_with('identity:0')
image_joined.assert_called_with('image:1')
@patch.object(relations, 'CONFIGS')
def test_relation_broken(self, configs):
relations.relation_broken()

View File

@ -26,6 +26,7 @@ TO_PATCH = [
class TestGlanceUtils(CharmTestCase):
def setUp(self):
super(TestGlanceUtils, self).setUp(utils, TO_PATCH)
self.config.side_effect = self.test_config.get_all

View File

@ -45,6 +45,7 @@ def get_default_config():
class CharmTestCase(unittest.TestCase):
def setUp(self, obj, patches):
super(CharmTestCase, self).setUp()
self.patches = patches
@ -65,6 +66,7 @@ class CharmTestCase(unittest.TestCase):
class TestConfig(object):
def __init__(self):
self.config = get_default_config()
@ -86,6 +88,7 @@ class TestConfig(object):
class TestRelation(object):
def __init__(self, relation_data={}):
self.relation_data = relation_data