Fix unit test
One refstack-client unit test had impementation issues causing failures in other tests. This patch fixes this test so that all tests can pass. Change-Id: Ia100d879d2f5706e37468a7e31e4b27f25be9716
This commit is contained in:
parent
0fc224a533
commit
e8f2a6a7ea
@ -24,8 +24,6 @@ import httmock
|
|||||||
import mock
|
import mock
|
||||||
from mock import MagicMock
|
from mock import MagicMock
|
||||||
import unittest
|
import unittest
|
||||||
import requests
|
|
||||||
|
|
||||||
|
|
||||||
import refstack_client.refstack_client as rc
|
import refstack_client.refstack_client as rc
|
||||||
import refstack_client.list_parser as lp
|
import refstack_client.list_parser as lp
|
||||||
@ -274,35 +272,37 @@ class TestRefstackClient(unittest.TestCase):
|
|||||||
auth_version, auth_url, content = \
|
auth_version, auth_url, content = \
|
||||||
client._generate_keystone_data(configs)
|
client._generate_keystone_data(configs)
|
||||||
client._generate_cpid_from_endpoint = MagicMock()
|
client._generate_cpid_from_endpoint = MagicMock()
|
||||||
requests.post = MagicMock()
|
|
||||||
# Test when the identity ID is None.
|
# Test when the identity ID is None.
|
||||||
ks3_ID_None = {'auth_ref': {'catalog':
|
ks3_ID_None = {'token': {'catalog':
|
||||||
[{'type': 'identity', 'id': None}]}}
|
[{'type': 'identity', 'id': None}]}}
|
||||||
|
|
||||||
@httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v3/auth/tokens')
|
@httmock.all_requests
|
||||||
def keystone_api_v3_mock(auth_version, url, request):
|
def keystone_api_v3_mock(url, request):
|
||||||
return ks3_ID_None
|
return httmock.response(201, ks3_ID_None)
|
||||||
with httmock.HTTMock(keystone_api_v3_mock):
|
with httmock.HTTMock(keystone_api_v3_mock):
|
||||||
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
||||||
client._generate_cpid_from_endpoint.assert_called_with(auth_url)
|
client._generate_cpid_from_endpoint.assert_called_with(auth_url)
|
||||||
|
|
||||||
# Test when the catalog is empty.
|
# Test when the catalog is empty.
|
||||||
ks3_catalog_empty = {'auth_ref': {'catalog': []}}
|
ks3_catalog_empty = {'token': {'catalog': []}}
|
||||||
|
client._generate_cpid_from_endpoint = MagicMock()
|
||||||
|
|
||||||
@httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v3/auth/tokens')
|
@httmock.all_requests
|
||||||
def keystone_api_v3_mock(auth_version, url, request):
|
def keystone_api_v3_mock2(url, request):
|
||||||
return ks3_catalog_empty
|
return httmock.response(201, ks3_catalog_empty)
|
||||||
with httmock.HTTMock(keystone_api_v3_mock):
|
with httmock.HTTMock(keystone_api_v3_mock2):
|
||||||
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
||||||
client._generate_cpid_from_endpoint.assert_called_with(auth_url)
|
client._generate_cpid_from_endpoint.assert_called_with(auth_url)
|
||||||
|
|
||||||
# Test when there is no service catalog.
|
# Test when there is no service catalog.
|
||||||
ks3_no_catalog = {'auth_ref': {}}
|
ks3_no_catalog = {'token': {}}
|
||||||
|
client._generate_cpid_from_endpoint = MagicMock()
|
||||||
|
|
||||||
@httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v3/auth/tokens')
|
@httmock.all_requests
|
||||||
def keystone_api_v3_mock(auth_version, url, request):
|
def keystone_api_v3_mock3(url, request):
|
||||||
return ks3_no_catalog
|
return httmock.response(201, ks3_no_catalog)
|
||||||
with httmock.HTTMock(keystone_api_v3_mock):
|
with httmock.HTTMock(keystone_api_v3_mock3):
|
||||||
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
||||||
client._generate_cpid_from_endpoint.assert_called_with(auth_url)
|
client._generate_cpid_from_endpoint.assert_called_with(auth_url)
|
||||||
|
|
||||||
@ -311,17 +311,17 @@ class TestRefstackClient(unittest.TestCase):
|
|||||||
'id': 'test-id1'},
|
'id': 'test-id1'},
|
||||||
{'type': 'identity',
|
{'type': 'identity',
|
||||||
'id': 'test-id2'}]}}
|
'id': 'test-id2'}]}}
|
||||||
headers = {'content-type': 'application/json'}
|
client._generate_cpid_from_endpoint = MagicMock()
|
||||||
|
|
||||||
@httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v3/auth/tokens')
|
@httmock.all_requests
|
||||||
def keystone_api_v3_mock(auth_version, url, request):
|
def keystone_api_v3_mock4(url, request):
|
||||||
return ks3_other_services
|
return httmock.response(201, ks3_other_services)
|
||||||
with httmock.HTTMock(keystone_api_v3_mock):
|
with httmock.HTTMock(keystone_api_v3_mock4):
|
||||||
client._get_cpid_from_keystone(auth_version, auth_url, content)
|
cpid = client._get_cpid_from_keystone(auth_version,
|
||||||
requests.post.assert_called_with(auth_url,
|
auth_url,
|
||||||
data=json.dumps(content),
|
content)
|
||||||
headers=headers,
|
self.assertFalse(client._generate_cpid_from_endpoint.called)
|
||||||
verify=True)
|
self.assertEqual('test-id2', cpid)
|
||||||
|
|
||||||
def test_get_cpid_from_keystone_failure_handled(self):
|
def test_get_cpid_from_keystone_failure_handled(self):
|
||||||
"""Test that get cpid from keystone API failure handled."""
|
"""Test that get cpid from keystone API failure handled."""
|
||||||
|
Loading…
Reference in New Issue
Block a user