From af6a5c763b7773525753d22984f47edcd4eeec26 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 14 Apr 2016 13:48:24 -0400 Subject: [PATCH 1/2] Convert the code to PEP8 --- almanach/adapters/api_route_v1.py | 68 +++++++++---------- almanach/adapters/database_adapter.py | 1 + almanach/adapters/retry_adapter.py | 4 +- almanach/api.py | 1 + almanach/collector.py | 1 + almanach/common/AlmanachException.py | 1 + almanach/common/DateFormatException.py | 2 + .../common/VolumeTypeNotFoundException.py | 2 + almanach/common/__init__.py | 1 - almanach/config.py | 3 + almanach/core/controller.py | 1 + almanach/core/model.py | 4 ++ tests/adapters/test_bus_adapter.py | 1 + tests/adapters/test_database_adapter.py | 49 ++++++++----- tests/adapters/test_retry_adapter.py | 3 +- tests/api_test.py | 40 +++++------ tests/builder.py | 4 ++ tests/core/test_controller.py | 68 +++++++++---------- tests/messages.py | 4 +- 19 files changed, 149 insertions(+), 109 deletions(-) diff --git a/almanach/adapters/api_route_v1.py b/almanach/adapters/api_route_v1.py index ce02f9f..4154d51 100644 --- a/almanach/adapters/api_route_v1.py +++ b/almanach/adapters/api_route_v1.py @@ -81,15 +81,15 @@ def create_instance(project_id): instance = json.loads(request.data) logging.info("Creating instance for tenant %s with data %s", project_id, instance) controller.create_instance( - tenant_id=project_id, - instance_id=instance['id'], - create_date=instance['created_at'], - flavor=instance['flavor'], - os_type=instance['os_type'], - distro=instance['os_distro'], - version=instance['os_version'], - name=instance['name'], - metadata={} + tenant_id=project_id, + instance_id=instance['id'], + create_date=instance['created_at'], + flavor=instance['flavor'], + os_type=instance['os_type'], + distro=instance['os_distro'], + version=instance['os_version'], + name=instance['name'], + metadata={} ) return Response(status=201) @@ -102,8 +102,8 @@ def delete_instance(instance_id): data = json.loads(request.data) logging.info("Deleting instance with id %s with data %s", instance_id, data) controller.delete_instance( - instance_id=instance_id, - delete_date=data['date'] + instance_id=instance_id, + delete_date=data['date'] ) return Response(status=202) @@ -116,9 +116,9 @@ def resize_instance(instance_id): instance = json.loads(request.data) logging.info("Resizing instance with id %s with data %s", instance_id, instance) controller.resize_instance( - instance_id=instance_id, - resize_date=instance['date'], - flavor=instance['flavor'] + instance_id=instance_id, + resize_date=instance['date'], + flavor=instance['flavor'] ) return Response(status=200) @@ -157,13 +157,13 @@ def create_volume(project_id): volume = json.loads(request.data) logging.info("Creating volume for tenant %s with data %s", project_id, volume) controller.create_volume( - project_id=project_id, - volume_id=volume['volume_id'], - start=volume['start'], - volume_type=volume['volume_type'], - size=volume['size'], - volume_name=volume['volume_name'], - attached_to=volume['attached_to'] + project_id=project_id, + volume_id=volume['volume_id'], + start=volume['start'], + volume_type=volume['volume_type'], + size=volume['size'], + volume_name=volume['volume_name'], + attached_to=volume['attached_to'] ) return Response(status=201) @@ -176,8 +176,8 @@ def delete_volume(volume_id): data = json.loads(request.data) logging.info("Deleting volume with id %s with data %s", volume_id, data) controller.delete_volume( - volume_id=volume_id, - delete_date=data['date'] + volume_id=volume_id, + delete_date=data['date'] ) return Response(status=202) @@ -190,9 +190,9 @@ def resize_volume(volume_id): volume = json.loads(request.data) logging.info("Resizing volume with id %s with data %s", volume_id, volume) controller.resize_volume( - volume_id=volume_id, - size=volume['size'], - update_date=volume['date'] + volume_id=volume_id, + size=volume['size'], + update_date=volume['date'] ) return Response(status=200) @@ -205,9 +205,9 @@ def attach_volume(volume_id): volume = json.loads(request.data) logging.info("Attaching volume with id %s with data %s", volume_id, volume) controller.attach_volume( - volume_id=volume_id, - date=volume['date'], - attachments=volume['attachments'] + volume_id=volume_id, + date=volume['date'], + attachments=volume['attachments'] ) return Response(status=200) @@ -220,9 +220,9 @@ def detach_volume(volume_id): volume = json.loads(request.data) logging.info("Detaching volume with id %s with data %s", volume_id, volume) controller.detach_volume( - volume_id=volume_id, - date=volume['date'], - attachments=volume['attachments'] + volume_id=volume_id, + date=volume['date'], + attachments=volume['attachments'] ) return Response(status=200) @@ -278,8 +278,8 @@ def create_volume_type(): volume_type = json.loads(request.data) logging.info("Creating volume type with data '%s'", volume_type) controller.create_volume_type( - volume_type_id=volume_type['type_id'], - volume_type_name=volume_type['type_name'] + volume_type_id=volume_type['type_id'], + volume_type_name=volume_type['type_name'] ) return Response(status=201) diff --git a/almanach/adapters/database_adapter.py b/almanach/adapters/database_adapter.py index 8d7a049..5010e22 100644 --- a/almanach/adapters/database_adapter.py +++ b/almanach/adapters/database_adapter.py @@ -55,6 +55,7 @@ def ensureindex(db): class DatabaseAdapter(object): + def __init__(self): self.db = None diff --git a/almanach/adapters/retry_adapter.py b/almanach/adapters/retry_adapter.py index f8468b9..e57e5aa 100644 --- a/almanach/adapters/retry_adapter.py +++ b/almanach/adapters/retry_adapter.py @@ -20,6 +20,7 @@ from almanach import config class RetryAdapter: + def __init__(self, connection): self.connection = connection retry_exchange = self._configure_retry_exchanges(self.connection) @@ -87,7 +88,8 @@ class RetryAdapter: return dead_exchange def error_callback(exception, interval): - logging.error('Failed to declare dead queue and exchange, retrying in %d seconds. %r' % (interval, exception)) + logging.error('Failed to declare dead queue and exchange, retrying in %d seconds. %r' % + (interval, exception)) declare_dead_queue = connection.ensure(connection, declare_dead_queue, errback=error_callback, interval_start=0, interval_step=5, interval_max=30) diff --git a/almanach/api.py b/almanach/api.py index 24d1e81..7710db5 100644 --- a/almanach/api.py +++ b/almanach/api.py @@ -25,6 +25,7 @@ from almanach.core.controller import Controller class AlmanachApi(Application): + def __init__(self): super(AlmanachApi, self).__init__() diff --git a/almanach/collector.py b/almanach/collector.py index 504500b..0cea44f 100644 --- a/almanach/collector.py +++ b/almanach/collector.py @@ -26,6 +26,7 @@ from almanach.core.controller import Controller class AlmanachCollector(object): + def __init__(self): log_bootstrap.configure() config.read(sys.argv) diff --git a/almanach/common/AlmanachException.py b/almanach/common/AlmanachException.py index 7079c69..ac3ec3d 100644 --- a/almanach/common/AlmanachException.py +++ b/almanach/common/AlmanachException.py @@ -12,5 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. + class AlmanachException(Exception): pass diff --git a/almanach/common/DateFormatException.py b/almanach/common/DateFormatException.py index d84b83c..9fb4149 100644 --- a/almanach/common/DateFormatException.py +++ b/almanach/common/DateFormatException.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. + class DateFormatException(Exception): + def __init__(self, message=None): if not message: message = "The provided date has an invalid format. Format should be of yyyy-mm-ddThh:mm:ss.msZ, " \ diff --git a/almanach/common/VolumeTypeNotFoundException.py b/almanach/common/VolumeTypeNotFoundException.py index dd326c0..a1f6221 100644 --- a/almanach/common/VolumeTypeNotFoundException.py +++ b/almanach/common/VolumeTypeNotFoundException.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. + class VolumeTypeNotFoundException(Exception): + def __init__(self, volume_type_id, message=None): if not message: message = "Unable to find volume_type id '{volume_type_id}'".format(volume_type_id=volume_type_id) diff --git a/almanach/common/__init__.py b/almanach/common/__init__.py index 8b13789..e69de29 100644 --- a/almanach/common/__init__.py +++ b/almanach/common/__init__.py @@ -1 +0,0 @@ - diff --git a/almanach/config.py b/almanach/config.py index 09f45fa..64bcc32 100644 --- a/almanach/config.py +++ b/almanach/config.py @@ -98,12 +98,15 @@ def rabbitmq_retry_return_exchange(): def rabbitmq_retry_queue(): return get("RABBITMQ", "retry.queue", default=None) + def rabbitmq_dead_queue(): return get("RABBITMQ", "dead.queue", default=None) + def rabbitmq_dead_exchange(): return get("RABBITMQ", "dead.exchange", default=None) + def rabbitmq_time_to_live(): return int(get("RABBITMQ", "retry.time.to.live", default=None)) diff --git a/almanach/core/controller.py b/almanach/core/controller.py index 27c10ca..3119485 100644 --- a/almanach/core/controller.py +++ b/almanach/core/controller.py @@ -25,6 +25,7 @@ from almanach import config class Controller(object): + def __init__(self, database_adapter): self.database_adapter = database_adapter self.metadata_whitelist = config.device_metadata_whitelist() diff --git a/almanach/core/model.py b/almanach/core/model.py index 1ff12a0..80b097b 100644 --- a/almanach/core/model.py +++ b/almanach/core/model.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. + class Entity(object): + def __init__(self, entity_id, project_id, start, end, last_event, name, entity_type): self.entity_id = entity_id self.project_id = project_id @@ -52,6 +54,7 @@ class Instance(Entity): class OS(object): + def __init__(self, os_type, distro, version): self.os_type = os_type self.distro = distro @@ -80,6 +83,7 @@ class Volume(Entity): class VolumeType(object): + def __init__(self, volume_type_id, volume_type_name): self.volume_type_id = volume_type_id self.volume_type_name = volume_type_name diff --git a/tests/adapters/test_bus_adapter.py b/tests/adapters/test_bus_adapter.py index cae95a2..9894493 100644 --- a/tests/adapters/test_bus_adapter.py +++ b/tests/adapters/test_bus_adapter.py @@ -23,6 +23,7 @@ from almanach.adapters.bus_adapter import BusAdapter class BusAdapterTest(unittest.TestCase): + def setUp(self): self.controller = flexmock() self.retry = flexmock() diff --git a/tests/adapters/test_database_adapter.py b/tests/adapters/test_database_adapter.py index 8836640..c507aa8 100644 --- a/tests/adapters/test_database_adapter.py +++ b/tests/adapters/test_database_adapter.py @@ -29,6 +29,7 @@ from tests.builder import a, instance, volume, volume_type class DatabaseAdapterTest(unittest.TestCase): + def setUp(self): config.read(config_file="resources/config/test.cfg") mongo_connection = mongomock.Connection() @@ -103,18 +104,23 @@ class DatabaseAdapterTest(unittest.TestCase): def test_list_instances(self): fake_instances = [ - a(instance().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id").with_metadata({})), - a(instance().with_id("id2").with_start(2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id").with_metadata({})), - a(instance().with_id("id3").with_start(2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id").with_metadata({})), + a(instance().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end( + 2014, 1, 1, 8, 0, 0).with_project_id("project_id").with_metadata({})), + a(instance().with_id("id2").with_start(2014, 1, 1, 1, 0, + 0).with_no_end().with_project_id("project_id").with_metadata({})), + a(instance().with_id("id3").with_start(2014, 1, 1, 8, 0, + 0).with_no_end().with_project_id("project_id").with_metadata({})), ] fake_volumes = [ - a(volume().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id")), + a(volume().with_id("id1").with_start(2014, 1, 1, 7, 0, 0).with_end( + 2014, 1, 1, 8, 0, 0).with_project_id("project_id")), a(volume().with_id("id2").with_start(2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id")), a(volume().with_id("id3").with_start(2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id")), ] [self.db.entity.insert(todict(fake_entity)) for fake_entity in fake_instances + fake_volumes] - entities = self.adapter.list_entities("project_id", datetime(2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance") + entities = self.adapter.list_entities("project_id", datetime( + 2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance") assert_that(entities, contains_inanyorder(*fake_instances)) def test_list_instances_with_decode_output(self): @@ -148,28 +154,37 @@ class DatabaseAdapterTest(unittest.TestCase): .with_no_end() .with_project_id("project_id") .with_metadata({"a_metadata.to_sanitize": "this.sanitize"})), - ] + ] [self.db.entity.insert(todict(fake_entity)) for fake_entity in fake_instances] - entities = self.adapter.list_entities("project_id", datetime(2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance") + entities = self.adapter.list_entities("project_id", datetime( + 2014, 1, 1, 0, 0, 0), datetime(2014, 1, 1, 12, 0, 0), "instance") assert_that(entities, contains_inanyorder(*expected_instances)) self.assert_entities_metadata_have_been_sanitize(entities) def test_list_entities_in_period(self): fake_entities_in_period = [ - a(instance().with_id("in_the_period").with_start(2014, 1, 1, 7, 0, 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id")), - a(instance().with_id("running_has_started_before").with_start(2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id")), - a(instance().with_id("running_has_started_during").with_start(2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id")), + a(instance().with_id("in_the_period").with_start(2014, 1, 1, 7, 0, + 0).with_end(2014, 1, 1, 8, 0, 0).with_project_id("project_id")), + a(instance().with_id("running_has_started_before").with_start( + 2014, 1, 1, 1, 0, 0).with_no_end().with_project_id("project_id")), + a(instance().with_id("running_has_started_during").with_start( + 2014, 1, 1, 8, 0, 0).with_no_end().with_project_id("project_id")), ] fake_entities_out_period = [ - a(instance().with_id("before_the_period").with_start(2014, 1, 1, 0, 0, 0).with_end(2014, 1, 1, 1, 0, 0).with_project_id("project_id")), - a(instance().with_id("after_the_period").with_start(2014, 1, 1, 10, 0, 0).with_end(2014, 1, 1, 11, 0, 0).with_project_id("project_id")), - a(instance().with_id("running_has_started_after").with_start(2014, 1, 1, 10, 0, 0).with_no_end().with_project_id("project_id")), + a(instance().with_id("before_the_period").with_start(2014, 1, 1, 0, + 0, 0).with_end(2014, 1, 1, 1, 0, 0).with_project_id("project_id")), + a(instance().with_id("after_the_period").with_start(2014, 1, 1, 10, + 0, 0).with_end(2014, 1, 1, 11, 0, 0).with_project_id("project_id")), + a(instance().with_id("running_has_started_after").with_start( + 2014, 1, 1, 10, 0, 0).with_no_end().with_project_id("project_id")), ] - [self.db.entity.insert(todict(fake_entity)) for fake_entity in fake_entities_in_period + fake_entities_out_period] + [self.db.entity.insert(todict(fake_entity)) + for fake_entity in fake_entities_in_period + fake_entities_out_period] - entities = self.adapter.list_entities("project_id", datetime(2014, 1, 1, 6, 0, 0), datetime(2014, 1, 1, 9, 0, 0)) + entities = self.adapter.list_entities("project_id", datetime( + 2014, 1, 1, 6, 0, 0), datetime(2014, 1, 1, 9, 0, 0)) assert_that(entities, contains_inanyorder(*fake_entities_in_period)) def test_update_entity(self): @@ -190,7 +205,8 @@ class DatabaseAdapterTest(unittest.TestCase): self.adapter.update_active_entity(fake_entity) - self.assertEqual(self.db.entity.find_one({"entity_id": fake_entity.entity_id})["os"]["distro"], fake_entity.os.distro) + self.assertEqual(self.db.entity.find_one({"entity_id": fake_entity.entity_id})[ + "os"]["distro"], fake_entity.os.distro) def test_insert_volume(self): count = self.db.entity.count() @@ -259,4 +275,3 @@ class DatabaseAdapterTest(unittest.TestCase): for key in entity.metadata: self.assertTrue(key.find("^") == -1, "The metadata key %s contains carret" % (key)) - diff --git a/tests/adapters/test_retry_adapter.py b/tests/adapters/test_retry_adapter.py index 72cef87..8b40621 100644 --- a/tests/adapters/test_retry_adapter.py +++ b/tests/adapters/test_retry_adapter.py @@ -24,6 +24,7 @@ from almanach.adapters.retry_adapter import RetryAdapter class BusAdapterTest(unittest.TestCase): + def setUp(self): self.setup_connection_mock() self.setup_config_mock() @@ -116,4 +117,4 @@ class BusAdapterTest(unittest.TestCase): class MyObject(object): - pass \ No newline at end of file + pass diff --git a/tests/api_test.py b/tests/api_test.py index 109a894..e91979f 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -30,6 +30,7 @@ from tests.builder import a, instance, volume_type class ApiTest(TestCase): + def setUp(self): self.controller = flexmock() api_route.controller = self.controller @@ -83,7 +84,7 @@ class ApiTest(TestCase): .with_args( instance_id="INSTANCE_ID", start_date=data["start_date"], - ).and_return(a(instance().with_id('INSTANCE_ID'))) + ).and_return(a(instance().with_id('INSTANCE_ID'))) code, result = self.api_update( '/entity/instance/INSTANCE_ID', @@ -194,8 +195,8 @@ class ApiTest(TestCase): def test_successful_volume_type_create(self): self.having_config('api_auth_token', 'some token value') data = dict( - type_id='A_VOLUME_TYPE_ID', - type_name="A_VOLUME_TYPE_NAME" + type_id='A_VOLUME_TYPE_ID', + type_name="A_VOLUME_TYPE_NAME" ) self.controller.should_receive('create_volume_type') \ @@ -317,10 +318,10 @@ class ApiTest(TestCase): headers={'X-Auth-Token': 'some token value'} ) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -375,10 +376,10 @@ class ApiTest(TestCase): code, result = self.api_delete('/volume/VOLUME_ID', data=data, headers={'X-Auth-Token': 'some token value'}) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -428,10 +429,10 @@ class ApiTest(TestCase): code, result = self.api_put('/volume/VOLUME_ID/resize', data=data, headers={'X-Auth-Token': 'some token value'}) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -488,10 +489,10 @@ class ApiTest(TestCase): code, result = self.api_put('/volume/VOLUME_ID/attach', data=data, headers={'X-Auth-Token': 'some token value'}) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -544,10 +545,10 @@ class ApiTest(TestCase): code, result = self.api_put('/volume/VOLUME_ID/detach', data=data, headers={'X-Auth-Token': 'some token value'}) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -636,10 +637,10 @@ class ApiTest(TestCase): headers={'X-Auth-Token': 'some token value'} ) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -717,10 +718,10 @@ class ApiTest(TestCase): code, result = self.api_delete('/instance/INSTANCE_ID', data=data, headers={'X-Auth-Token': 'some token value'}) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -764,10 +765,10 @@ class ApiTest(TestCase): headers={'X-Auth-Token': 'some token value'} ) assert_that(result, has_entries( - { + { "error": "The provided date has an invalid format. " "Format should be of yyyy-mm-ddThh:mm:ss.msZ, ex: 2015-01-31T18:24:34.1523Z" - } + } )) assert_that(code, equal_to(400)) @@ -891,6 +892,7 @@ class ApiTest(TestCase): class DateMatcher(object): + def __init__(self, date): self.date = date diff --git a/tests/builder.py b/tests/builder.py index 4f922dd..3131132 100644 --- a/tests/builder.py +++ b/tests/builder.py @@ -22,11 +22,13 @@ from almanach.core.model import build_entity_from_dict, Instance, Volume, Volume class Builder(object): + def __init__(self, dict_object): self.dict_object = dict_object class EntityBuilder(Builder): + def build(self): return build_entity_from_dict(self.dict_object) @@ -73,6 +75,7 @@ class EntityBuilder(Builder): class VolumeBuilder(EntityBuilder): + def with_attached_to(self, attached_to): self.dict_object["attached_to"] = attached_to return self @@ -91,6 +94,7 @@ class VolumeBuilder(EntityBuilder): class VolumeTypeBuilder(Builder): + def build(self): return VolumeType(**self.dict_object) diff --git a/tests/core/test_controller.py b/tests/core/test_controller.py index d8bcc6a..955b76b 100644 --- a/tests/core/test_controller.py +++ b/tests/core/test_controller.py @@ -64,8 +64,8 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.create_instance(fake_instance.entity_id, fake_instance.project_id, fake_instance.start, - fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro, - fake_instance.os.version, fake_instance.name, fake_instance.metadata) + fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro, + fake_instance.os.version, fake_instance.name, fake_instance.metadata) def test_resize_instance(self): fake_instance = a(instance()) @@ -123,9 +123,9 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.create_instance(fake_instance.entity_id, fake_instance.project_id, - '2015-10-21T16:25:00.000000Z', - fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro, - fake_instance.os.version, fake_instance.name, fake_instance.metadata) + '2015-10-21T16:25:00.000000Z', + fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro, + fake_instance.os.version, fake_instance.name, fake_instance.metadata) def test_instance_created_but_find_garbage(self): fake_instance = a(instance().with_all_dates_in_string()) @@ -147,8 +147,8 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.create_instance(fake_instance.entity_id, fake_instance.project_id, fake_instance.start, - fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro, - fake_instance.os.version, fake_instance.name, fake_instance.metadata) + fake_instance.flavor, fake_instance.os.os_type, fake_instance.os.distro, + fake_instance.os.version, fake_instance.name, fake_instance.metadata) def test_instance_deleted(self): (flexmock(self.database_adapter) @@ -250,7 +250,8 @@ class ControllerTest(unittest.TestCase): .with_args("project_id", "start", "end") .and_return(["volume2", "volume3", "instance1"])) - self.assertEqual(self.controller.list_entities("project_id", "start", "end"), ["volume2", "volume3", "instance1"]) + self.assertEqual(self.controller.list_entities( + "project_id", "start", "end"), ["volume2", "volume3", "instance1"]) def test_create_volume(self): some_volume_type = a(volume_type().with_volume_type_name("some_volume_type_name")) @@ -280,22 +281,22 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.create_volume(some_volume.entity_id, some_volume.project_id, some_volume.start, - some_volume_type.volume_type_id, some_volume.size, some_volume.name, - some_volume.attached_to) + some_volume_type.volume_type_id, some_volume.size, some_volume.name, + some_volume.attached_to) def test_create_volume_raises_bad_date_format(self): some_volume = a(volume()) assert_raises( - DateFormatException, - self.controller.create_volume, - some_volume.entity_id, - some_volume.project_id, - 'bad_date_format', - some_volume.volume_type, - some_volume.size, - some_volume.name, - some_volume.attached_to + DateFormatException, + self.controller.create_volume, + some_volume.entity_id, + some_volume.project_id, + 'bad_date_format', + some_volume.volume_type, + some_volume.size, + some_volume.name, + some_volume.attached_to ) def test_create_volume_insert_none_volume_type_as_type(self): @@ -324,8 +325,8 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.create_volume(some_volume.entity_id, some_volume.project_id, some_volume.start, - some_volume_type.volume_type_id, some_volume.size, some_volume.name, - some_volume.attached_to) + some_volume_type.volume_type_id, some_volume.size, some_volume.name, + some_volume.attached_to) def test_create_volume_with_invalid_volume_type(self): some_volume_type = a(volume_type()) @@ -350,8 +351,8 @@ class ControllerTest(unittest.TestCase): with self.assertRaises(KeyError): self.controller.create_volume(some_volume.entity_id, some_volume.project_id, some_volume.start, - some_volume_type.volume_type_id, some_volume.size, some_volume.name, - some_volume.attached_to) + some_volume_type.volume_type_id, some_volume.size, some_volume.name, + some_volume.attached_to) def test_create_volume_but_its_an_old_event(self): some_volume = a(volume().with_last_event(pytz.utc.localize(datetime(2015, 10, 21, 16, 29, 0)))) @@ -362,7 +363,7 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.create_volume(some_volume.entity_id, some_volume.project_id, '2015-10-21T16:25:00.000000Z', - some_volume.volume_type, some_volume.size, some_volume.name, some_volume.attached_to) + some_volume.volume_type, some_volume.size, some_volume.name, some_volume.attached_to) def test_volume_updated(self): fake_volume = a(volume()) @@ -406,9 +407,9 @@ class ControllerTest(unittest.TestCase): .with_args(fake_volume)) self.controller.attach_volume( - fake_volume.entity_id, - date.strftime("%Y-%m-%dT%H:%M:%S.%f"), - ["new_attached_to"] + fake_volume.entity_id, + date.strftime("%Y-%m-%dT%H:%M:%S.%f"), + ["new_attached_to"] ) self.assertEqual(fake_volume.attached_to, ["new_attached_to"]) @@ -430,9 +431,9 @@ class ControllerTest(unittest.TestCase): .with_args(fake_volume)) self.controller.attach_volume( - fake_volume.entity_id, - date.strftime("%Y-%m-%dT%H:%M:%S.%f"), - ["existing_attached_to", "new_attached_to"] + fake_volume.entity_id, + date.strftime("%Y-%m-%dT%H:%M:%S.%f"), + ["existing_attached_to", "new_attached_to"] ) self.assertEqual(fake_volume.attached_to, ["existing_attached_to", "new_attached_to"]) @@ -468,9 +469,9 @@ class ControllerTest(unittest.TestCase): .once()) self.controller.attach_volume( - fake_volume.entity_id, - date.strftime("%Y-%m-%dT%H:%M:%S.%f"), - ["new_attached_to"] + fake_volume.entity_id, + date.strftime("%Y-%m-%dT%H:%M:%S.%f"), + ["new_attached_to"] ) def test_volume_detach_with_two_attachments(self): @@ -631,4 +632,3 @@ class ControllerTest(unittest.TestCase): .once()) self.assertEqual(len(self.controller.list_volume_types()), 2) - diff --git a/tests/messages.py b/tests/messages.py index e724af7..6ce146c 100644 --- a/tests/messages.py +++ b/tests/messages.py @@ -272,7 +272,7 @@ def _get_instance_payload(event_type, instance_id=None, tenant_id=None, hostname def _get_volume_icehouse_payload(event_type, volume_id=None, tenant_id=None, display_name=None, volume_type=None, - volume_size=None, timestamp=None, created_at=None, launched_at=None, status=None, attached_to=None): + volume_size=None, timestamp=None, created_at=None, launched_at=None, status=None, attached_to=None): volume_id = volume_id or "64a0ca7f-5f5a-4dc5-a1e1-e04e89eb95ed" tenant_id = tenant_id or "46eeb8e44298460899cf4b3554bfe11f" display_name = display_name or "mytenant-0001-myvolume" @@ -312,7 +312,7 @@ def _get_volume_icehouse_payload(event_type, volume_id=None, tenant_id=None, dis def _get_volume_kilo_payload(event_type, volume_id=None, tenant_id=None, display_name=None, volume_type=None, - timestamp=None, attached_to=None, volume_size=1): + timestamp=None, attached_to=None, volume_size=1): volume_id = volume_id or "64a0ca7f-5f5a-4dc5-a1e1-e04e89eb95ed" tenant_id = tenant_id or "46eeb8e44298460899cf4b3554bfe11f" display_name = display_name or "mytenant-0001-myvolume" From e4ab5ba5d1daefc65042f6c687b9de55c6aed131 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 14 Apr 2016 14:49:43 -0400 Subject: [PATCH 2/2] Rename exceptions filename to avoid camelCase --- almanach/adapters/api_route_v1.py | 2 +- almanach/adapters/database_adapter.py | 4 ++-- .../common/{AlmanachException.py => almanach_exception.py} | 0 .../{DateFormatException.py => date_format_exception.py} | 0 ...otFoundException.py => volume_type_not_found_exception.py} | 0 almanach/config.py | 2 +- almanach/core/controller.py | 2 +- tests/adapters/test_database_adapter.py | 4 ++-- tests/api_test.py | 4 ++-- tests/core/test_controller.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename almanach/common/{AlmanachException.py => almanach_exception.py} (100%) rename almanach/common/{DateFormatException.py => date_format_exception.py} (100%) rename almanach/common/{VolumeTypeNotFoundException.py => volume_type_not_found_exception.py} (100%) diff --git a/almanach/adapters/api_route_v1.py b/almanach/adapters/api_route_v1.py index 4154d51..72202bc 100644 --- a/almanach/adapters/api_route_v1.py +++ b/almanach/adapters/api_route_v1.py @@ -22,7 +22,7 @@ from flask import Blueprint, Response, request from werkzeug.wrappers import BaseResponse from almanach import config -from almanach.common.DateFormatException import DateFormatException +from almanach.common.date_format_exception import DateFormatException api = Blueprint("api", __name__) controller = None diff --git a/almanach/adapters/database_adapter.py b/almanach/adapters/database_adapter.py index 5010e22..9c56890 100644 --- a/almanach/adapters/database_adapter.py +++ b/almanach/adapters/database_adapter.py @@ -17,8 +17,8 @@ import pymongo from pymongo.errors import ConfigurationError from almanach import config -from almanach.common.AlmanachException import AlmanachException -from almanach.common.VolumeTypeNotFoundException import VolumeTypeNotFoundException +from almanach.common.almanach_exception import AlmanachException +from almanach.common.volume_type_not_found_exception import VolumeTypeNotFoundException from almanach.core.model import build_entity_from_dict, VolumeType from pymongomodem.utils import decode_output, encode_input diff --git a/almanach/common/AlmanachException.py b/almanach/common/almanach_exception.py similarity index 100% rename from almanach/common/AlmanachException.py rename to almanach/common/almanach_exception.py diff --git a/almanach/common/DateFormatException.py b/almanach/common/date_format_exception.py similarity index 100% rename from almanach/common/DateFormatException.py rename to almanach/common/date_format_exception.py diff --git a/almanach/common/VolumeTypeNotFoundException.py b/almanach/common/volume_type_not_found_exception.py similarity index 100% rename from almanach/common/VolumeTypeNotFoundException.py rename to almanach/common/volume_type_not_found_exception.py diff --git a/almanach/config.py b/almanach/config.py index 64bcc32..d094bc8 100644 --- a/almanach/config.py +++ b/almanach/config.py @@ -16,7 +16,7 @@ import ConfigParser import pkg_resources import os.path as Path -from almanach.common.AlmanachException import AlmanachException +from almanach.common.almanach_exception import AlmanachException configuration = ConfigParser.RawConfigParser() diff --git a/almanach/core/controller.py b/almanach/core/controller.py index 3119485..b61fa32 100644 --- a/almanach/core/controller.py +++ b/almanach/core/controller.py @@ -19,7 +19,7 @@ from datetime import timedelta from dateutil import parser as date_parser from pkg_resources import get_distribution -from almanach.common.DateFormatException import DateFormatException +from almanach.common.date_format_exception import DateFormatException from almanach.core.model import Instance, Volume, VolumeType from almanach import config diff --git a/tests/adapters/test_database_adapter.py b/tests/adapters/test_database_adapter.py index c507aa8..4399d35 100644 --- a/tests/adapters/test_database_adapter.py +++ b/tests/adapters/test_database_adapter.py @@ -21,8 +21,8 @@ from hamcrest import assert_that, contains_inanyorder from pymongo import MongoClient from almanach.adapters.database_adapter import DatabaseAdapter -from almanach.common.VolumeTypeNotFoundException import VolumeTypeNotFoundException -from almanach.common.AlmanachException import AlmanachException +from almanach.common.volume_type_not_found_exception import VolumeTypeNotFoundException +from almanach.common.almanach_exception import AlmanachException from almanach import config from almanach.core.model import todict from tests.builder import a, instance, volume, volume_type diff --git a/tests/api_test.py b/tests/api_test.py index e91979f..998042f 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -22,8 +22,8 @@ from flexmock import flexmock, flexmock_teardown from hamcrest import assert_that, has_key, equal_to, has_length, has_entry, has_entries from almanach import config -from almanach.common.DateFormatException import DateFormatException -from almanach.common.AlmanachException import AlmanachException +from almanach.common.date_format_exception import DateFormatException +from almanach.common.almanach_exception import AlmanachException from almanach.adapters import api_route_v1 as api_route from tests.builder import a, instance, volume_type diff --git a/tests/core/test_controller.py b/tests/core/test_controller.py index 955b76b..892bb13 100644 --- a/tests/core/test_controller.py +++ b/tests/core/test_controller.py @@ -21,7 +21,7 @@ from flexmock import flexmock, flexmock_teardown from nose.tools import assert_raises from almanach import config -from almanach.common.DateFormatException import DateFormatException +from almanach.common.date_format_exception import DateFormatException from almanach.core.controller import Controller from almanach.core.model import Instance, Volume from tests.builder import a, instance, volume, volume_type