|
| 1 | +# Copyright 2013 OpenStack, LLC. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import httpretty |
| 17 | + |
| 18 | +from openstackclient.network.v2_0 import network |
| 19 | +from openstackclient.tests.network.v2_0 import common |
| 20 | + |
| 21 | + |
| 22 | +class TestNetworkIntegration(common.TestIntegrationBase): |
| 23 | + HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER |
| 24 | + SUBNETS_URL = HOSTESS + "/subnets.json" |
| 25 | + SUBNETS_ONE = '{ "subnets": [{ "id": "12312311" }]}' |
| 26 | + CREATE_URL = HOSTESS + "/networks.json" |
| 27 | + CREATE = """ |
| 28 | +{ |
| 29 | + "network": |
| 30 | + { |
| 31 | + "status": "ACTIVE", |
| 32 | + "name": "gator", |
| 33 | + "tenant_id": "33a40233", |
| 34 | + "id": "a9254bdb" |
| 35 | + } |
| 36 | +}""" |
| 37 | + DELETE_URL = HOSTESS + "/networks/a9254bdb.json" |
| 38 | + DELETE = "{}" |
| 39 | + LIST_URL = HOSTESS + "/networks.json" |
| 40 | + LIST_ONE = """ |
| 41 | +{ |
| 42 | + "networks": [{ |
| 43 | + "id": "a9254bdb" |
| 44 | + }] |
| 45 | +}""" |
| 46 | + LIST = """ |
| 47 | +{ |
| 48 | + "networks": [ |
| 49 | + { |
| 50 | + "status": "ACTIVE", |
| 51 | + "name": "gator", |
| 52 | + "tenant_id": "33a40233", |
| 53 | + "id": "a9254bdb" |
| 54 | + }, |
| 55 | + { |
| 56 | + "status": "ACTIVE", |
| 57 | + "name": "croc", |
| 58 | + "tenant_id": "33a40233", |
| 59 | + "id": "b8408dgd" |
| 60 | + } |
| 61 | + ] |
| 62 | +}""" |
| 63 | + SHOW_URL = HOSTESS + "/networks/a9254bdb.json" |
| 64 | + SHOW = CREATE |
| 65 | + |
| 66 | + @httpretty.activate |
| 67 | + def test_create(self): |
| 68 | + pargs = common.FakeParsedArgs() |
| 69 | + pargs.name = 'gator' |
| 70 | + pargs.admin_state = True |
| 71 | + pargs.shared = True |
| 72 | + pargs.tenant_id = '33a40233' |
| 73 | + httpretty.register_uri(httpretty.POST, self.CREATE_URL, |
| 74 | + body=self.CREATE) |
| 75 | + self.when_run(network.CreateNetwork, pargs) |
| 76 | + self.assertEqual('', self.stderr()) |
| 77 | + self.assertEqual(u"""\ |
| 78 | +Created a new network: |
| 79 | +id="a9254bdb" |
| 80 | +name="gator" |
| 81 | +status="ACTIVE" |
| 82 | +tenant_id="33a40233" |
| 83 | +""", self.stdout()) |
| 84 | + |
| 85 | + @httpretty.activate |
| 86 | + def test_delete(self): |
| 87 | + pargs = common.FakeParsedArgs() |
| 88 | + pargs.id = 'gator' |
| 89 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 90 | + body=self.LIST_ONE) |
| 91 | + httpretty.register_uri(httpretty.DELETE, self.DELETE_URL, |
| 92 | + body=self.DELETE) |
| 93 | + self.when_run(network.DeleteNetwork, pargs) |
| 94 | + self.assertEqual('', self.stderr()) |
| 95 | + self.assertEqual(u'Deleted network: gator\n', |
| 96 | + self.stdout()) |
| 97 | + |
| 98 | + @httpretty.activate |
| 99 | + def test_list(self): |
| 100 | + pargs = common.FakeParsedArgs() |
| 101 | + pargs.formatter = 'csv' |
| 102 | + pargs.external = False |
| 103 | + httpretty.register_uri(httpretty.GET, self.SUBNETS_URL, |
| 104 | + body=self.SUBNETS_ONE) |
| 105 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 106 | + body=self.LIST) |
| 107 | + self.when_run(network.ListNetwork, pargs) |
| 108 | + self.assertEqual('', self.stderr()) |
| 109 | + self.assertEqual("""\ |
| 110 | +id,name |
| 111 | +a9254bdb,gator |
| 112 | +b8408dgd,croc |
| 113 | +""", self.stdout()) |
| 114 | + |
| 115 | + @httpretty.activate |
| 116 | + def test_list_external(self): |
| 117 | + pargs = common.FakeParsedArgs() |
| 118 | + pargs.formatter = 'csv' |
| 119 | + pargs.external = True |
| 120 | + httpretty.register_uri(httpretty.GET, self.SUBNETS_URL, |
| 121 | + body=self.SUBNETS_ONE) |
| 122 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 123 | + body=self.LIST) |
| 124 | + self.when_run(network.ListNetwork, pargs) |
| 125 | + self.assertEqual('', self.stderr()) |
| 126 | + self.assertEqual("""\ |
| 127 | +id,name |
| 128 | +a9254bdb,gator |
| 129 | +b8408dgd,croc |
| 130 | +""", self.stdout()) |
| 131 | + |
| 132 | + @httpretty.activate |
| 133 | + def test_set(self): |
| 134 | + pargs = common.FakeParsedArgs() |
| 135 | + pargs.name = 'gator' |
| 136 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 137 | + body=self.LIST_ONE) |
| 138 | + self.when_run(network.SetNetwork, pargs) |
| 139 | + self.assertEqual('', self.stderr()) |
| 140 | + self.assertEqual('', self.stdout()) |
| 141 | + |
| 142 | + @httpretty.activate |
| 143 | + def test_show(self): |
| 144 | + pargs = common.FakeParsedArgs() |
| 145 | + pargs.id = 'gator' |
| 146 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 147 | + body=self.LIST_ONE) |
| 148 | + httpretty.register_uri(httpretty.GET, self.SHOW_URL, |
| 149 | + body=self.SHOW) |
| 150 | + self.when_run(network.ShowNetwork, pargs) |
| 151 | + self.assertEqual('', self.stderr()) |
| 152 | + self.assertEqual(u"""\ |
| 153 | +id="a9254bdb" |
| 154 | +name="gator" |
| 155 | +status="ACTIVE" |
| 156 | +tenant_id="33a40233" |
| 157 | +""", self.stdout()) |
0 commit comments