Beispiel #1
0
 def test_get_id_from_id_then_name_empty(self):
     _id = str(uuid.uuid4())
     reses = {
         'networks': [
             {
                 'id': _id,
             },
         ],
     }
     resstr = self.client.serialize(reses)
     resstr1 = self.client.serialize({'networks': []})
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, "networks_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&id=" + _id),
         'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr1))
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&name=" + _id),
         'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     returned_id = quantumv20.find_resourceid_by_name_or_id(
         self.client, 'network', _id)
     self.assertEqual(_id, returned_id)
Beispiel #2
0
    def test_list_nets_empty_with_column(self):
        resources = "networks"
        cmd = ListNetwork(MyApp(sys.stdout), None)
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {resources: []}
        resstr = self.client.serialize(reses)
        # url method body
        query = "id=myfakeid"
        args = ['-c', 'id', '--', '--id', 'myfakeid']
        path = getattr(self.client, resources + "_path")
        self.client.httpclient.request(test_cli20.end_url(path, query),
                                       'GET',
                                       body=None,
                                       headers=test_cli20.ContainsKeyValue(
                                           'X-Auth-Token',
                                           test_cli20.TOKEN)).AndReturn(
                                               (test_cli20.MyResp(200),
                                                resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertEquals('\n', _str)
Beispiel #3
0
 def test_get_id_from_name_multiple(self):
     name = 'myname'
     reses = {
         'networks': [{
             'id': str(uuid.uuid4())
         }, {
             'id': str(uuid.uuid4())
         }]
     }
     resstr = self.client.serialize(reses)
     self.mox.StubOutWithMock(self.client.httpclient, "request")
     path = getattr(self.client, "networks_path")
     self.client.httpclient.request(
         test_cli20.end_url(path, "fields=id&name=" + name),
         'GET',
         body=None,
         headers=ContainsKeyValue('X-Auth-Token',
                                  test_cli20.TOKEN)).AndReturn(
                                      (test_cli20.MyResp(200), resstr))
     self.mox.ReplayAll()
     try:
         quantumv20.find_resourceid_by_name_or_id(self.client, 'network',
                                                  name)
     except exceptions.QuantumClientException as ex:
         self.assertTrue('Multiple' in ex.message)