Convert to requests-mock
We've had some trouble with httpretty in the past and so are moving to requests-mock. There should be no functionality change in this patch, simply a transition to a newer library. Examples: - Python 2/3 inconsistencies - Breaking compatibility between releases - Incorrect package dependency specifications - Problems with distro packaging around tests - *can* introduce a maintained state between tests. Change-Id: I666a5c7e6747f0c5c2dc96336774fd0fcd3f5907
This commit is contained in:
parent
77991e571b
commit
caf9f799ef
novaclient/tests
fixture_data
agents.pyaggregates.pyavailability_zones.pybase.pycerts.pyclient.pycloudpipe.pyfixedips.pyfloatingips.pyfping.pyhosts.pyhypervisors.pyimages.pykeypairs.pylimits.pynetworks.pyquotas.pysecurity_group_rules.pysecurity_groups.pyserver_groups.pyservers.py
utils.pyv1_1
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -35,9 +32,9 @@ class Fixture(base.Fixture):
|
||||
}
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=jsonutils.dumps(post_os_agents),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_agents,
|
||||
headers=self.json_headers)
|
||||
|
||||
put_os_agents_1 = {
|
||||
"agent": {
|
||||
@ -48,10 +45,10 @@ class Fixture(base.Fixture):
|
||||
}
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url(1),
|
||||
body=jsonutils.dumps(put_os_agents_1),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url(1),
|
||||
json=put_os_agents_1,
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(1),
|
||||
content_type='application/json',
|
||||
status=202)
|
||||
self.requests.register_uri('DELETE', self.url(1),
|
||||
headers=self.json_headers,
|
||||
status_code=202)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -32,21 +29,24 @@ class Fixture(base.Fixture):
|
||||
'availability_zone': 'nova1'},
|
||||
]}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_aggregates),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_aggregates,
|
||||
headers=self.json_headers)
|
||||
|
||||
r = jsonutils.dumps({'aggregate': get_os_aggregates['aggregates'][0]})
|
||||
get_aggregates_1 = {'aggregate': get_os_aggregates['aggregates'][0]}
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(), body=r,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=get_aggregates_1,
|
||||
headers=self.json_headers)
|
||||
|
||||
for agg_id in (1, 2):
|
||||
for method in (httpretty.GET, httpretty.PUT):
|
||||
httpretty.register_uri(method, self.url(agg_id), body=r,
|
||||
content_type='application/json')
|
||||
for method in ('GET', 'PUT'):
|
||||
self.requests.register_uri(method, self.url(agg_id),
|
||||
json=get_aggregates_1,
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(agg_id, 'action'),
|
||||
body=r, content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(agg_id, 'action'),
|
||||
json=get_aggregates_1,
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(1), status=202)
|
||||
self.requests.register_uri('DELETE', self.url(1), status_code=202)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -41,9 +38,10 @@ class V1(base.Fixture):
|
||||
}
|
||||
]
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_availability_zone),
|
||||
content_type='application/json')
|
||||
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_availability_zone,
|
||||
headers=self.json_headers)
|
||||
|
||||
get_os_zone_detail = {
|
||||
self.zone_info_key: [
|
||||
@ -88,9 +86,9 @@ class V1(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('detail'),
|
||||
body=jsonutils.dumps(get_os_zone_detail),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('detail'),
|
||||
json=get_os_zone_detail,
|
||||
headers=self.json_headers)
|
||||
|
||||
|
||||
class V3(V1):
|
||||
|
@ -19,9 +19,11 @@ COMPUTE_URL = 'http://compute.host'
|
||||
class Fixture(fixtures.Fixture):
|
||||
|
||||
base_url = None
|
||||
json_headers = {'Content-Type': 'application/json'}
|
||||
|
||||
def __init__(self, compute_url=COMPUTE_URL):
|
||||
def __init__(self, requests, compute_url=COMPUTE_URL):
|
||||
super(Fixture, self).__init__()
|
||||
self.requests = requests
|
||||
self.compute_url = compute_url
|
||||
|
||||
def url(self, *args, **kwargs):
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -43,9 +40,9 @@ class Fixture(base.Fixture):
|
||||
'data': 'foo'
|
||||
}
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url('root'),
|
||||
body=jsonutils.dumps(get_os_certificate),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('root'),
|
||||
json=get_os_certificate,
|
||||
headers=self.json_headers)
|
||||
|
||||
post_os_certificates = {
|
||||
'certificate': {
|
||||
@ -53,6 +50,6 @@ class Fixture(base.Fixture):
|
||||
'data': 'bar'
|
||||
}
|
||||
}
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=jsonutils.dumps(post_os_certificates),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_certificates,
|
||||
headers=self.json_headers)
|
||||
|
@ -11,11 +11,9 @@
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
import httpretty
|
||||
from keystoneclient.auth.identity import v2
|
||||
from keystoneclient import session
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.v1_1 import client as v1_1client
|
||||
from novaclient.v3 import client as v3client
|
||||
|
||||
@ -25,11 +23,13 @@ COMPUTE_URL = 'http://compute.host'
|
||||
|
||||
class V1(fixtures.Fixture):
|
||||
|
||||
def __init__(self, compute_url=COMPUTE_URL, identity_url=IDENTITY_URL):
|
||||
def __init__(self, requests,
|
||||
compute_url=COMPUTE_URL, identity_url=IDENTITY_URL):
|
||||
super(V1, self).__init__()
|
||||
self.identity_url = identity_url
|
||||
self.compute_url = compute_url
|
||||
self.client = None
|
||||
self.requests = requests
|
||||
|
||||
self.token = {
|
||||
'access': {
|
||||
@ -86,13 +86,12 @@ class V1(fixtures.Fixture):
|
||||
|
||||
def setUp(self):
|
||||
super(V1, self).setUp()
|
||||
httpretty.enable()
|
||||
self.addCleanup(httpretty.disable)
|
||||
|
||||
auth_url = '%s/tokens' % self.identity_url
|
||||
httpretty.register_uri(httpretty.POST, auth_url,
|
||||
body=jsonutils.dumps(self.token),
|
||||
content_type='application/json')
|
||||
headers = {'X-Content-Type': 'application/json'}
|
||||
self.requests.register_uri('POST', auth_url,
|
||||
json=self.token,
|
||||
headers=headers)
|
||||
self.client = self.new_client()
|
||||
|
||||
def new_client(self):
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -24,17 +21,17 @@ class Fixture(base.Fixture):
|
||||
super(Fixture, self).setUp()
|
||||
|
||||
get_os_cloudpipe = {'cloudpipes': [{'project_id': 1}]}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_cloudpipe),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_cloudpipe,
|
||||
headers=self.json_headers)
|
||||
|
||||
instance_id = '9d5824aa-20e6-4b9f-b967-76a699fc51fd'
|
||||
post_os_cloudpipe = {'instance_id': instance_id}
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=jsonutils.dumps(post_os_cloudpipe),
|
||||
content_type='application/json',
|
||||
status=202)
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_cloudpipe,
|
||||
headers=self.json_headers,
|
||||
status_code=202)
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('configure-project'),
|
||||
content_type='application/json',
|
||||
status=202)
|
||||
self.requests.register_uri('PUT', self.url('configure-project'),
|
||||
headers=self.json_headers,
|
||||
status_code=202)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -31,11 +28,12 @@ class Fixture(base.Fixture):
|
||||
'host': 'bar'
|
||||
}
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url('192.168.1.1'),
|
||||
body=jsonutils.dumps(get_os_fixed_ips),
|
||||
content_type='application/json')
|
||||
|
||||
httpretty.register_uri(httpretty.POST,
|
||||
self.url('192.168.1.1', 'action'),
|
||||
content_type='application/json',
|
||||
status=202)
|
||||
self.requests.register_uri('GET', self.url('192.168.1.1'),
|
||||
json=get_os_fixed_ips,
|
||||
headers=self.json_headers)
|
||||
|
||||
self.requests.register_uri('POST',
|
||||
self.url('192.168.1.1', 'action'),
|
||||
headers=self.json_headers,
|
||||
status_code=202)
|
||||
|
@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests import fakes
|
||||
from novaclient.tests.fixture_data import base
|
||||
@ -28,29 +26,28 @@ class FloatingFixture(base.Fixture):
|
||||
{'id': 2, 'fixed_ip': '10.0.0.2', 'ip': '11.0.0.2'}]
|
||||
|
||||
get_os_floating_ips = {'floating_ips': floating_ips}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_floating_ips),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_floating_ips,
|
||||
headers=self.json_headers)
|
||||
|
||||
for ip in floating_ips:
|
||||
get_os_floating_ip = {'floating_ip': ip}
|
||||
httpretty.register_uri(httpretty.GET, self.url(ip['id']),
|
||||
body=jsonutils.dumps(get_os_floating_ip),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(ip['id']),
|
||||
json=get_os_floating_ip,
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(ip['id']),
|
||||
content_type='application/json',
|
||||
status=204)
|
||||
self.requests.register_uri('DELETE', self.url(ip['id']),
|
||||
headers=self.json_headers,
|
||||
status_code=204)
|
||||
|
||||
def post_os_floating_ips(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_os_floating_ips(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
ip = floating_ips[0].copy()
|
||||
ip['pool'] = body.get('pool')
|
||||
ip = jsonutils.dumps({'floating_ip': ip})
|
||||
return 200, headers, ip
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_os_floating_ips,
|
||||
content_type='application/json')
|
||||
return {'floating_ip': ip}
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_floating_ips,
|
||||
headers=self.json_headers)
|
||||
|
||||
|
||||
class DNSFixture(base.Fixture):
|
||||
@ -66,10 +63,10 @@ class DNSFixture(base.Fixture):
|
||||
{'domain': 'example.com'}
|
||||
]
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_floating_ip_dns),
|
||||
content_type='application/json',
|
||||
status=205)
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_floating_ip_dns,
|
||||
headers=self.json_headers,
|
||||
status_code=205)
|
||||
|
||||
get_dns_testdomain_entries_testname = {
|
||||
'dns_entry': {
|
||||
@ -80,31 +77,30 @@ class DNSFixture(base.Fixture):
|
||||
}
|
||||
}
|
||||
url = self.url('testdomain', 'entries', 'testname')
|
||||
body = jsonutils.dumps(get_dns_testdomain_entries_testname)
|
||||
httpretty.register_uri(httpretty.GET, url,
|
||||
body=body,
|
||||
content_type='application/json',
|
||||
status=205)
|
||||
self.requests.register_uri('GET', url,
|
||||
json=get_dns_testdomain_entries_testname,
|
||||
headers=self.json_headers,
|
||||
status_code=205)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url('testdomain'),
|
||||
status=200)
|
||||
self.requests.register_uri('DELETE', self.url('testdomain'))
|
||||
|
||||
url = self.url('testdomain', 'entries', 'testname')
|
||||
httpretty.register_uri(httpretty.DELETE, url, status=200)
|
||||
self.requests.register_uri('DELETE', url)
|
||||
|
||||
def put_dns_testdomain_entries_testname(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def put_dns_testdomain_entries_testname(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
fakes.assert_has_keys(body['dns_entry'],
|
||||
required=['ip', 'dns_type'])
|
||||
return 205, headers, request.body
|
||||
httpretty.register_uri(httpretty.PUT, url,
|
||||
body=put_dns_testdomain_entries_testname,
|
||||
content_type='application/json')
|
||||
context.status_code = 205
|
||||
return request.body
|
||||
self.requests.register_uri('PUT', url,
|
||||
body=put_dns_testdomain_entries_testname,
|
||||
headers=self.json_headers)
|
||||
|
||||
url = self.url('testdomain', 'entries')
|
||||
httpretty.register_uri(httpretty.GET, url, status=404)
|
||||
self.requests.register_uri('GET', url, status_code=404)
|
||||
|
||||
get_os_floating_ip_dns_testdomain_entries = {
|
||||
get_os_floating_ip_dns_testdomain = {
|
||||
'dns_entries': [
|
||||
{
|
||||
'dns_entry': {
|
||||
@ -124,14 +120,13 @@ class DNSFixture(base.Fixture):
|
||||
},
|
||||
]
|
||||
}
|
||||
body = jsonutils.dumps(get_os_floating_ip_dns_testdomain_entries)
|
||||
httpretty.register_uri(httpretty.GET, url + '?ip=1.2.3.4',
|
||||
body=body,
|
||||
status=205,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', url + '?ip=1.2.3.4',
|
||||
json=get_os_floating_ip_dns_testdomain,
|
||||
status_code=205,
|
||||
headers=self.json_headers)
|
||||
|
||||
def put_os_floating_ip_dns_testdomain(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def put_os_floating_ip_dns_testdomain(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
if body['domain_entry']['scope'] == 'private':
|
||||
fakes.assert_has_keys(body['domain_entry'],
|
||||
required=['availability_zone', 'scope'])
|
||||
@ -142,11 +137,12 @@ class DNSFixture(base.Fixture):
|
||||
fakes.assert_has_keys(body['domain_entry'],
|
||||
required=['project', 'scope'])
|
||||
|
||||
headers['Content-Type'] = 'application/json'
|
||||
return (205, headers, request.body)
|
||||
return request.body
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('testdomain'),
|
||||
body=put_os_floating_ip_dns_testdomain)
|
||||
self.requests.register_uri('PUT', self.url('testdomain'),
|
||||
body=put_os_floating_ip_dns_testdomain,
|
||||
status_code=205,
|
||||
headers=self.json_headers)
|
||||
|
||||
|
||||
class BulkFixture(base.Fixture):
|
||||
@ -162,40 +158,38 @@ class BulkFixture(base.Fixture):
|
||||
{'id': 2, 'fixed_ip': '10.0.0.2', 'ip': '11.0.0.2'},
|
||||
]
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_floating_ips_bulk),
|
||||
content_type='application/json')
|
||||
httpretty.register_uri(httpretty.GET, self.url('testHost'),
|
||||
body=jsonutils.dumps(get_os_floating_ips_bulk),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_floating_ips_bulk,
|
||||
headers=self.json_headers)
|
||||
self.requests.register_uri('GET', self.url('testHost'),
|
||||
json=get_os_floating_ips_bulk,
|
||||
headers=self.json_headers)
|
||||
|
||||
def put_os_floating_ips_bulk_delete(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def put_os_floating_ips_bulk_delete(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
ip_range = body.get('ip_range')
|
||||
data = {'floating_ips_bulk_delete': ip_range}
|
||||
return 200, headers, jsonutils.dumps(data)
|
||||
return {'floating_ips_bulk_delete': ip_range}
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('delete'),
|
||||
body=put_os_floating_ips_bulk_delete,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url('delete'),
|
||||
json=put_os_floating_ips_bulk_delete,
|
||||
headers=self.json_headers)
|
||||
|
||||
def post_os_floating_ips_bulk(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_os_floating_ips_bulk(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
params = body.get('floating_ips_bulk_create')
|
||||
pool = params.get('pool', 'defaultPool')
|
||||
interface = params.get('interface', 'defaultInterface')
|
||||
data = {
|
||||
return {
|
||||
'floating_ips_bulk_create': {
|
||||
'ip_range': '192.168.1.0/30',
|
||||
'pool': pool,
|
||||
'interface': interface
|
||||
}
|
||||
}
|
||||
return 200, headers, jsonutils.dumps(data)
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_os_floating_ips_bulk,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_floating_ips_bulk,
|
||||
headers=self.json_headers)
|
||||
|
||||
|
||||
class PoolsFixture(base.Fixture):
|
||||
@ -211,6 +205,6 @@ class PoolsFixture(base.Fixture):
|
||||
{'name': 'bar'}
|
||||
]
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_floating_ip_pools),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_floating_ip_pools,
|
||||
headers=self.json_headers)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -30,9 +27,9 @@ class Fixture(base.Fixture):
|
||||
"alive": True,
|
||||
}
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url(1),
|
||||
body=jsonutils.dumps(get_os_fping_1),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1),
|
||||
json=get_os_fping_1,
|
||||
headers=self.json_headers)
|
||||
|
||||
get_os_fping = {
|
||||
'servers': [
|
||||
@ -44,6 +41,6 @@ class Fixture(base.Fixture):
|
||||
},
|
||||
]
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_fping),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_fping,
|
||||
headers=self.json_headers)
|
||||
|
@ -10,7 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
@ -36,12 +35,15 @@ class BaseFixture(base.Fixture):
|
||||
'cpu': 1, 'memory_mb': 2048, 'disk_gb': 30}}
|
||||
]
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url('host'),
|
||||
body=jsonutils.dumps(get_os_hosts_host),
|
||||
content_type='application/json')
|
||||
|
||||
def get_os_hosts(request, url, headers):
|
||||
host, query = parse.splitquery(url)
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
self.requests.register_uri('GET', self.url('host'),
|
||||
json=get_os_hosts_host,
|
||||
headers=headers)
|
||||
|
||||
def get_os_hosts(request, context):
|
||||
host, query = parse.splitquery(request.url)
|
||||
zone = 'nova1'
|
||||
|
||||
if query:
|
||||
@ -51,7 +53,7 @@ class BaseFixture(base.Fixture):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
data = {
|
||||
return {
|
||||
'hosts': [
|
||||
{
|
||||
'host': 'host1',
|
||||
@ -65,56 +67,52 @@ class BaseFixture(base.Fixture):
|
||||
}
|
||||
]
|
||||
}
|
||||
return 200, headers, jsonutils.dumps(data)
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=get_os_hosts,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_hosts,
|
||||
headers=headers)
|
||||
|
||||
get_os_hosts_sample_host = {
|
||||
'host': [
|
||||
{'resource': {'host': 'sample_host'}}
|
||||
],
|
||||
}
|
||||
httpretty.register_uri(httpretty.GET, self.url('sample_host'),
|
||||
body=jsonutils.dumps(get_os_hosts_sample_host),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('sample_host'),
|
||||
json=get_os_hosts_sample_host,
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('sample_host', 1),
|
||||
body=jsonutils.dumps(self.put_host_1()),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url('sample_host', 1),
|
||||
json=self.put_host_1(),
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('sample_host', 2),
|
||||
body=jsonutils.dumps(self.put_host_2()),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url('sample_host', 2),
|
||||
json=self.put_host_2(),
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('sample_host', 3),
|
||||
body=jsonutils.dumps(self.put_host_3()),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url('sample_host', 3),
|
||||
json=self.put_host_3(),
|
||||
headers=headers)
|
||||
|
||||
url = self.url('sample_host', 'reboot')
|
||||
httpretty.register_uri(httpretty.GET, url,
|
||||
body=jsonutils.dumps(self.get_host_reboot()),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('sample_host', 'reboot'),
|
||||
json=self.get_host_reboot(),
|
||||
headers=headers)
|
||||
|
||||
url = self.url('sample_host', 'startup')
|
||||
httpretty.register_uri(httpretty.GET, url,
|
||||
body=jsonutils.dumps(self.get_host_startup()),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('sample_host', 'startup'),
|
||||
json=self.get_host_startup(),
|
||||
headers=headers)
|
||||
|
||||
url = self.url('sample_host', 'shutdown')
|
||||
httpretty.register_uri(httpretty.GET, url,
|
||||
body=jsonutils.dumps(self.get_host_shutdown()),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('sample_host', 'shutdown'),
|
||||
json=self.get_host_shutdown(),
|
||||
headers=headers)
|
||||
|
||||
def put_os_hosts_sample_host(request, url, headers):
|
||||
def put_os_hosts_sample_host(request, context):
|
||||
result = {'host': 'dummy'}
|
||||
result.update(jsonutils.loads(request.body.decode('utf-8')))
|
||||
return 200, headers, jsonutils.dumps(result)
|
||||
result.update(jsonutils.loads(request.body))
|
||||
return result
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url('sample_host'),
|
||||
body=put_os_hosts_sample_host,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url('sample_host'),
|
||||
json=put_os_hosts_sample_host,
|
||||
headers=headers)
|
||||
|
||||
|
||||
class V1(BaseFixture):
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -30,9 +27,11 @@ class V1(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_hypervisors),
|
||||
content_type='application/json')
|
||||
self.headers = {'Content-Type': 'application/json'}
|
||||
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_hypervisors,
|
||||
headers=self.headers)
|
||||
|
||||
get_os_hypervisors_detail = {
|
||||
'hypervisors': [
|
||||
@ -83,9 +82,9 @@ class V1(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('detail'),
|
||||
body=jsonutils.dumps(get_os_hypervisors_detail),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('detail'),
|
||||
json=get_os_hypervisors_detail,
|
||||
headers=self.headers)
|
||||
|
||||
get_os_hypervisors_stats = {
|
||||
'hypervisor_statistics': {
|
||||
@ -104,9 +103,9 @@ class V1(base.Fixture):
|
||||
}
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('statistics'),
|
||||
body=jsonutils.dumps(get_os_hypervisors_stats),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('statistics'),
|
||||
json=get_os_hypervisors_stats,
|
||||
headers=self.headers)
|
||||
|
||||
get_os_hypervisors_search = {
|
||||
'hypervisors': [
|
||||
@ -115,9 +114,9 @@ class V1(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('hyper', 'search'),
|
||||
body=jsonutils.dumps(get_os_hypervisors_search),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('hyper', 'search'),
|
||||
json=get_os_hypervisors_search,
|
||||
headers=self.headers)
|
||||
|
||||
get_hyper_server = {
|
||||
'hypervisors': [
|
||||
@ -140,9 +139,9 @@ class V1(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('hyper', 'servers'),
|
||||
body=jsonutils.dumps(get_hyper_server),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('hyper', 'servers'),
|
||||
json=get_hyper_server,
|
||||
headers=self.headers)
|
||||
|
||||
get_os_hypervisors_1234 = {
|
||||
'hypervisor': {
|
||||
@ -166,9 +165,9 @@ class V1(base.Fixture):
|
||||
}
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1234),
|
||||
body=jsonutils.dumps(get_os_hypervisors_1234),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1234),
|
||||
json=get_os_hypervisors_1234,
|
||||
headers=self.headers)
|
||||
|
||||
get_os_hypervisors_uptime = {
|
||||
'hypervisor': {
|
||||
@ -178,9 +177,9 @@ class V1(base.Fixture):
|
||||
}
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1234, 'uptime'),
|
||||
body=jsonutils.dumps(get_os_hypervisors_uptime),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1234, 'uptime'),
|
||||
json=get_os_hypervisors_uptime,
|
||||
headers=self.headers)
|
||||
|
||||
|
||||
class V3(V1):
|
||||
@ -195,10 +194,10 @@ class V3(V1):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url('search', query='hyper'),
|
||||
body=jsonutils.dumps(get_os_hypervisors_search),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET',
|
||||
self.url('search', query='hyper'),
|
||||
json=get_os_hypervisors_search,
|
||||
headers=self.headers)
|
||||
|
||||
get_1234_servers = {
|
||||
'hypervisor': {
|
||||
@ -211,6 +210,6 @@ class V3(V1):
|
||||
},
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1234, 'servers'),
|
||||
body=jsonutils.dumps(get_1234_servers),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1234, 'servers'),
|
||||
json=get_1234_servers,
|
||||
headers=self.headers)
|
||||
|
@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests import fakes
|
||||
from novaclient.tests.fixture_data import base
|
||||
@ -31,9 +29,11 @@ class V1(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_images),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_images,
|
||||
headers=headers)
|
||||
|
||||
image_1 = {
|
||||
'id': 1,
|
||||
@ -58,60 +58,53 @@ class V1(base.Fixture):
|
||||
"links": {},
|
||||
}
|
||||
|
||||
get_images_detail = {'images': [image_1, image_2]}
|
||||
self.requests.register_uri('GET', self.url('detail'),
|
||||
json={'images': [image_1, image_2]},
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('detail'),
|
||||
body=jsonutils.dumps(get_images_detail),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1),
|
||||
json={'image': image_1},
|
||||
headers=headers)
|
||||
|
||||
get_images_1 = {'image': image_1}
|
||||
self.requests.register_uri('GET', self.url(2),
|
||||
json={'image': image_2},
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1),
|
||||
body=jsonutils.dumps(get_images_1),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(456),
|
||||
json={'image': image_2},
|
||||
headers=headers)
|
||||
|
||||
get_images_2 = {'image': image_2}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(2),
|
||||
body=jsonutils.dumps(get_images_2),
|
||||
content_type='application/json')
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(456),
|
||||
body=jsonutils.dumps(get_images_2),
|
||||
content_type='application/json')
|
||||
|
||||
def post_images(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_images(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['image']
|
||||
fakes.assert_has_keys(body['image'], required=['serverId', 'name'])
|
||||
return 202, headers, jsonutils.dumps(images_1)
|
||||
return images_1
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_images,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_images,
|
||||
headers=headers,
|
||||
status_code=202)
|
||||
|
||||
def post_images_1_metadata(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_images_1_metadata(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['metadata']
|
||||
fakes.assert_has_keys(body['metadata'], required=['test_key'])
|
||||
data = jsonutils.dumps({'metadata': image_1['metadata']})
|
||||
return 200, headers, data
|
||||
return {'metadata': image_1['metadata']}
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(1, 'metadata'),
|
||||
body=post_images_1_metadata,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(1, 'metadata'),
|
||||
json=post_images_1_metadata,
|
||||
headers=headers)
|
||||
|
||||
for u in (1, 2, '1/metadata/test_key'):
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(u),
|
||||
status=204)
|
||||
self.requests.register_uri('DELETE', self.url(u), status_code=204)
|
||||
|
||||
httpretty.register_uri(httpretty.HEAD, self.url(1), status=200,
|
||||
x_image_meta_id=1,
|
||||
x_image_meta_name='CentOS 5.2',
|
||||
x_image_meta_updated='2010-10-10T12:00:00Z',
|
||||
x_image_meta_created='2010-10-10T12:00:00Z',
|
||||
x_image_meta_status='ACTIVE',
|
||||
x_image_meta_property_test_key='test_value')
|
||||
image_headers = {'x-image-meta-id': '1',
|
||||
'x-image-meta-name': 'CentOS 5.2',
|
||||
'x-image-meta-updated': '2010-10-10T12:00:00Z',
|
||||
'x-image-meta-created': '2010-10-10T12:00:00Z',
|
||||
'x-image-meta-status': 'ACTIVE',
|
||||
'x-image-meta-property-test-key': 'test_value'}
|
||||
self.requests.register_uri('HEAD', self.url(1), headers=image_headers)
|
||||
|
||||
|
||||
class V3(V1):
|
||||
|
@ -10,9 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests import fakes
|
||||
from novaclient.tests.fixture_data import base
|
||||
@ -26,25 +23,27 @@ class V1(base.Fixture):
|
||||
super(V1, self).setUp()
|
||||
keypair = {'fingerprint': 'FAKE_KEYPAIR', 'name': 'test'}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps({'keypairs': [keypair]}),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('test'),
|
||||
body=jsonutils.dumps({'keypair': keypair}),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json={'keypairs': [keypair]},
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url('test'), status=202)
|
||||
self.requests.register_uri('GET', self.url('test'),
|
||||
json={'keypair': keypair},
|
||||
headers=headers)
|
||||
|
||||
def post_os_keypairs(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
self.requests.register_uri('DELETE', self.url('test'), status_code=202)
|
||||
|
||||
def post_os_keypairs(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['keypair']
|
||||
fakes.assert_has_keys(body['keypair'], required=['name'])
|
||||
return 202, headers, jsonutils.dumps({'keypair': keypair})
|
||||
return {'keypair': keypair}
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_os_keypairs,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_keypairs,
|
||||
headers=headers)
|
||||
|
||||
|
||||
class V3(V1):
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -77,6 +74,7 @@ class Fixture(base.Fixture):
|
||||
},
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_limits),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_limits,
|
||||
headers=headers)
|
||||
|
@ -10,8 +10,6 @@
|
||||
# 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
|
||||
|
||||
@ -34,29 +32,30 @@ class Fixture(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_networks),
|
||||
content_type='application/json')
|
||||
headers = {'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
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_os_networks,
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_os_networks,
|
||||
content_type='application/json')
|
||||
def post_os_networks(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
return {'network': body}
|
||||
|
||||
self.requests.register_uri("POST", self.url(),
|
||||
json=post_os_networks,
|
||||
headers=headers)
|
||||
|
||||
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')
|
||||
self.requests.register_uri('GET', self.url(1),
|
||||
json=get_os_networks_1,
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url('networkdelete'),
|
||||
stauts=202)
|
||||
self.requests.register_uri('DELETE',
|
||||
self.url('networkdelete'),
|
||||
status_code=202)
|
||||
|
||||
for u in ('add', 'networkdisassociate/action', 'networktest/action',
|
||||
'1/action', '2/action'):
|
||||
httpretty.register_uri(httpretty.POST, self.url(u), stauts=202)
|
||||
self.requests.register_uri('POST', self.url(u), status_code=202)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
|
||||
@ -25,32 +22,32 @@ class V1(base.Fixture):
|
||||
|
||||
uuid = '97f4c221-bff4-4578-b030-0df4ef119353'
|
||||
uuid2 = '97f4c221bff44578b0300df4ef119353'
|
||||
test_json = jsonutils.dumps({'quota_set': self.test_quota('test')})
|
||||
test_json = {'quota_set': self.test_quota('test')}
|
||||
self.headers = {'Content-Type': 'application/json'}
|
||||
|
||||
for u in ('test', 'tenant-id', 'tenant-id/defaults',
|
||||
'%s/defaults' % uuid2):
|
||||
httpretty.register_uri(httpretty.GET, self.url(u),
|
||||
body=test_json,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(u),
|
||||
json=test_json,
|
||||
headers=self.headers)
|
||||
|
||||
quota_json = jsonutils.dumps({'quota_set': self.test_quota(uuid)})
|
||||
httpretty.register_uri(httpretty.PUT, self.url(uuid),
|
||||
body=quota_json,
|
||||
content_type='application/json')
|
||||
httpretty.register_uri(httpretty.GET, self.url(uuid),
|
||||
body=quota_json,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url(uuid),
|
||||
json={'quota_set': self.test_quota(uuid)},
|
||||
headers=self.headers)
|
||||
|
||||
quota_json2 = jsonutils.dumps({'quota_set': self.test_quota(uuid2)})
|
||||
httpretty.register_uri(httpretty.PUT, self.url(uuid2),
|
||||
body=quota_json2,
|
||||
content_type='application/json')
|
||||
httpretty.register_uri(httpretty.GET, self.url(uuid2),
|
||||
body=quota_json2,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(uuid),
|
||||
json={'quota_set': self.test_quota(uuid)},
|
||||
headers=self.headers)
|
||||
|
||||
self.requests.register_uri('PUT', self.url(uuid2),
|
||||
json={'quota_set': self.test_quota(uuid2)},
|
||||
headers=self.headers)
|
||||
self.requests.register_uri('GET', self.url(uuid2),
|
||||
json={'quota_set': self.test_quota(uuid2)},
|
||||
headers=self.headers)
|
||||
|
||||
for u in ('test', uuid2):
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(u), status=202)
|
||||
self.requests.register_uri('DELETE', self.url(u), status_code=202)
|
||||
|
||||
def test_quota(self, tenant_id='test'):
|
||||
return {
|
||||
@ -82,6 +79,6 @@ class V3(V1):
|
||||
}
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('test', 'detail'),
|
||||
body=jsonutils.dumps(get_detail),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('test', 'detail'),
|
||||
json=get_detail,
|
||||
headers=self.headers)
|
||||
|
@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests import fakes
|
||||
from novaclient.tests.fixture_data import base
|
||||
@ -34,24 +32,26 @@ class Fixture(base.Fixture):
|
||||
'cidr': '10.0.0.0/8'
|
||||
}
|
||||
|
||||
get_rules = {'security_group_rules': [rule]}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_rules),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json={'security_group_rules': [rule]},
|
||||
headers=headers)
|
||||
|
||||
for u in (1, 11, 12):
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(u), status=202)
|
||||
self.requests.register_uri('DELETE', self.url(u), status_code=202)
|
||||
|
||||
def post_rules(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_rules(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['security_group_rule']
|
||||
fakes.assert_has_keys(body['security_group_rule'],
|
||||
required=['parent_group_id'],
|
||||
optional=['group_id', 'ip_protocol',
|
||||
'from_port', 'to_port', 'cidr'])
|
||||
|
||||
return 202, headers, jsonutils.dumps({'security_group_rule': rule})
|
||||
return {'security_group_rule': rule}
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_rules,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_rules,
|
||||
headers=headers,
|
||||
status_code=202)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests import fakes
|
||||
from novaclient.tests.fixture_data import base
|
||||
@ -64,36 +61,39 @@ class Fixture(base.Fixture):
|
||||
}
|
||||
|
||||
get_groups = {'security_groups': [security_group_1, security_group_2]}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_groups),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_groups,
|
||||
headers=headers)
|
||||
|
||||
get_group_1 = {'security_group': security_group_1}
|
||||
httpretty.register_uri(httpretty.GET, self.url(1),
|
||||
body=jsonutils.dumps(get_group_1),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1),
|
||||
json=get_group_1,
|
||||
headers=headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(1), status=202)
|
||||
self.requests.register_uri('DELETE', self.url(1), status_code=202)
|
||||
|
||||
def post_os_security_groups(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_os_security_groups(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['security_group']
|
||||
fakes.assert_has_keys(body['security_group'],
|
||||
required=['name', 'description'])
|
||||
r = jsonutils.dumps({'security_group': security_group_1})
|
||||
return 202, headers, r
|
||||
return {'security_group': security_group_1}
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=post_os_security_groups,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=post_os_security_groups,
|
||||
headers=headers,
|
||||
status_code=202)
|
||||
|
||||
def put_os_security_groups_1(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def put_os_security_groups_1(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['security_group']
|
||||
fakes.assert_has_keys(body['security_group'],
|
||||
required=['name', 'description'])
|
||||
return 205, headers, request.body
|
||||
return body
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url(1),
|
||||
body=put_os_security_groups_1,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url(1),
|
||||
json=put_os_security_groups_1,
|
||||
headers=headers,
|
||||
status_code=205)
|
||||
|
@ -10,9 +10,6 @@
|
||||
# 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
|
||||
|
||||
@ -54,22 +51,23 @@ class Fixture(base.Fixture):
|
||||
}
|
||||
]
|
||||
|
||||
get_server_groups = {'server_groups': server_groups}
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_server_groups),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json={'server_groups': server_groups},
|
||||
headers=headers)
|
||||
|
||||
server = server_groups[0]
|
||||
server_json = jsonutils.dumps({'server_group': server})
|
||||
server_j = jsonutils.dumps({'server_group': server})
|
||||
|
||||
def _register(method, *args):
|
||||
httpretty.register_uri(method, self.url(*args), body=server_json)
|
||||
self.requests.register_uri(method, self.url(*args), text=server_j)
|
||||
|
||||
_register(httpretty.POST)
|
||||
_register(httpretty.POST, server['id'])
|
||||
_register(httpretty.GET, server['id'])
|
||||
_register(httpretty.PUT, server['id'])
|
||||
_register(httpretty.POST, server['id'], '/action')
|
||||
_register('POST')
|
||||
_register('POST', server['id'])
|
||||
_register('GET', server['id'])
|
||||
_register('PUT', server['id'])
|
||||
_register('POST', server['id'], '/action')
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(server['id']),
|
||||
status=202)
|
||||
self.requests.register_uri('DELETE', self.url(server['id']),
|
||||
status_code=202)
|
||||
|
@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests import fakes
|
||||
from novaclient.tests.fixture_data import base
|
||||
@ -31,9 +29,9 @@ class Base(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_servers),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(),
|
||||
json=get_servers,
|
||||
headers=self.json_headers)
|
||||
|
||||
self.server_1234 = {
|
||||
"id": 1234,
|
||||
@ -151,48 +149,47 @@ class Base(base.Fixture):
|
||||
servers = [self.server_1234, self.server_5678, self.server_9012]
|
||||
get_servers_detail = {"servers": servers}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url('detail'),
|
||||
body=jsonutils.dumps(get_servers_detail),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url('detail'),
|
||||
json=get_servers_detail,
|
||||
headers=self.json_headers)
|
||||
|
||||
self.server_1235 = self.server_1234.copy()
|
||||
self.server_1235['id'] = 1235
|
||||
self.server_1235['status'] = 'error'
|
||||
self.server_1235['fault'] = {'message': 'something went wrong!'}
|
||||
servers.append(self.server_1235)
|
||||
|
||||
for s in servers:
|
||||
httpretty.register_uri(httpretty.GET, self.url(s['id']),
|
||||
body=jsonutils.dumps({'server': s}),
|
||||
content_type='application/json')
|
||||
for s in servers + [self.server_1235]:
|
||||
self.requests.register_uri('GET', self.url(s['id']),
|
||||
json={'server': s},
|
||||
headers=self.json_headers)
|
||||
|
||||
for s in (1234, 5678):
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(s), status=202)
|
||||
self.requests.register_uri('DELETE', self.url(s), status_code=202)
|
||||
|
||||
for k in ('test_key', 'key1', 'key2'):
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url(1234, 'metadata', k),
|
||||
status=204)
|
||||
self.requests.register_uri('DELETE',
|
||||
self.url(1234, 'metadata', k),
|
||||
status_code=204)
|
||||
|
||||
metadata1 = jsonutils.dumps({'metadata': {'test_key': 'test_value'}})
|
||||
httpretty.register_uri(httpretty.POST, self.url(1234, 'metadata'),
|
||||
body=metadata1, status=200,
|
||||
content_type='application/json')
|
||||
httpretty.register_uri(httpretty.PUT,
|
||||
self.url(1234, 'metadata', 'test_key'),
|
||||
body=metadata1, status=200,
|
||||
content_type='application/json')
|
||||
metadata1 = {'metadata': {'test_key': 'test_value'}}
|
||||
self.requests.register_uri('POST', self.url(1234, 'metadata'),
|
||||
json=metadata1,
|
||||
headers=self.json_headers)
|
||||
self.requests.register_uri('PUT',
|
||||
self.url(1234, 'metadata', 'test_key'),
|
||||
json=metadata1,
|
||||
headers=self.json_headers)
|
||||
|
||||
self.diagnostic = jsonutils.dumps({'data': 'Fake diagnostics'})
|
||||
self.diagnostic = {'data': 'Fake diagnostics'}
|
||||
|
||||
metadata2 = jsonutils.dumps({'metadata': {'key1': 'val1'}})
|
||||
metadata2 = {'metadata': {'key1': 'val1'}}
|
||||
for u in ('uuid1', 'uuid2', 'uuid3', 'uuid4'):
|
||||
httpretty.register_uri(httpretty.POST, self.url(u, 'metadata'),
|
||||
body=metadata2, status=204)
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url(u, 'metadata', 'key1'),
|
||||
body=self.diagnostic,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(u, 'metadata'),
|
||||
json=metadata2, status_code=204)
|
||||
self.requests.register_uri('DELETE',
|
||||
self.url(u, 'metadata', 'key1'),
|
||||
json=self.diagnostic,
|
||||
headers=self.json_headers)
|
||||
|
||||
get_security_groups = {
|
||||
"security_groups": [{
|
||||
@ -203,18 +200,17 @@ class Base(base.Fixture):
|
||||
'rules': []}]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url('1234', 'os-security-groups'),
|
||||
body=jsonutils.dumps(get_security_groups),
|
||||
status=200)
|
||||
self.requests.register_uri('GET',
|
||||
self.url('1234', 'os-security-groups'),
|
||||
json=get_security_groups)
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(),
|
||||
body=self.post_servers,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url(),
|
||||
json=self.post_servers,
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url('1234', 'action'),
|
||||
body=self.post_servers_1234_action,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url('1234', 'action'),
|
||||
json=self.post_servers_1234_action,
|
||||
headers=self.json_headers)
|
||||
|
||||
get_os_interface = {
|
||||
"interfaceAttachments": [
|
||||
@ -235,30 +231,31 @@ class Base(base.Fixture):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url('1234', 'os-interface'),
|
||||
body=jsonutils.dumps(get_os_interface),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET',
|
||||
self.url('1234', 'os-interface'),
|
||||
json=get_os_interface,
|
||||
headers=self.json_headers)
|
||||
|
||||
interface_data = {'interfaceAttachment': {}}
|
||||
httpretty.register_uri(httpretty.POST,
|
||||
self.url('1234', 'os-interface'),
|
||||
body=jsonutils.dumps(interface_data),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST',
|
||||
self.url('1234', 'os-interface'),
|
||||
json=interface_data,
|
||||
headers=self.json_headers)
|
||||
|
||||
def put_servers_1234(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def put_servers_1234(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert list(body) == ['server']
|
||||
fakes.assert_has_keys(body['server'],
|
||||
optional=['name', 'adminPass'])
|
||||
return 204, headers, request.body
|
||||
return request.body
|
||||
|
||||
httpretty.register_uri(httpretty.PUT, self.url(1234),
|
||||
body=put_servers_1234,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('PUT', self.url(1234),
|
||||
body=put_servers_1234,
|
||||
status_code=204,
|
||||
headers=self.json_headers)
|
||||
|
||||
def post_os_volumes_boot(request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_os_volumes_boot(request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert (set(body.keys()) <=
|
||||
set(['server', 'os:scheduler_hints']))
|
||||
|
||||
@ -277,23 +274,24 @@ class Base(base.Fixture):
|
||||
msg = "found extra keys: 'block_device_mapping'"
|
||||
raise AssertionError(msg)
|
||||
|
||||
return 202, headers, jsonutils.dumps({'server': self.server_9012})
|
||||
return {'server': self.server_9012}
|
||||
|
||||
# NOTE(jamielennox): hack to make os_volumes mock go to the right place
|
||||
base_url = self.base_url
|
||||
self.base_url = None
|
||||
httpretty.register_uri(httpretty.POST, self.url('os-volumes_boot'),
|
||||
body=post_os_volumes_boot,
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST', self.url('os-volumes_boot'),
|
||||
json=post_os_volumes_boot,
|
||||
status_code=202,
|
||||
headers=self.json_headers)
|
||||
self.base_url = base_url
|
||||
|
||||
#
|
||||
# Server password
|
||||
#
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url(1234, 'os-server-password'),
|
||||
status=202)
|
||||
self.requests.register_uri('DELETE',
|
||||
self.url(1234, 'os-server-password'),
|
||||
status_code=202)
|
||||
|
||||
|
||||
class V1(Base):
|
||||
@ -306,29 +304,28 @@ class V1(Base):
|
||||
#
|
||||
|
||||
add = self.server_1234['addresses']
|
||||
httpretty.register_uri(httpretty.GET, self.url(1234, 'ips'),
|
||||
jsonutils.dumps({'addresses': add}),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1234, 'ips'),
|
||||
json={'addresses': add},
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1234, 'ips', 'public'),
|
||||
jsonutils.dumps({'public': add['public']}),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1234, 'ips', 'public'),
|
||||
json={'public': add['public']},
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(1234, 'ips', 'private'),
|
||||
jsonutils.dumps({'private': add['private']}),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET', self.url(1234, 'ips', 'private'),
|
||||
json={'private': add['private']},
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url(1234, 'ips', 'public', '1.2.3.4'),
|
||||
status=202)
|
||||
self.requests.register_uri('DELETE',
|
||||
self.url(1234, 'ips', 'public', '1.2.3.4'),
|
||||
status_code=202)
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url('1234', 'diagnostics'),
|
||||
body=self.diagnostic,
|
||||
status=200)
|
||||
self.requests.register_uri('GET',
|
||||
self.url('1234', 'diagnostics'),
|
||||
json=self.diagnostic)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url('1234', 'os-interface', 'port-id'))
|
||||
self.requests.register_uri('DELETE',
|
||||
self.url('1234', 'os-interface', 'port-id'))
|
||||
|
||||
# Testing with the following password and key
|
||||
#
|
||||
@ -351,12 +348,13 @@ class V1(Base):
|
||||
'/y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N'
|
||||
'tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk'
|
||||
'Hi/fmZZNQQqj1Ijq0caOIw=='}
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url(1234, 'os-server-password'),
|
||||
jsonutils.dumps(get_server_password))
|
||||
self.requests.register_uri('GET',
|
||||
self.url(1234, 'os-server-password'),
|
||||
json=get_server_password)
|
||||
|
||||
def post_servers(self, request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_servers(self, request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
context.status_code = 202
|
||||
assert (set(body.keys()) <=
|
||||
set(['server', 'os:scheduler_hints']))
|
||||
fakes.assert_has_keys(body['server'],
|
||||
@ -370,12 +368,12 @@ class V1(Base):
|
||||
else:
|
||||
body = self.server_1234
|
||||
|
||||
return 202, headers, jsonutils.dumps({'server': body})
|
||||
return {'server': body}
|
||||
|
||||
def post_servers_1234_action(self, request, url, headers):
|
||||
def post_servers_1234_action(self, request, context):
|
||||
_body = ''
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
resp = 202
|
||||
body = jsonutils.loads(request.body)
|
||||
context.status_code = 202
|
||||
assert len(body.keys()) == 1
|
||||
action = list(body)[0]
|
||||
if action == 'reboot':
|
||||
@ -393,7 +391,8 @@ class V1(Base):
|
||||
elif action == 'confirmResize':
|
||||
assert body[action] is None
|
||||
# This one method returns a different response code
|
||||
return 204, headers, ''
|
||||
context.status_code = 204
|
||||
return None
|
||||
elif action == 'revertResize':
|
||||
assert body[action] is None
|
||||
elif action == 'migrate':
|
||||
@ -445,12 +444,13 @@ class V1(Base):
|
||||
assert list(body[action]) == ['address']
|
||||
elif action == 'createImage':
|
||||
assert set(body[action].keys()) == set(['name', 'metadata'])
|
||||
headers['location'] = "http://blah/images/456"
|
||||
context.headers['location'] = "http://blah/images/456"
|
||||
elif action == 'changePassword':
|
||||
assert list(body[action]) == ['adminPass']
|
||||
elif action == 'os-getConsoleOutput':
|
||||
assert list(body[action]) == ['length']
|
||||
return 202, headers, jsonutils.dumps({'output': 'foo'})
|
||||
context.status_code = 202
|
||||
return {'output': 'foo'}
|
||||
elif action == 'os-getVNCConsole':
|
||||
assert list(body[action]) == ['type']
|
||||
elif action == 'os-getSPICEConsole':
|
||||
@ -480,7 +480,7 @@ class V1(Base):
|
||||
assert set(keys) == set(['host', 'onSharedStorage'])
|
||||
else:
|
||||
raise AssertionError("Unexpected server action: %s" % action)
|
||||
return resp, headers, jsonutils.dumps({'server': _body})
|
||||
return {'server': _body}
|
||||
|
||||
|
||||
class V3(Base):
|
||||
@ -507,32 +507,30 @@ class V3(Base):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url('1234', 'os-attach-interfaces'),
|
||||
body=jsonutils.dumps(get_interfaces),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('GET',
|
||||
self.url('1234', 'os-attach-interfaces'),
|
||||
json=get_interfaces,
|
||||
headers=self.json_headers)
|
||||
|
||||
attach_body = {'interface_attachment': {}}
|
||||
httpretty.register_uri(httpretty.POST,
|
||||
self.url('1234', 'os-attach-interfaces'),
|
||||
body=jsonutils.dumps(attach_body),
|
||||
content_type='application/json')
|
||||
self.requests.register_uri('POST',
|
||||
self.url('1234', 'os-attach-interfaces'),
|
||||
json=attach_body,
|
||||
headers=self.json_headers)
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url('1234', 'os-server-diagnostics'),
|
||||
body=self.diagnostic,
|
||||
status=200)
|
||||
self.requests.register_uri('GET',
|
||||
self.url('1234', 'os-server-diagnostics'),
|
||||
json=self.diagnostic)
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE,
|
||||
self.url('1234', 'os-attach-interfaces',
|
||||
'port-id'))
|
||||
url = self.url('1234', 'os-attach-interfaces', 'port-id')
|
||||
self.requests.register_uri('DELETE', url)
|
||||
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
self.url(1234, 'os-server-password'),
|
||||
jsonutils.dumps({'password': ''}))
|
||||
self.requests.register_uri('GET',
|
||||
self.url(1234, 'os-server-password'),
|
||||
json={'password': ''})
|
||||
|
||||
def post_servers(self, request, url, headers):
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
def post_servers(self, request, context):
|
||||
body = jsonutils.loads(request.body)
|
||||
assert set(body.keys()) <= set(['server'])
|
||||
fakes.assert_has_keys(body['server'],
|
||||
required=['name', 'image_ref', 'flavor_ref'],
|
||||
@ -543,10 +541,11 @@ class V3(Base):
|
||||
else:
|
||||
body = self.server_1234
|
||||
|
||||
return 202, headers, jsonutils.dumps({'server': body})
|
||||
context.status_code = 202
|
||||
return {'server': body}
|
||||
|
||||
def post_servers_1234_action(self, request, url, headers):
|
||||
resp = 202
|
||||
def post_servers_1234_action(self, request, context):
|
||||
context.status_code = 202
|
||||
body_is_none_list = [
|
||||
'revert_resize', 'migrate', 'stop', 'start', 'force_delete',
|
||||
'restore', 'pause', 'unpause', 'lock', 'unlock', 'unrescue',
|
||||
@ -577,7 +576,7 @@ class V3(Base):
|
||||
'detach': ['volume_id'],
|
||||
'swap_volume_attachment': ['old_volume_id', 'new_volume_id']}
|
||||
|
||||
body = jsonutils.loads(request.body.decode('utf-8'))
|
||||
body = jsonutils.loads(request.body)
|
||||
assert len(body.keys()) == 1
|
||||
action = list(body)[0]
|
||||
_body = body_return_map.get(action, '')
|
||||
@ -598,13 +597,13 @@ class V3(Base):
|
||||
assert body[action]['type'] in ['HARD', 'SOFT']
|
||||
elif action == 'confirm_resize':
|
||||
# This one method returns a different response code
|
||||
resp = 204
|
||||
context.status_code = 204
|
||||
elif action == 'create_image':
|
||||
headers['location'] = "http://blah/images/456"
|
||||
context.headers['location'] = "http://blah/images/456"
|
||||
|
||||
if action not in set.union(set(body_is_none_list),
|
||||
set(body_params_check_exact.keys()),
|
||||
set(body_param_check_exists.keys())):
|
||||
raise AssertionError("Unexpected server action: %s" % action)
|
||||
|
||||
return resp, headers, jsonutils.dumps(_body)
|
||||
return _body
|
||||
|
@ -14,8 +14,8 @@
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
import httpretty
|
||||
import requests
|
||||
from requests_mock.contrib import fixture as requests_mock_fixture
|
||||
import six
|
||||
import testscenarios
|
||||
import testtools
|
||||
@ -52,24 +52,26 @@ class FixturedTestCase(testscenarios.TestWithScenarios, TestCase):
|
||||
def setUp(self):
|
||||
super(FixturedTestCase, self).setUp()
|
||||
|
||||
httpretty.reset()
|
||||
self.requests = self.useFixture(requests_mock_fixture.Fixture())
|
||||
self.data_fixture = None
|
||||
self.client_fixture = None
|
||||
self.cs = None
|
||||
|
||||
if self.client_fixture_class:
|
||||
self.client_fixture = self.useFixture(self.client_fixture_class())
|
||||
fix = self.client_fixture_class(self.requests)
|
||||
self.client_fixture = self.useFixture(fix)
|
||||
self.cs = self.client_fixture.client
|
||||
|
||||
if self.data_fixture_class:
|
||||
self.data_fixture = self.useFixture(self.data_fixture_class())
|
||||
fix = self.data_fixture_class(self.requests)
|
||||
self.data_fixture = self.useFixture(fix)
|
||||
|
||||
def assert_called(self, method, path, body=None):
|
||||
self.assertEqual(httpretty.last_request().method, method)
|
||||
self.assertEqual(httpretty.last_request().path, path)
|
||||
self.assertEqual(self.requests.last_request.method, method)
|
||||
self.assertEqual(self.requests.last_request.path_url, path)
|
||||
|
||||
if body:
|
||||
req_data = httpretty.last_request().body
|
||||
req_data = self.requests.last_request.body
|
||||
if isinstance(req_data, six.binary_type):
|
||||
req_data = req_data.decode('utf-8')
|
||||
if not isinstance(body, six.string_types):
|
||||
|
@ -13,9 +13,6 @@
|
||||
# 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 agents as data
|
||||
from novaclient.tests.fixture_data import client
|
||||
from novaclient.tests import utils
|
||||
@ -53,9 +50,10 @@ class AgentsTest(utils.FixturedTestCase):
|
||||
]
|
||||
}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.data_fixture.url(),
|
||||
body=jsonutils.dumps(get_os_agents),
|
||||
content_type='application/json')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
self.requests.register_uri('GET', self.data_fixture.url(),
|
||||
json=get_os_agents,
|
||||
headers=headers)
|
||||
|
||||
def test_list_agents(self):
|
||||
self.stub_hypervisors()
|
||||
|
@ -12,11 +12,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import httpretty
|
||||
import mock
|
||||
import six
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.tests.fixture_data import client
|
||||
from novaclient.tests.fixture_data import floatingips
|
||||
from novaclient.tests.fixture_data import servers as data
|
||||
@ -31,7 +31,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ServersTest, self).setUp()
|
||||
self.useFixture(floatingips.FloatingFixture())
|
||||
self.useFixture(floatingips.FloatingFixture(self.requests))
|
||||
|
||||
def test_list_servers(self):
|
||||
sl = self.cs.servers.list()
|
||||
@ -191,7 +191,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
self.assertIsInstance(s, servers.Server)
|
||||
|
||||
# verify disk config param was used in the request:
|
||||
body = httpretty.last_request().parsed_body
|
||||
body = jsonutils.loads(self.requests.last_request.body)
|
||||
server = body['server']
|
||||
self.assertTrue('OS-DCF:diskConfig' in server)
|
||||
self.assertEqual(disk_config, server['OS-DCF:diskConfig'])
|
||||
@ -280,7 +280,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
self.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
# verify disk config param was used in the request:
|
||||
body = httpretty.last_request().parsed_body
|
||||
body = jsonutils.loads(self.requests.last_request.body)
|
||||
|
||||
d = body[operation]
|
||||
self.assertTrue('OS-DCF:diskConfig' in d)
|
||||
@ -296,7 +296,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
s = self.cs.servers.get(1234)
|
||||
s.rebuild(image=1, preserve_ephemeral=True)
|
||||
self.assert_called('POST', '/servers/1234/action')
|
||||
body = httpretty.last_request().parsed_body
|
||||
body = jsonutils.loads(self.requests.last_request.body)
|
||||
d = body['rebuild']
|
||||
self.assertIn('preserve_ephemeral', d)
|
||||
self.assertEqual(d['preserve_ephemeral'], True)
|
||||
@ -305,7 +305,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
files = {'/etc/passwd': 'some data'}
|
||||
s = self.cs.servers.get(1234)
|
||||
s.rebuild(image=1, name='new', meta={'foo': 'bar'}, files=files)
|
||||
body = httpretty.last_request().parsed_body
|
||||
body = jsonutils.loads(self.requests.last_request.body)
|
||||
d = body['rebuild']
|
||||
self.assertEqual('new', d['name'])
|
||||
self.assertEqual({'foo': 'bar'}, d['metadata'])
|
||||
|
@ -3,9 +3,9 @@ hacking>=0.9.2,<0.10
|
||||
coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.14
|
||||
httpretty>=0.8.0,!=0.8.1,!=0.8.2
|
||||
keyring>=2.1,!=3.3
|
||||
mock>=1.0
|
||||
requests-mock>=0.4.0
|
||||
sphinx>=1.1.2,!=1.2.0,<1.3
|
||||
python-keystoneclient>=0.10.0
|
||||
oslosphinx
|
||||
|
Loading…
x
Reference in New Issue
Block a user