Merge "Move orm/common/client tests to top level"
This commit is contained in:
commit
d61621cf84
@ -1 +0,0 @@
|
|||||||
"""test package."""
|
|
@ -1 +0,0 @@
|
|||||||
"""api package."""
|
|
@ -1 +0,0 @@
|
|||||||
"""model package."""
|
|
@ -3,6 +3,7 @@ import logging
|
|||||||
|
|
||||||
import requests
|
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.v2_0 import client as v2_client
|
||||||
from orm.common.client.keystone.mock_keystone.keystoneclient.v3 import client as v3_client
|
from orm.common.client.keystone.mock_keystone.keystoneclient.v3 import client as v3_client
|
||||||
from orm.common.orm_common.utils import dictator
|
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)
|
return TokenUser(token_info)
|
||||||
# Other exceptions raised by validate() are critical errors,
|
# Other exceptions raised by validate() are critical errors,
|
||||||
# so instead of returning False, we'll just let them propagate
|
# 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 '
|
logger.debug('User token not found in Keystone! Make sure that it is '
|
||||||
'correct and that it has not expired yet')
|
'correct and that it has not expired yet')
|
||||||
return None
|
return None
|
||||||
@ -161,7 +162,7 @@ def _does_user_have_role(keystone, version, user, role, location):
|
|||||||
try:
|
try:
|
||||||
return keystone.roles.check(role, user=user['user']['id'],
|
return keystone.roles.check(role, user=user['user']['id'],
|
||||||
**location)
|
**location)
|
||||||
except v3_client.exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
return False
|
return False
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Shouldn't be raised when using Keystone's v3/v2.0 API, but let's
|
# 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')
|
logger.debug('User token found in Keystone')
|
||||||
# Other exceptions raised by validate() are critical errors,
|
# Other exceptions raised by validate() are critical errors,
|
||||||
# so instead of returning False, we'll just let them propagate
|
# 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'
|
logger.debug('User token not found in Keystone! Make sure that it is'
|
||||||
'correct and that it has not expired yet')
|
'correct and that it has not expired yet')
|
||||||
return False
|
return False
|
||||||
@ -268,7 +269,7 @@ def is_token_valid(token_to_validate, lcp_id, conf, required_role=None,
|
|||||||
logger.debug('Checking role...')
|
logger.debug('Checking role...')
|
||||||
return _does_user_have_role(keystone, conf.version, user,
|
return _does_user_have_role(keystone, conf.version, user,
|
||||||
required_role, role_location)
|
required_role, role_location)
|
||||||
except client.exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
raise ValueError('Role %s or tenant %s not found!' % (
|
raise ValueError('Role %s or tenant %s not found!' % (
|
||||||
required_role, role_location,))
|
required_role, role_location,))
|
||||||
else:
|
else:
|
||||||
|
@ -5,8 +5,9 @@ import threading
|
|||||||
import unittest
|
import unittest
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
from audit_client.api import audit
|
from orm.common.client.audit.audit_client.api import audit
|
||||||
from audit_client.api.exceptions.audit_exception import AuditException
|
from orm.common.client.audit.audit_client.api.exceptions.audit_exception import AuditException
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import unittest
|
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):
|
class Test(unittest.TestCase):
|
@ -1,7 +1,9 @@
|
|||||||
"""keystone_utils token validator unittests."""
|
"""keystone_utils token validator unittests."""
|
||||||
import unittest
|
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
|
import mock
|
||||||
|
|
||||||
|
|
||||||
@ -16,10 +18,10 @@ class MyResponse(object):
|
|||||||
|
|
||||||
class MyKeystone(object):
|
class MyKeystone(object):
|
||||||
def validate(self, a):
|
def validate(self, a):
|
||||||
raise tokens.v3_client.exceptions.NotFound('test')
|
raise exceptions.NotFound('test')
|
||||||
|
|
||||||
def find(self, **kwargs):
|
def find(self, **kwargs):
|
||||||
raise tokens.v3_client.exceptions.NotFound('test')
|
raise exceptions.NotFound('test')
|
||||||
|
|
||||||
|
|
||||||
class MyClient(object):
|
class MyClient(object):
|
||||||
@ -151,7 +153,7 @@ class TokensTest(unittest.TestCase):
|
|||||||
def test_does_user_have_role_sanity_false(self, mock_client):
|
def test_does_user_have_role_sanity_false(self, mock_client):
|
||||||
user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
|
user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
|
||||||
mock_client.roles.check = mock.MagicMock(
|
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,
|
self.assertFalse(tokens._does_user_have_role(mock_client, '3', user,
|
||||||
'admin',
|
'admin',
|
||||||
{'domain': 'test'}))
|
{'domain': 'test'}))
|
||||||
@ -167,8 +169,8 @@ class TokensTest(unittest.TestCase):
|
|||||||
def test_does_user_have_role_role_does_not_exist(self, mock_client):
|
def test_does_user_have_role_role_does_not_exist(self, mock_client):
|
||||||
user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
|
user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
|
||||||
mock_client.roles.find = mock.MagicMock(
|
mock_client.roles.find = mock.MagicMock(
|
||||||
side_effect=tokens.v3_client.exceptions.NotFound('test'))
|
side_effect=exceptions.NotFound('test'))
|
||||||
self.assertRaises(tokens.v3_client.exceptions.NotFound,
|
self.assertRaises(exceptions.NotFound,
|
||||||
tokens._does_user_have_role, mock_client, '3',
|
tokens._does_user_have_role, mock_client, '3',
|
||||||
user, 'test', {'domain': 'default'})
|
user, 'test', {'domain': 'default'})
|
||||||
|
|
||||||
@ -198,7 +200,7 @@ class TokensTest(unittest.TestCase):
|
|||||||
@mock.patch.object(tokens, '_get_keystone_client')
|
@mock.patch.object(tokens, '_get_keystone_client')
|
||||||
def test_get_token_user_token_not_found(self, mock_get_keystone_client):
|
def test_get_token_user_token_not_found(self, mock_get_keystone_client):
|
||||||
ks = mock.MagicMock()
|
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
|
mock_get_keystone_client.return_value = ks
|
||||||
conf = tokens.TokenConf(*('3',) * 5)
|
conf = tokens.TokenConf(*('3',) * 5)
|
||||||
self.assertIsNone(tokens.get_token_user('a', conf, 'c', 'd'))
|
self.assertIsNone(tokens.get_token_user('a', conf, 'c', 'd'))
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import unittest
|
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):
|
class Test(unittest.TestCase):
|
Loading…
x
Reference in New Issue
Block a user