Convert network tests to httpretty
Change-Id: I81a83c98b925a2bc7373dd17f2c2ecd78fa23a6d blueprint: httpretty-testing
This commit is contained in:
parent
c4fa6648c8
commit
5d9537a02e
62
novaclient/tests/fixture_data/networks.py
Normal file
62
novaclient/tests/fixture_data/networks.py
Normal file
@ -0,0 +1,62 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests.fixture_data import base
|
||||
|
||||
|
||||
class Fixture(base.Fixture):
|
||||
|
||||
base_url = 'os-networks'
|
||||
|
||||
def setUp(self):
|
||||
super(Fixture, self).setUp()
|
||||
|
||||
get_os_networks = {
|
||||
'networks': [
|
||||
{
|
||||
"label": "1",
|
||||
"cidr": "10.0.0.0/24",
|
||||
'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
|
||||
'id': '1'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_networks),
|
||||
content_type='application/json')
|
||||
|
||||
def post_os_networks(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
data = jsonutils.dumps({'network': body})
|
||||
return 202, headers, data
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_os_networks,
|
||||
content_type='application/json')
|
||||
|
||||
get_os_networks_1 = {'network': {"label": "1", "cidr": "10.0.0.0/24"}}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1),
|
||||
body=jsonutils.dumps(get_os_networks_1),
|
||||
content_type='application/json')
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url('networkdelete'),
|
||||
stauts=202)
|
||||
|
||||
for u in ('add', 'networkdisassociate/action', 'networktest/action',
|
||||
'1/action', '2/action'):
|
||||
httpretty.register_uri(httpretty.POST, self.url(u), stauts=202)
|
@ -11,34 +11,35 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from novaclient.tests.fixture_data import client
|
||||
from novaclient.tests.fixture_data import networks as data
|
||||
from novaclient.tests import utils
|
||||
from novaclient.tests.v1_1 import fakes
|
||||
from novaclient.v1_1 import networks
|
||||
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
class NetworksTest(utils.FixturedTestCase):
|
||||
|
||||
|
||||
class NetworksTest(utils.TestCase):
|
||||
client_fixture_class = client.V1
|
||||
data_fixture_class = data.Fixture
|
||||
|
||||
def test_list_networks(self):
|
||||
fl = cs.networks.list()
|
||||
cs.assert_called('GET', '/os-networks')
|
||||
fl = self.cs.networks.list()
|
||||
self.assert_called('GET', '/os-networks')
|
||||
[self.assertIsInstance(f, networks.Network) for f in fl]
|
||||
|
||||
def test_get_network(self):
|
||||
f = cs.networks.get(1)
|
||||
cs.assert_called('GET', '/os-networks/1')
|
||||
f = self.cs.networks.get(1)
|
||||
self.assert_called('GET', '/os-networks/1')
|
||||
self.assertIsInstance(f, networks.Network)
|
||||
|
||||
def test_delete(self):
|
||||
cs.networks.delete('networkdelete')
|
||||
cs.assert_called('DELETE', '/os-networks/networkdelete')
|
||||
self.cs.networks.delete('networkdelete')
|
||||
self.assert_called('DELETE', '/os-networks/networkdelete')
|
||||
|
||||
def test_create(self):
|
||||
f = cs.networks.create(label='foo')
|
||||
cs.assert_called('POST', '/os-networks',
|
||||
{'network': {'label': 'foo'}})
|
||||
f = self.cs.networks.create(label='foo')
|
||||
self.assert_called('POST', '/os-networks',
|
||||
{'network': {'label': 'foo'}})
|
||||
self.assertIsInstance(f, networks.Network)
|
||||
|
||||
def test_create_allparams(self):
|
||||
@ -60,39 +61,39 @@ class NetworksTest(utils.TestCase):
|
||||
'vpn_start': 1
|
||||
}
|
||||
|
||||
f = cs.networks.create(**params)
|
||||
cs.assert_called('POST', '/os-networks', {'network': params})
|
||||
f = self.cs.networks.create(**params)
|
||||
self.assert_called('POST', '/os-networks', {'network': params})
|
||||
self.assertIsInstance(f, networks.Network)
|
||||
|
||||
def test_associate_project(self):
|
||||
cs.networks.associate_project('networktest')
|
||||
cs.assert_called('POST', '/os-networks/add',
|
||||
{'id': 'networktest'})
|
||||
self.cs.networks.associate_project('networktest')
|
||||
self.assert_called('POST', '/os-networks/add',
|
||||
{'id': 'networktest'})
|
||||
|
||||
def test_associate_host(self):
|
||||
cs.networks.associate_host('networktest', 'testHost')
|
||||
cs.assert_called('POST', '/os-networks/networktest/action',
|
||||
{'associate_host': 'testHost'})
|
||||
self.cs.networks.associate_host('networktest', 'testHost')
|
||||
self.assert_called('POST', '/os-networks/networktest/action',
|
||||
{'associate_host': 'testHost'})
|
||||
|
||||
def test_disassociate(self):
|
||||
cs.networks.disassociate('networkdisassociate')
|
||||
cs.assert_called('POST',
|
||||
'/os-networks/networkdisassociate/action',
|
||||
{'disassociate': None})
|
||||
self.cs.networks.disassociate('networkdisassociate')
|
||||
self.assert_called('POST',
|
||||
'/os-networks/networkdisassociate/action',
|
||||
{'disassociate': None})
|
||||
|
||||
def test_disassociate_host_only(self):
|
||||
cs.networks.disassociate('networkdisassociate', True, False)
|
||||
cs.assert_called('POST',
|
||||
'/os-networks/networkdisassociate/action',
|
||||
{'disassociate_host': None})
|
||||
self.cs.networks.disassociate('networkdisassociate', True, False)
|
||||
self.assert_called('POST',
|
||||
'/os-networks/networkdisassociate/action',
|
||||
{'disassociate_host': None})
|
||||
|
||||
def test_disassociate_project(self):
|
||||
cs.networks.disassociate('networkdisassociate', False, True)
|
||||
cs.assert_called('POST',
|
||||
'/os-networks/networkdisassociate/action',
|
||||
{'disassociate_project': None})
|
||||
self.cs.networks.disassociate('networkdisassociate', False, True)
|
||||
self.assert_called('POST',
|
||||
'/os-networks/networkdisassociate/action',
|
||||
{'disassociate_project': None})
|
||||
|
||||
def test_add(self):
|
||||
cs.networks.add('networkadd')
|
||||
cs.assert_called('POST', '/os-networks/add',
|
||||
{'id': 'networkadd'})
|
||||
self.cs.networks.add('networkadd')
|
||||
self.assert_called('POST', '/os-networks/add',
|
||||
{'id': 'networkadd'})
|
||||
|
Loading…
Reference in New Issue
Block a user