def test_on_get_response_networksv2_list(self): """Test list function""" client, env = get_client_env(query_string='name=123321') client['Account'].getNetworkVlans.return_value = [{ 'id': '123321', 'name': 'Public Network', 'subnets': [{ 'id': 1 }, { 'id': 3 }, { 'id': 5 }], 'vlanNumber': 999, 'networkSpace': 'PRIVATE' }] req = falcon.Request(env) resp = falcon.Response() networks.NetworksV2().on_get(req, resp) self.assertEqual(resp.status, 200) self.check_response_body(resp.body['networks'][0])
def setup_routes(app, disp): # V2 Routes disp.set_handler('v2_network', networks.NetworkV2()) disp.set_handler('v2_networks', networks.NetworksV2()) disp.set_handler('v2_subnet', subnets.SubnetV2()) disp.set_handler('v2_subnets', subnets.SubnetsV2()) disp.set_handler('v2_extensions', extensions.ExtensionsV2()) sl_common.add_hooks(app)
def setup_routes(app, disp): # V2 Routes disp.set_handler('index', index.Index(app)) disp.set_handler('v2_detail', versionv2.VersionV2(app)) disp.set_handler('v2_network', networks.NetworkV2()) disp.set_handler('v2_networks', networks.NetworksV2()) disp.set_handler('v2_subnet', subnets.SubnetV2()) disp.set_handler('v2_subnets', subnets.SubnetsV2()) disp.set_handler('v2_extensions', extensions.ExtensionsV2()) sl_common.add_hooks(app)
def test_on_get_response_networksv2_show_no_match(self): """Test show function in NetworksV2 with no matching ID""" client, env = get_client_env(query_string='name=123321') client['Account'].getNetworkVlans.return_value = [] req = api.Request(env, sl_client=client) resp = falcon.Response() networks.NetworksV2().on_get(req, resp) self.assertEqual(resp.status, 200) self.assertEqual(resp.body['networks'], [])
def test_on_get_response_networksv2_list_filter_private(self): client, env = get_client_env(query_string='name=private') client['Account'].getNetworkVlans.return_value = [] req = api.Request(env, sl_client=client) resp = falcon.Response() networks.NetworksV2().on_get(req, resp) self.assertEqual(resp.status, 200) self.assertEqual(len(resp.body['networks']), 1) self.assertEqual( resp.body['networks'][0], networks.format_network(networks.VLANS['private'], TENANT_ID))
def test_on_get_response_networksv2_show(self): """Test show function in NetworksV2""" client, env = get_client_env(query_string='name=123321') account = client['Account'] fake_net = get_fake_net(network='PRIVATE') account.getNetworkVlans.return_value = [fake_net] req = api.Request(env, sl_client=client) resp = falcon.Response() networks.NetworksV2().on_get(req, resp) self.assertEqual(resp.status, 200) self.assertEqual(resp.body['networks'][0], networks.format_network(fake_net, TENANT_ID))
def test_on_get_response_networksv2_list_no_filter(self): # Verify that a list with no filter will return all of the # networks from getNetworkVlans along with the placeholder # public and private networks client, env = get_client_env() fake_net = get_fake_net(network='PRIVATE') client['Account'].getNetworkVlans.return_value = [fake_net] req = api.Request(env, sl_client=client) resp = falcon.Response() networks.NetworksV2().on_get(req, resp) nets = [fake_net] + networks.VLANS.values() expected = [networks.format_network(net, TENANT_ID) for net in nets] self.assertEqual(resp.status, 200) self.assertEqual(len(resp.body['networks']), 3) # Assert that we have 3 networks: the fake network, # public placeholder network, and the private placeholder network self.assertItemsEqual(resp.body['networks'], expected)