Merge "Move orm/common/client tests to top level"

This commit is contained in:
Jenkins 2017-08-29 02:46:43 +00:00 committed by Gerrit Code Review
commit d61621cf84
10 changed files with 19 additions and 18 deletions

View File

@ -1 +0,0 @@
"""test package."""

View File

@ -1 +0,0 @@
"""api package."""

View File

@ -1 +0,0 @@
"""model package."""

View File

@ -3,6 +3,7 @@ import logging
import requests
from orm.common.client.keystone.mock_keystone.keystoneclient import exceptions
from orm.common.client.keystone.mock_keystone.keystoneclient.v2_0 import client as v2_client
from orm.common.client.keystone.mock_keystone.keystoneclient.v3 import client as v3_client
from orm.common.orm_common.utils import dictator
@ -98,7 +99,7 @@ def get_token_user(token, conf, lcp_id=None, keystone_ep=None):
return TokenUser(token_info)
# Other exceptions raised by validate() are critical errors,
# so instead of returning False, we'll just let them propagate
except client.exceptions.NotFound:
except exceptions.NotFound:
logger.debug('User token not found in Keystone! Make sure that it is '
'correct and that it has not expired yet')
return None
@ -161,7 +162,7 @@ def _does_user_have_role(keystone, version, user, role, location):
try:
return keystone.roles.check(role, user=user['user']['id'],
**location)
except v3_client.exceptions.NotFound:
except exceptions.NotFound:
return False
except KeyError:
# Shouldn't be raised when using Keystone's v3/v2.0 API, but let's
@ -254,7 +255,7 @@ def is_token_valid(token_to_validate, lcp_id, conf, required_role=None,
logger.debug('User token found in Keystone')
# Other exceptions raised by validate() are critical errors,
# so instead of returning False, we'll just let them propagate
except client.exceptions.NotFound:
except exceptions.NotFound:
logger.debug('User token not found in Keystone! Make sure that it is'
'correct and that it has not expired yet')
return False
@ -268,7 +269,7 @@ def is_token_valid(token_to_validate, lcp_id, conf, required_role=None,
logger.debug('Checking role...')
return _does_user_have_role(keystone, conf.version, user,
required_role, role_location)
except client.exceptions.NotFound:
except exceptions.NotFound:
raise ValueError('Role %s or tenant %s not found!' % (
required_role, role_location,))
else:

View File

@ -5,8 +5,9 @@ import threading
import unittest
import urllib2
from audit_client.api import audit
from audit_client.api.exceptions.audit_exception import AuditException
from orm.common.client.audit.audit_client.api import audit
from orm.common.client.audit.audit_client.api.exceptions.audit_exception import AuditException
from mock import patch

View File

@ -2,7 +2,7 @@
import unittest
from audit_client.api.model.get_audits_result import AuditsResult
from orm.common.client.audit.audit_client.api.model.get_audits_result import AuditsResult
class Test(unittest.TestCase):

View File

@ -1,7 +1,9 @@
"""keystone_utils token validator unittests."""
import unittest
from keystone_utils import tokens
from orm.common.client.keystone.keystone_utils import tokens
from orm.common.client.keystone.mock_keystone.keystoneclient import exceptions
import mock
@ -16,10 +18,10 @@ class MyResponse(object):
class MyKeystone(object):
def validate(self, a):
raise tokens.v3_client.exceptions.NotFound('test')
raise exceptions.NotFound('test')
def find(self, **kwargs):
raise tokens.v3_client.exceptions.NotFound('test')
raise exceptions.NotFound('test')
class MyClient(object):
@ -151,7 +153,7 @@ class TokensTest(unittest.TestCase):
def test_does_user_have_role_sanity_false(self, mock_client):
user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
mock_client.roles.check = mock.MagicMock(
side_effect=tokens.v3_client.exceptions.NotFound('test'))
side_effect=exceptions.NotFound('test'))
self.assertFalse(tokens._does_user_have_role(mock_client, '3', user,
'admin',
{'domain': 'test'}))
@ -167,8 +169,8 @@ class TokensTest(unittest.TestCase):
def test_does_user_have_role_role_does_not_exist(self, mock_client):
user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
mock_client.roles.find = mock.MagicMock(
side_effect=tokens.v3_client.exceptions.NotFound('test'))
self.assertRaises(tokens.v3_client.exceptions.NotFound,
side_effect=exceptions.NotFound('test'))
self.assertRaises(exceptions.NotFound,
tokens._does_user_have_role, mock_client, '3',
user, 'test', {'domain': 'default'})
@ -198,7 +200,7 @@ class TokensTest(unittest.TestCase):
@mock.patch.object(tokens, '_get_keystone_client')
def test_get_token_user_token_not_found(self, mock_get_keystone_client):
ks = mock.MagicMock()
ks.tokens.validate.side_effect = tokens.v3_client.exceptions.NotFound()
ks.tokens.validate.side_effect = exceptions.NotFound()
mock_get_keystone_client.return_value = ks
conf = tokens.TokenConf(*('3',) * 5)
self.assertIsNone(tokens.get_token_user('a', conf, 'c', 'd'))

View File

@ -2,7 +2,7 @@
import unittest
from audit_client.api.model.transaction import Transaction
from orm.common.client.audit.audit_client.api.model.transaction import Transaction
class Test(unittest.TestCase):