Add unit tests for connection.add_service
Change-Id: Ifb488d9a49c988e9c21ff2d8e0a0ad7abbb28618
This commit is contained in:
0
openstack/tests/unit/fake/__init__.py
Normal file
0
openstack/tests/unit/fake/__init__.py
Normal file
24
openstack/tests/unit/fake/fake_service.py
Normal file
24
openstack/tests/unit/fake/fake_service.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
from openstack import service_description
|
||||||
|
from openstack.tests.unit.fake.v1 import _proxy as _proxy_1
|
||||||
|
from openstack.tests.unit.fake.v2 import _proxy as _proxy_2
|
||||||
|
|
||||||
|
|
||||||
|
class FakeService(service_description.ServiceDescription):
|
||||||
|
"""The fake service."""
|
||||||
|
|
||||||
|
supported_versions = {
|
||||||
|
'1': _proxy_1.Proxy,
|
||||||
|
'2': _proxy_2.Proxy,
|
||||||
|
}
|
||||||
0
openstack/tests/unit/fake/v1/__init__.py
Normal file
0
openstack/tests/unit/fake/v1/__init__.py
Normal file
20
openstack/tests/unit/fake/v1/_proxy.py
Normal file
20
openstack/tests/unit/fake/v1/_proxy.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 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.
|
||||||
|
from openstack import proxy
|
||||||
|
|
||||||
|
|
||||||
|
class Proxy(proxy.Proxy):
|
||||||
|
|
||||||
|
skip_discovery = True
|
||||||
|
|
||||||
|
def dummy(self):
|
||||||
|
return True
|
||||||
35
openstack/tests/unit/fake/v1/fake.py
Normal file
35
openstack/tests/unit/fake/v1/fake.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# 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.
|
||||||
|
from openstack import resource
|
||||||
|
|
||||||
|
|
||||||
|
class Fake(resource.Resource):
|
||||||
|
resource_key = "resource"
|
||||||
|
resources_key = "resources"
|
||||||
|
base_path = "/fake"
|
||||||
|
|
||||||
|
allow_create = True
|
||||||
|
allow_fetch = True
|
||||||
|
allow_commit = True
|
||||||
|
allow_delete = True
|
||||||
|
allow_list = True
|
||||||
|
allow_head = True
|
||||||
|
|
||||||
|
#: The transaction date and time.
|
||||||
|
timestamp = resource.Header("x-timestamp")
|
||||||
|
#: The name of this resource.
|
||||||
|
name = resource.Body("name", alternate_id=True)
|
||||||
|
#: The value of the resource. Also available in headers.
|
||||||
|
value = resource.Body("value", alias="x-resource-value")
|
||||||
|
#: Is this resource cool? If so, set it to True.
|
||||||
|
#: This is a multi-line comment about cool stuff.
|
||||||
|
cool = resource.Body("cool", type=bool)
|
||||||
0
openstack/tests/unit/fake/v2/__init__.py
Normal file
0
openstack/tests/unit/fake/v2/__init__.py
Normal file
20
openstack/tests/unit/fake/v2/_proxy.py
Normal file
20
openstack/tests/unit/fake/v2/_proxy.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 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.
|
||||||
|
from openstack import proxy
|
||||||
|
|
||||||
|
|
||||||
|
class Proxy(proxy.Proxy):
|
||||||
|
|
||||||
|
skip_discovery = True
|
||||||
|
|
||||||
|
def dummy(self):
|
||||||
|
return False
|
||||||
35
openstack/tests/unit/fake/v2/fake.py
Normal file
35
openstack/tests/unit/fake/v2/fake.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# 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.
|
||||||
|
from openstack import resource
|
||||||
|
|
||||||
|
|
||||||
|
class Fake(resource.Resource):
|
||||||
|
resource_key = "resource"
|
||||||
|
resources_key = "resources"
|
||||||
|
base_path = "/fake"
|
||||||
|
|
||||||
|
allow_create = True
|
||||||
|
allow_fetch = True
|
||||||
|
allow_commit = True
|
||||||
|
allow_delete = True
|
||||||
|
allow_list = True
|
||||||
|
allow_head = True
|
||||||
|
|
||||||
|
#: The transaction date and time.
|
||||||
|
timestamp = resource.Header("x-timestamp")
|
||||||
|
#: The name of this resource.
|
||||||
|
name = resource.Body("name", alternate_id=True)
|
||||||
|
#: The value of the resource. Also available in headers.
|
||||||
|
value = resource.Body("value", alias="x-resource-value")
|
||||||
|
#: Is this resource cool? If so, set it to True.
|
||||||
|
#: This is a multi-line comment about cool stuff.
|
||||||
|
cool = resource.Body("cool", type=bool)
|
||||||
71
openstack/tests/unit/fixtures/catalog-v3-fake-v1.json
Normal file
71
openstack/tests/unit/fixtures/catalog-v3-fake-v1.json
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"token": {
|
||||||
|
"audit_ids": [
|
||||||
|
"Rvn7eHkiSeOwucBIPaKdYA"
|
||||||
|
],
|
||||||
|
"catalog": [
|
||||||
|
{
|
||||||
|
"endpoints": [
|
||||||
|
{
|
||||||
|
"id": "4deb4d0504a044a395d4480741ba628c",
|
||||||
|
"interface": "public",
|
||||||
|
"region": "RegionOne",
|
||||||
|
"url": "https://identity.example.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "012322eeedcd459edabb4933021112bc",
|
||||||
|
"interface": "admin",
|
||||||
|
"region": "RegionOne",
|
||||||
|
"url": "https://identity.example.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"endpoints_links": [],
|
||||||
|
"name": "keystone",
|
||||||
|
"type": "identity"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endpoints": [
|
||||||
|
{
|
||||||
|
"id": "1e875ca2225b408bbf3520a1b8e1a537",
|
||||||
|
"interface": "public",
|
||||||
|
"region": "RegionOne",
|
||||||
|
"url": "https://fake.example.com/v1/1c36b64c840a42cd9e9b931a369337f0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "fake_service",
|
||||||
|
"type": "fake"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"expires_at": "9999-12-31T23:59:59Z",
|
||||||
|
"issued_at": "2016-12-17T14:25:05.000000Z",
|
||||||
|
"methods": [
|
||||||
|
"password"
|
||||||
|
],
|
||||||
|
"project": {
|
||||||
|
"domain": {
|
||||||
|
"id": "default",
|
||||||
|
"name": "default"
|
||||||
|
},
|
||||||
|
"id": "1c36b64c840a42cd9e9b931a369337f0",
|
||||||
|
"name": "Default Project"
|
||||||
|
},
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": "9fe2ff9ee4384b1894a90878d3e92bab",
|
||||||
|
"name": "_member_"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "37071fc082e14c2284c32a2761f71c63",
|
||||||
|
"name": "swiftoperator"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user": {
|
||||||
|
"domain": {
|
||||||
|
"id": "default",
|
||||||
|
"name": "default"
|
||||||
|
},
|
||||||
|
"id": "c17534835f8f42bf98fc367e0bf35e09",
|
||||||
|
"name": "mordred"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
71
openstack/tests/unit/fixtures/catalog-v3-fake-v2.json
Normal file
71
openstack/tests/unit/fixtures/catalog-v3-fake-v2.json
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"token": {
|
||||||
|
"audit_ids": [
|
||||||
|
"Rvn7eHkiSeOwucBIPaKdYA"
|
||||||
|
],
|
||||||
|
"catalog": [
|
||||||
|
{
|
||||||
|
"endpoints": [
|
||||||
|
{
|
||||||
|
"id": "4deb4d0504a044a395d4480741ba628c",
|
||||||
|
"interface": "public",
|
||||||
|
"region": "RegionOne",
|
||||||
|
"url": "https://identity.example.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "012322eeedcd459edabb4933021112bc",
|
||||||
|
"interface": "admin",
|
||||||
|
"region": "RegionOne",
|
||||||
|
"url": "https://identity.example.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"endpoints_links": [],
|
||||||
|
"name": "keystone",
|
||||||
|
"type": "identity"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endpoints": [
|
||||||
|
{
|
||||||
|
"id": "1e875ca2225b408bbf3520a1b8e1a537",
|
||||||
|
"interface": "public",
|
||||||
|
"region": "RegionOne",
|
||||||
|
"url": "https://fake.example.com/v2/1c36b64c840a42cd9e9b931a369337f0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "fake_service",
|
||||||
|
"type": "fake"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"expires_at": "9999-12-31T23:59:59Z",
|
||||||
|
"issued_at": "2016-12-17T14:25:05.000000Z",
|
||||||
|
"methods": [
|
||||||
|
"password"
|
||||||
|
],
|
||||||
|
"project": {
|
||||||
|
"domain": {
|
||||||
|
"id": "default",
|
||||||
|
"name": "default"
|
||||||
|
},
|
||||||
|
"id": "1c36b64c840a42cd9e9b931a369337f0",
|
||||||
|
"name": "Default Project"
|
||||||
|
},
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": "9fe2ff9ee4384b1894a90878d3e92bab",
|
||||||
|
"name": "_member_"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "37071fc082e14c2284c32a2761f71c63",
|
||||||
|
"name": "swiftoperator"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user": {
|
||||||
|
"domain": {
|
||||||
|
"id": "default",
|
||||||
|
"name": "default"
|
||||||
|
},
|
||||||
|
"id": "c17534835f8f42bf98fc367e0bf35e09",
|
||||||
|
"name": "mordred"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import mock
|
|||||||
from openstack import connection
|
from openstack import connection
|
||||||
import openstack.config
|
import openstack.config
|
||||||
from openstack.tests.unit import base
|
from openstack.tests.unit import base
|
||||||
|
from openstack.tests.unit.fake import fake_service
|
||||||
|
|
||||||
|
|
||||||
CONFIG_AUTH_URL = "https://identity.example.com/"
|
CONFIG_AUTH_URL = "https://identity.example.com/"
|
||||||
@@ -251,3 +252,56 @@ class TestAuthorize(base.TestCase):
|
|||||||
|
|
||||||
self.assertRaises(openstack.exceptions.HttpException,
|
self.assertRaises(openstack.exceptions.HttpException,
|
||||||
self.cloud.authorize)
|
self.cloud.authorize)
|
||||||
|
|
||||||
|
|
||||||
|
class TestNewService(base.TestCase):
|
||||||
|
|
||||||
|
def test_add_service_v1(self):
|
||||||
|
self.use_keystone_v3(catalog='catalog-v3-fake-v1.json')
|
||||||
|
conn = self.cloud
|
||||||
|
|
||||||
|
self.register_uris([
|
||||||
|
dict(method='GET',
|
||||||
|
uri='https://fake.example.com',
|
||||||
|
status_code=404),
|
||||||
|
dict(method='GET',
|
||||||
|
uri='https://fake.example.com/v1/',
|
||||||
|
status_code=404),
|
||||||
|
dict(method='GET',
|
||||||
|
uri=self.get_mock_url('fake'),
|
||||||
|
status_code=404),
|
||||||
|
])
|
||||||
|
|
||||||
|
service = fake_service.FakeService('fake')
|
||||||
|
|
||||||
|
conn.add_service(service)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
'openstack.tests.unit.fake.v1._proxy',
|
||||||
|
conn.fake.__class__.__module__)
|
||||||
|
self.assertTrue(conn.fake.dummy())
|
||||||
|
|
||||||
|
def test_add_service_v2(self):
|
||||||
|
self.use_keystone_v3(catalog='catalog-v3-fake-v2.json')
|
||||||
|
conn = self.cloud
|
||||||
|
|
||||||
|
self.register_uris([
|
||||||
|
dict(method='GET',
|
||||||
|
uri='https://fake.example.com',
|
||||||
|
status_code=404),
|
||||||
|
dict(method='GET',
|
||||||
|
uri='https://fake.example.com/v2/',
|
||||||
|
status_code=404),
|
||||||
|
dict(method='GET',
|
||||||
|
uri=self.get_mock_url('fake'),
|
||||||
|
status_code=404),
|
||||||
|
])
|
||||||
|
|
||||||
|
service = fake_service.FakeService('fake')
|
||||||
|
|
||||||
|
conn.add_service(service)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
'openstack.tests.unit.fake.v2._proxy',
|
||||||
|
conn.fake.__class__.__module__)
|
||||||
|
self.assertFalse(conn.fake.dummy())
|
||||||
|
|||||||
Reference in New Issue
Block a user