[merge][trivial] Tidy flake8 lint

This commit is contained in:
James Page 2013-11-08 13:31:34 +08:00
commit dc02e63d39
6 changed files with 54 additions and 90 deletions

View File

@ -1,12 +1,18 @@
#!/usr/bin/make
lint:
@echo -n "Running flake8 tests: "
@flake8 --exclude hooks/charmhelpers hooks
@flake8 unit_tests
@echo "OK"
@echo -n "Running charm proof: "
@charm proof
@echo "OK"
sync:
@charm-helper-sync -c charm-helpers.yaml
test:
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
all: test lint

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

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