def test_list_nets_with_default_column(self): cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None) returned_body = {"networks": [{"name": "buildname3", "id": "id3", "tenant_id": "tenant_3", "subnets": []}]} self._test_list_nets_columns(cmd, returned_body) _str = self.fake_stdout.make_string() returned_networks = utils.loads(_str) self.assertEquals(1, len(returned_networks)) net = returned_networks[0] self.assertEquals(3, len(net)) self.assertEquals(0, len(set(net) ^ set(cmd.list_columns)))
def test_list_nets_defined_column(self): cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None) returned_body = {"networks": [{"name": "buildname3", "id": "id3", "tenant_id": "tenant_3", "subnets": []}]} self._test_list_nets_columns(cmd, returned_body, args=['-f', 'json', '-c', 'id']) _str = self.fake_stdout.make_string() returned_networks = utils.loads(_str) self.assertEquals(1, len(returned_networks)) net = returned_networks[0] self.assertEquals(1, len(net)) self.assertEquals("id", net.keys()[0])
def test_list_nets_with_default_column(self): resources = 'networks' cmd = ListNetwork(MyApp(sys.stdout), None) returned_body = { "networks": [{ "name": "buildname3", "id": "id3", "tenant_id": "tenant_3", "subnets": [] }] } self._test_list_columns(cmd, resources, returned_body) _str = self.fake_stdout.make_string() returned_networks = utils.loads(_str) self.assertEquals(1, len(returned_networks)) network = returned_networks[0] self.assertEquals(3, len(network)) self.assertEquals(0, len(set(network) ^ set(cmd.list_columns)))
def test_list_nets_defined_column(self): resources = 'networks' cmd = ListNetwork(MyApp(sys.stdout), None) returned_body = { "networks": [{ "name": "buildname3", "id": "id3", "tenant_id": "tenant_3", "subnets": [] }] } self._test_list_columns(cmd, resources, returned_body, args=['-f', 'json', '-c', 'id']) _str = self.fake_stdout.make_string() returned_networks = utils.loads(_str) self.assertEquals(1, len(returned_networks)) network = returned_networks[0] self.assertEquals(1, len(network)) self.assertEquals("id", network.keys()[0])
def _from_json(self, datastring): return utils.loads(datastring)
def test_loads(self): self.assertEqual(utils.loads('{"a": "b"}'), {'a': 'b'})