Convert aggregates testing to use httpretty
This is the first in the series and so contains some setup classes. In general the original data will not be able to be removed from fakes until the very end because testing shell depends on a lot of it. Change-Id: I499fe968923b9452f60c1b2ca50d5749e89827de blueprint: httpretty-testingchanges/61/77961/7
parent
c9f4e085e2
commit
119a480fc1
@ -0,0 +1,52 @@
|
||||
# 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-aggregates'
|
||||
|
||||
def setUp(self):
|
||||
super(Fixture, self).setUp()
|
||||
|
||||
get_os_aggregates = {"aggregates": [
|
||||
{'id': '1',
|
||||
'name': 'test',
|
||||
'availability_zone': 'nova1'},
|
||||
{'id': '2',
|
||||
'name': 'test2',
|
||||
'availability_zone': 'nova1'},
|
||||
]}
|
||||
|
||||
httpretty.register_uri(httpretty.GET, self.url(),
|
||||
body=jsonutils.dumps(get_os_aggregates),
|
||||
content_type='application/json')
|
||||
|
||||
r = jsonutils.dumps({'aggregate': get_os_aggregates['aggregates'][0]})
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(), body=r,
|
||||
content_type='application/json')
|
||||
|
||||
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')
|
||||
|
||||
httpretty.register_uri(httpretty.POST, self.url(agg_id, 'action'),
|
||||
body=r, content_type='application/json')
|
||||
|
||||
httpretty.register_uri(httpretty.DELETE, self.url(1), status=202)
|
@ -0,0 +1,32 @@
|
||||
# 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 fixtures
|
||||
|
||||
COMPUTE_URL = 'http://compute.host'
|
||||
|
||||
|
||||
class Fixture(fixtures.Fixture):
|
||||
|
||||
base_url = None
|
||||
|
||||
def __init__(self, compute_url=COMPUTE_URL):
|
||||
super(Fixture, self).__init__()
|
||||
self.compute_url = compute_url
|
||||
|
||||
def url(self, *args):
|
||||
url_args = [self.compute_url]
|
||||
|
||||
if self.base_url:
|
||||
url_args.append(self.base_url)
|
||||
|
||||
return '/'.join(str(a).strip('/') for a in tuple(url_args) + args)
|
@ -0,0 +1,109 @@
|
||||
# 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 fixtures
|
||||
import httpretty
|
||||
|
||||
from novaclient.openstack.common import jsonutils
|
||||
from novaclient.v1_1 import client as v1_1client
|
||||
from novaclient.v3 import client as v3client
|
||||
|
||||
IDENTITY_URL = 'http://identityserver:5000/v2.0'
|
||||
COMPUTE_URL = 'http://compute.host'
|
||||
|
||||
|
||||
class V1(fixtures.Fixture):
|
||||
|
||||
def __init__(self, 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.token = {
|
||||
'access': {
|
||||
"token": {
|
||||
"id": "ab48a9efdfedb23ty3494",
|
||||
"expires": "2010-11-01T03:32:15-05:00",
|
||||
"tenant": {
|
||||
"id": "345",
|
||||
"name": "My Project"
|
||||
}
|
||||
},
|
||||
"user": {
|
||||
"id": "123",
|
||||
"name": "jqsmith",
|
||||
"roles": [
|
||||
{
|
||||
"id": "234",
|
||||
"name": "compute:admin",
|
||||
},
|
||||
{
|
||||
"id": "235",
|
||||
"name": "object-store:admin",
|
||||
"tenantId": "1",
|
||||
}
|
||||
],
|
||||
"roles_links": [],
|
||||
},
|
||||
"serviceCatalog": [
|
||||
{
|
||||
"name": "Cloud Servers",
|
||||
"type": "compute",
|
||||
"endpoints": [
|
||||
{
|
||||
"publicURL": self.compute_url,
|
||||
"internalURL": "https://compute1.host/v1/1",
|
||||
},
|
||||
],
|
||||
"endpoints_links": [],
|
||||
},
|
||||
{
|
||||
"name": "Cloud Servers",
|
||||
"type": "computev3",
|
||||
"endpoints": [
|
||||
{
|
||||
"publicURL": self.compute_url,
|
||||
"internalURL": "https://compute1.host/v1/1",
|
||||
},
|
||||
],
|
||||
"endpoints_links": [],
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
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')
|
||||
self.client = self.new_client()
|
||||
|
||||
def new_client(self):
|
||||
return v1_1client.Client(username='xx',
|
||||
api_key='xx',
|
||||
project_id='xx',
|
||||
auth_url=self.identity_url)
|
||||
|
||||
|
||||
class V3(V1):
|
||||
|
||||
def new_client(self):
|
||||
return v3client.Client(username='xx',
|
||||
password='xx',
|
||||
project_id='xx',
|
||||
auth_url=self.identity_url)
|
Loading…
Reference in New Issue