Skip to content

Commit cf78b95

Browse files
committed
add integration tests
1 parent d34af78 commit cf78b95

7 files changed

Lines changed: 844 additions & 129 deletions
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 floatingip
19+
from openstackclient.tests.network.v2_0 import common
20+
21+
22+
class TestFloatingIpIntegration(common.TestIntegrationBase):
23+
HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER
24+
NETWORK_URL = HOSTESS + "/networks.json"
25+
NETWORK_ONE = '{ "networks": [{ "id": "2222223" }] }'
26+
CREATE_URL = HOSTESS + "/floatingips.json"
27+
CREATE = """
28+
{
29+
"floatingip":
30+
{
31+
"status": "ACTIVE",
32+
"name": "gator",
33+
"tenant_id": "33a40233",
34+
"id": "a9254bdb"
35+
}
36+
}"""
37+
DELETE_URL = HOSTESS + "/floatingips/gator.json"
38+
DELETE = "{}"
39+
LIST_URL = HOSTESS + "/floatingips.json"
40+
LIST_ONE = '{ "floatingips": [{ "id": "a9254bdb" }] }'
41+
LIST = """
42+
{
43+
"floatingips": [
44+
{
45+
"id": "a9254bdb",
46+
"fixed_ip_address": "10.1.1.1",
47+
"floating_ip_address": "15.1.1.2",
48+
"port_id": "9090909",
49+
"tenant_id": "33a40233"
50+
},
51+
{
52+
"id": "b8408dgd",
53+
"fixed_ip_address": "10.1.1.2",
54+
"floating_ip_address": "15.1.1.3",
55+
"port_id": "8080808",
56+
"tenant_id": "33a40233"
57+
}
58+
]
59+
}"""
60+
SHOW_URL = HOSTESS + "/floatingips/gator.json"
61+
SHOW = CREATE
62+
63+
@httpretty.activate
64+
def test_create(self):
65+
pargs = common.FakeParsedArgs()
66+
pargs.name = 'gator'
67+
pargs.floating_network_id = '123123'
68+
pargs.port_id = '7777899'
69+
pargs.fixed_ip_address = None
70+
pargs.tenant_id = '33a40233'
71+
httpretty.register_uri(httpretty.GET, self.NETWORK_URL,
72+
body=self.NETWORK_ONE)
73+
httpretty.register_uri(httpretty.POST, self.CREATE_URL,
74+
body=self.CREATE)
75+
self.when_run(floatingip.CreateFloatingIp, pargs)
76+
self.assertEqual('', self.stderr())
77+
self.assertEqual(u"""\
78+
Created a new floatingip:
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.DELETE, self.DELETE_URL,
90+
body=self.DELETE)
91+
self.when_run(floatingip.DeleteFloatingIp, pargs)
92+
self.assertEqual('', self.stderr())
93+
self.assertEqual(u'Deleted floatingip: gator\n',
94+
self.stdout())
95+
96+
@httpretty.activate
97+
def test_list(self):
98+
pargs = common.FakeParsedArgs()
99+
pargs.formatter = 'csv'
100+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
101+
body=self.LIST)
102+
self.when_run(floatingip.ListFloatingIp, pargs)
103+
self.assertEqual('', self.stderr())
104+
self.assertEqual("""\
105+
id,fixed_ip_address,floating_ip_address,port_id
106+
a9254bdb,10.1.1.1,15.1.1.2,9090909
107+
b8408dgd,10.1.1.2,15.1.1.3,8080808
108+
""", self.stdout())
109+
110+
@httpretty.activate
111+
def test_show(self):
112+
pargs = common.FakeParsedArgs()
113+
pargs.id = 'gator'
114+
httpretty.register_uri(httpretty.GET, self.SHOW_URL,
115+
body=self.SHOW)
116+
self.when_run(floatingip.ShowFloatingIp, pargs)
117+
self.assertEqual('', self.stderr())
118+
self.assertEqual(u"""\
119+
id="a9254bdb"
120+
name="gator"
121+
status="ACTIVE"
122+
tenant_id="33a40233"
123+
""", self.stdout())
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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 port
19+
from openstackclient.tests.network.v2_0 import common
20+
21+
22+
class TestPortIntegration(common.TestIntegrationBase):
23+
HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER
24+
NETWORK_URL = HOSTESS + "/networks.json"
25+
NETWORK = '{ "networks": [{ "id": "1111111" }] }'
26+
ROUTER_URL = HOSTESS + "/routers.json"
27+
ROUTER = '{ "routers": [{ "id": "22222222" }] }'
28+
CREATE_URL = HOSTESS + "/ports.json"
29+
CREATE = """
30+
{
31+
"port":
32+
{
33+
"status": "ACTIVE",
34+
"name": "gator",
35+
"tenant_id": "33a40233",
36+
"id": "a9254bdb"
37+
}
38+
}"""
39+
DELETE_URL = HOSTESS + "/ports/a9254bdb.json"
40+
DELETE = "{}"
41+
LIST_URL = HOSTESS + "/ports.json"
42+
LIST_ONE = '{ "ports": [{ "id": "a9254bdb" }] }'
43+
LIST = """
44+
{
45+
"ports": [
46+
{
47+
"status": "ACTIVE",
48+
"name": "gator",
49+
"tenant_id": "33a40233",
50+
"id": "a9254bdb"
51+
},
52+
{
53+
"status": "ACTIVE",
54+
"name": "croc",
55+
"tenant_id": "33a40233",
56+
"id": "b8408dgd"
57+
}
58+
]
59+
}"""
60+
SHOW_URL = HOSTESS + "/ports/a9254bdb.json"
61+
SHOW = CREATE
62+
63+
@httpretty.activate
64+
def test_create(self):
65+
pargs = common.FakeParsedArgs()
66+
pargs.name = 'gator'
67+
pargs.network_id = '44444448'
68+
pargs.admin_state = 'UP'
69+
pargs.mac_address = '1231233212'
70+
pargs.device_id = '1231231237'
71+
pargs.fixed_ip = None
72+
pargs.security_groups = None
73+
pargs.no_security_groups = False
74+
pargs.extra_dhcp_opts = None
75+
pargs.tenant_id = '33a40233'
76+
httpretty.register_uri(httpretty.GET, self.NETWORK_URL,
77+
body=self.NETWORK)
78+
httpretty.register_uri(httpretty.POST, self.CREATE_URL,
79+
body=self.CREATE)
80+
self.when_run(port.CreatePort, pargs)
81+
self.assertEqual('', self.stderr())
82+
self.assertEqual(u"""\
83+
Created a new port:
84+
id="a9254bdb"
85+
name="gator"
86+
status="ACTIVE"
87+
tenant_id="33a40233"
88+
""", self.stdout())
89+
90+
@httpretty.activate
91+
def test_delete(self):
92+
pargs = common.FakeParsedArgs()
93+
pargs.id = 'gator'
94+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
95+
body=self.LIST_ONE)
96+
httpretty.register_uri(httpretty.DELETE, self.DELETE_URL,
97+
body=self.DELETE)
98+
self.when_run(port.DeletePort, pargs)
99+
self.assertEqual('', self.stderr())
100+
self.assertEqual(u'Deleted port: gator\n',
101+
self.stdout())
102+
103+
@httpretty.activate
104+
def test_list(self):
105+
pargs = common.FakeParsedArgs()
106+
pargs.router = 'roo'
107+
pargs.page_size = None
108+
pargs.sort_key = []
109+
pargs.sort_dir = []
110+
pargs.formatter = 'csv'
111+
httpretty.register_uri(httpretty.GET, self.ROUTER_URL,
112+
body=self.ROUTER)
113+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
114+
body=self.LIST)
115+
self.when_run(port.ListPort, pargs)
116+
self.assertEqual('', self.stderr())
117+
self.assertEqual("""\
118+
id,name
119+
a9254bdb,gator
120+
b8408dgd,croc
121+
""", self.stdout())
122+
123+
@httpretty.activate
124+
def test_set(self):
125+
pargs = common.FakeParsedArgs()
126+
pargs.name = 'gator'
127+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
128+
body=self.LIST_ONE)
129+
self.when_run(port.SetPort, pargs)
130+
self.assertEqual('', self.stderr())
131+
self.assertEqual('', self.stdout())
132+
133+
@httpretty.activate
134+
def test_show(self):
135+
pargs = common.FakeParsedArgs()
136+
pargs.id = 'gator'
137+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
138+
body=self.LIST_ONE)
139+
httpretty.register_uri(httpretty.GET, self.SHOW_URL,
140+
body=self.SHOW)
141+
self.when_run(port.ShowPort, pargs)
142+
self.assertEqual('', self.stderr())
143+
self.assertEqual(u"""\
144+
id="a9254bdb"
145+
name="gator"
146+
status="ACTIVE"
147+
tenant_id="33a40233"
148+
""", self.stdout())

0 commit comments

Comments
 (0)