diff options
| author | Tang Chen <chen.tang@easystack.cn> | 2016-02-20 16:39:06 +0800 |
|---|---|---|
| committer | Tang Chen <chen.tang@easystack.cn> | 2016-02-20 16:39:06 +0800 |
| commit | 6af28838854ecb20c34d3ba1708b5b255155ef93 (patch) | |
| tree | 002169ebbb40a7df96b32d17ddf9cbc1e2352985 /openstackclient/tests | |
| parent | 5a978b9ec137cece167f0164dbb1754002a81bec (diff) | |
| download | python-openstackclient-6af28838854ecb20c34d3ba1708b5b255155ef93.tar.gz | |
Refactor: Set "project_id" for FakeXXX in a consistent style
OpenStack SDK will translate "project_id" into "tenant_id" automatically
when referring to "tenant_id" attribute with the name "project_id". So
when faking an object returned fron SDK, we need to fake this behavior.
The original way is ugly. This patch turns it into a consistent style,
and give better comments.
Change-Id: I0dfb1f7552fc28eb4e7ebf5c614c9f3bde79ad80
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/network/v2/fakes.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index 60895e74..680e9cbf 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -138,12 +138,11 @@ class FakeNetwork(object): router_external, status, subnets, tenant_id """ # Set default attributes. - project_id = 'project-id-' + uuid.uuid4().hex network_attrs = { 'id': 'network-id-' + uuid.uuid4().hex, 'name': 'network-name-' + uuid.uuid4().hex, 'status': 'ACTIVE', - 'tenant_id': project_id, + 'tenant_id': 'project-id-' + uuid.uuid4().hex, 'admin_state_up': True, 'shared': False, 'subnets': ['a', 'b'], @@ -169,7 +168,9 @@ class FakeNetwork(object): network = fakes.FakeResource(info=copy.deepcopy(network_attrs), methods=copy.deepcopy(network_methods), loaded=True) - network.project_id = project_id + + # Set attributes with special mapping in OpenStack SDK. + network.project_id = network_attrs['tenant_id'] return network @@ -273,7 +274,7 @@ class FakePort(object): methods=copy.deepcopy(port_methods), loaded=True) - # Set attributes with special mappings. + # Set attributes with special mappings in OpenStack SDK. port.project_id = port_attrs['tenant_id'] port.binding_host_id = port_attrs['binding:host_id'] port.binding_profile = port_attrs['binding:profile'] @@ -695,24 +696,19 @@ class FakeSubnetPool(object): A FakeResource object faking the subnet pool """ # Set default attributes. - project_id = 'project-id-' + uuid.uuid4().hex subnet_pool_attrs = { 'id': 'subnet-pool-id-' + uuid.uuid4().hex, 'name': 'subnet-pool-name-' + uuid.uuid4().hex, 'prefixes': ['10.0.0.0/24', '10.1.0.0/24'], 'default_prefixlen': 8, 'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex, - 'tenant_id': project_id, + 'tenant_id': 'project-id-' + uuid.uuid4().hex, 'is_default': False, 'shared': False, 'max_prefixlen': 32, 'min_prefixlen': 8, 'default_quota': None, 'ip_version': 4, - - # OpenStack SDK automatically translates project_id to tenant_id. - # So we need an additional attr to simulate this behavior. - 'project_id': project_id, } # Overwrite default attributes. @@ -735,6 +731,9 @@ class FakeSubnetPool(object): loaded=True ) + # Set attributes with special mapping in OpenStack SDK. + subnet_pool.project_id = subnet_pool_attrs['tenant_id'] + return subnet_pool @staticmethod |
