diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-04-20 20:22:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-04-20 20:22:55 +0000 |
| commit | e78113a5fcc924eaed8f331b42b314949fc64b12 (patch) | |
| tree | 767356866045cbab860496cd744e70ff68b35187 /openstackclient/tests/compute | |
| parent | 98a0fba3c1fc8e5fa231d07349cb38102b015cc4 (diff) | |
| parent | 09c20b2b5c53024c47da8828095ea95dc63810f6 (diff) | |
| download | python-openstackclient-e78113a5fcc924eaed8f331b42b314949fc64b12.tar.gz | |
Merge "Fix mutable default arguments in tests"
Diffstat (limited to 'openstackclient/tests/compute')
| -rw-r--r-- | openstackclient/tests/compute/v2/fakes.py | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 7f38b32b..948d9e97 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -100,8 +100,7 @@ class FakeAggregate(object): :return: A FakeResource object, with id and other attributes """ - if attrs is None: - attrs = {} + attrs = attrs or {} # Set default attribute aggregate_info = { @@ -220,7 +219,7 @@ class FakeHypervisor(object): """Fake one or more hypervisor.""" @staticmethod - def create_one_hypervisor(attrs={}): + def create_one_hypervisor(attrs=None): """Create a fake hypervisor. :param Dictionary attrs: @@ -228,6 +227,8 @@ class FakeHypervisor(object): :return: A FakeResource object, with id, hypervisor_hostname, and so on """ + attrs = attrs or {} + # Set default attributes. hypervisor_info = { 'id': 'hypervisor-id-' + uuid.uuid4().hex, @@ -266,7 +267,7 @@ class FakeHypervisor(object): return hypervisor @staticmethod - def create_hypervisors(attrs={}, count=2): + def create_hypervisors(attrs=None, count=2): """Create multiple fake hypervisors. :param Dictionary attrs: @@ -287,7 +288,7 @@ class FakeHypervisorStats(object): """Fake one or more hypervisor stats.""" @staticmethod - def create_one_hypervisor_stats(attrs={}): + def create_one_hypervisor_stats(attrs=None): """Create a fake hypervisor stats. :param Dictionary attrs: @@ -295,6 +296,8 @@ class FakeHypervisorStats(object): :return: A FakeResource object, with id, hypervisor_hostname, and so on """ + attrs = attrs or {} + # Set default attributes. stats_info = { 'count': 2, @@ -322,7 +325,7 @@ class FakeHypervisorStats(object): return hypervisor_stats @staticmethod - def create_hypervisors_stats(attrs={}, count=2): + def create_hypervisors_stats(attrs=None, count=2): """Create multiple fake hypervisors stats. :param Dictionary attrs: @@ -352,8 +355,7 @@ class FakeSecurityGroup(object): :return: A FakeResource object, with id, name, etc. """ - if attrs is None: - attrs = {} + attrs = attrs or {} # Set default attributes. security_group_attrs = { @@ -403,8 +405,7 @@ class FakeSecurityGroupRule(object): :return: A FakeResource object, with id, etc. """ - if attrs is None: - attrs = {} + attrs = attrs or {} # Set default attributes. security_group_rule_attrs = { @@ -448,7 +449,7 @@ class FakeServer(object): """Fake one or more compute servers.""" @staticmethod - def create_one_server(attrs={}, methods={}): + def create_one_server(attrs=None, methods=None): """Create a fake server. :param Dictionary attrs: @@ -458,6 +459,9 @@ class FakeServer(object): :return: A FakeResource object, with id, name, metadata """ + attrs = attrs or {} + methods = methods or {} + # Set default attributes. server_info = { 'id': 'server-id-' + uuid.uuid4().hex, @@ -480,7 +484,7 @@ class FakeServer(object): return server @staticmethod - def create_servers(attrs={}, methods={}, count=2): + def create_servers(attrs=None, methods=None, count=2): """Create multiple fake servers. :param Dictionary attrs: @@ -530,8 +534,7 @@ class FakeFlavor(object): :return: A FakeResource object, with id, name, ram, vcpus, properties """ - if attrs is None: - attrs = {} + attrs = attrs or {} # Set default attributes. flavor_info = { @@ -569,7 +572,7 @@ class FakeFlavor(object): return flavor @staticmethod - def create_flavors(attrs={}, count=2): + def create_flavors(attrs=None, count=2): """Create multiple fake flavors. :param Dictionary attrs: @@ -617,10 +620,9 @@ class FakeKeypair(object): :return: A FakeResource """ - # Set default attributes. - if attrs is None: - attrs = {} + attrs = attrs or {} + # Set default attributes. keypair_info = { 'name': 'keypair-name-' + uuid.uuid4().hex, 'fingerprint': 'dummy', @@ -661,7 +663,7 @@ class FakeAvailabilityZone(object): """Fake one or more compute availability zones (AZs).""" @staticmethod - def create_one_availability_zone(attrs={}): + def create_one_availability_zone(attrs=None): """Create a fake AZ. :param Dictionary attrs: @@ -669,6 +671,8 @@ class FakeAvailabilityZone(object): :return: A FakeResource object with zoneName, zoneState, etc. """ + attrs = attrs or {} + # Set default attributes. host_name = uuid.uuid4().hex service_name = uuid.uuid4().hex @@ -692,7 +696,7 @@ class FakeAvailabilityZone(object): return availability_zone @staticmethod - def create_availability_zones(attrs={}, count=2): + def create_availability_zones(attrs=None, count=2): """Create multiple fake AZs. :param Dictionary attrs: @@ -715,7 +719,7 @@ class FakeFloatingIP(object): """Fake one or more floating ip.""" @staticmethod - def create_one_floating_ip(attrs={}): + def create_one_floating_ip(attrs=None): """Create a fake floating ip. :param Dictionary attrs: @@ -723,6 +727,8 @@ class FakeFloatingIP(object): :return: A FakeResource object, with id, ip, and so on """ + attrs = attrs or {} + # Set default attributes. floating_ip_attrs = { 'id': 'floating-ip-id-' + uuid.uuid4().hex, @@ -742,7 +748,7 @@ class FakeFloatingIP(object): return floating_ip @staticmethod - def create_floating_ips(attrs={}, count=2): + def create_floating_ips(attrs=None, count=2): """Create multiple fake floating ips. :param Dictionary attrs: @@ -781,7 +787,7 @@ class FakeNetwork(object): """Fake one or more networks.""" @staticmethod - def create_one_network(attrs={}): + def create_one_network(attrs=None): """Create a fake network. :param Dictionary attrs: @@ -789,6 +795,8 @@ class FakeNetwork(object): :return: A FakeResource object, with id, label, cidr and so on """ + attrs = attrs or {} + # Set default attributes. network_attrs = { 'bridge': 'br100', @@ -834,7 +842,7 @@ class FakeNetwork(object): return network @staticmethod - def create_networks(attrs={}, count=2): + def create_networks(attrs=None, count=2): """Create multiple fake networks. :param Dictionary attrs: @@ -863,8 +871,7 @@ class FakeHost(object): :return: A FakeResource object, with id and other attributes """ - if attrs is None: - attrs = {} + attrs = attrs or {} # Set default attributes. host_info = { |
