← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1111192] Re: quantumclient unit test: Declare less variables when possible

 

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

** Changed in: python-neutronclient
       Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1111192

Title:
  quantumclient unit test: Declare less variables when possible

Status in neutron:
  Won't Fix
Status in python-neutronclient:
  Expired

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()

To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1111192/+subscriptions