quantumclient unit test: Declare less variables when possible

Bug #1111192 reported by Avishay Balderman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Won't Fix
Undecided
Unassigned
python-neutronclient
Expired
Low
Unassigned

Bug Description

In quantumclient/tests/unit/lb/test_cli20_pool.py (as an example) we have the following code:
def test_create_pool_with_mandatory_params(self):
        """lb-pool-create with mandatory params only"""
        resource = 'pool'
        cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None)
        name = 'my-name'
        lb_method = 'round-robin'
        protocol = 'http'
        subnet_id = 'subnet-id'
        tenant_id = 'my-tenant'
        my_id = 'my-id'
        args = ['--lb-method', lb_method,
                '--name', name,
                '--protocol', protocol,
                '--subnet-id', subnet_id,
                '--tenant-id', tenant_id]
        position_names = ['admin_state_up', 'lb_method', 'name',
                          'protocol', 'subnet_id', 'tenant_id']
        position_values = [True, lb_method, name,
                           protocol, subnet_id, tenant_id]
        self._test_create_resource(resource, cmd, name, my_id, args,
                                   position_names, position_values)

 -- This is a pattern in the load balancing tests in quantumclient. --
The proposal below will cover the 'simple' cases and might need some modifications in other cases

We are able to implement this code in a more "economic" way. The main point us to define 'args' as dict and derive rest of the data we need from this dict.

A working example below.
-----------------------------
def create_args(args):
    position_names = args.keys()
    position_values = args.values()
    args_list = []
    for k,v in args.iteritems():
        args_list.append("--" + k)
        args_list.append(v)
    return position_names, position_values, args_list
def main():
    args = {}
    args["name"] = "my-name"
    args["description"] = "my-description"
    args["address"] = "10.0.0.2"
    args["admin_state"] = False
    args["connection_limit"] = 1000
    args["port"] = 80
    args["subnet_id"] = "subnet_id"
    args["tenant_id"] = "my-tenant"
    position_names, position_values, args_list = create_args(args)
    print position_names
    print position_values
    print args_list
if __name__ == "__main__":
    main()

Revision history for this message
Maru Newby (maru) wrote :

Please refine the description of this bug to be more specific to the problem being addressed.

Also, if args is going to be defined as a dict, consider defining it in one step for brevity, e.g.:

args = dict(
  name='my-name',
  description='my-description',
  ...
  )

summary: - Having less code do the same job.
+ quantumclient-lbass test. Declare less variabels
summary: - quantumclient-lbass test. Declare less variabels
+ quantumclient-lbass test. Declare less variabels when possible.
Revision history for this message
Mark McClain (markmcclain) wrote : Re: quantumclient-lbass test. Declare less variabels when possible.

Moving to client project since this bug applies there.

tags: added: lbaas
Changed in quantum:
status: New → Won't Fix
Revision history for this message
Akihiro Motoki (amotoki) wrote :

It is not specific to LBaaS v1 test. This pattern is used everywhere in neutronclient.
It should be cleanup once.

BTW, neutronclient uses mox as the test framework.
If we do migration to mock, it may be a good chance to refactor this kind tests.

tags: removed: lbaas
summary: - quantumclient-lbass test. Declare less variabels when possible.
+ quantumclient unit test: Declare less variables when possible
Changed in python-neutronclient:
importance: Undecided → Low
Revision history for this message
Akihiro Motoki (amotoki) wrote :

There is no activity for a long time, so I will mark it as Incomplete.

Changed in python-neutronclient:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for python-neutronclient because there has been no activity for 60 days.]

Changed in python-neutronclient:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.