Skip to content

Commit 1a5704d

Browse files
jiahui.qiangstevemar
authored andcommitted
Functional test for ip_availability
Refactor ip_availability functional tests. Change-Id: I2397bd20236e1e9e3c69177ea6afbaadf2c445ae
1 parent 054060c commit 1a5704d

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

openstackclient/tests/functional/network/v2/test_ip_availability.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,27 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import json
1314
import uuid
1415

1516
from openstackclient.tests.functional import base
1617

1718

1819
class IPAvailabilityTests(base.TestCase):
1920
"""Functional tests for IP availability. """
20-
NAME = uuid.uuid4().hex
21-
NETWORK_NAME = uuid.uuid4().hex
22-
FIELDS = ['network_name']
2321

2422
@classmethod
2523
def setUpClass(cls):
2624
# Create a network for the subnet.
25+
cls.NAME = uuid.uuid4().hex
26+
cls.NETWORK_NAME = uuid.uuid4().hex
2727
cls.openstack('network create ' + cls.NETWORK_NAME)
28-
opts = cls.get_opts(['name'])
29-
raw_output = cls.openstack(
30-
'subnet create --network ' + cls.NETWORK_NAME +
28+
cmd_output = json.loads(cls.openstack(
29+
'subnet create -f json --network ' + cls.NETWORK_NAME +
3130
' --subnet-range 10.10.10.0/24 ' +
32-
cls.NAME + opts
33-
)
34-
expected = cls.NAME + '\n'
35-
cls.assertOutput(expected, raw_output)
31+
cls.NAME
32+
))
33+
cls.assertOutput(cls.NAME, cmd_output['name'])
3634

3735
@classmethod
3836
def tearDownClass(cls):
@@ -42,12 +40,17 @@ def tearDownClass(cls):
4240
cls.assertOutput('', raw_network)
4341

4442
def test_ip_availability_list(self):
45-
opts = ' -f csv -c "Network Name"'
46-
raw_output = self.openstack('ip availability list' + opts)
47-
self.assertIn(self.NETWORK_NAME, raw_output)
43+
"""Test ip availability list"""
44+
cmd_output = json.loads(self.openstack(
45+
'ip availability list -f json'))
46+
names = [x['Network Name'] for x in cmd_output]
47+
self.assertIn(self.NETWORK_NAME, names)
4848

4949
def test_ip_availability_show(self):
50-
opts = self.get_opts(self.FIELDS)
51-
raw_output = self.openstack(
52-
'ip availability show ' + self.NETWORK_NAME + opts)
53-
self.assertEqual(self.NETWORK_NAME + "\n", raw_output)
50+
"""Test ip availability show"""
51+
cmd_output = json.loads(self.openstack(
52+
'ip availability show -f json ' + self.NETWORK_NAME))
53+
self.assertEqual(
54+
self.NETWORK_NAME,
55+
cmd_output['network_name'],
56+
)

0 commit comments

Comments
 (0)