@ -14,8 +14,11 @@
# under the License.
from __future__ import absolute_import
import tobiko
from tobiko import config
from tobiko . tests import unit
from tobiko . openstack import keystone
from tobiko . openstack . keystone import credentials as _credentials
V2_PARAMS = {
@ -31,6 +34,12 @@ V2_ENVIRON = {
' OS_PASSWORD ' : ' super-secret ' ,
' OS_AUTH_URL ' : ' http://10.0.0.1:5678/v2.0 ' }
V2_ENVIRON_WITH_TENANT_NAME = {
' OS_TENANT_NAME ' : ' demo ' ,
' OS_USERNAME ' : ' demo ' ,
' OS_PASSWORD ' : ' super-secret ' ,
' OS_AUTH_URL ' : ' http://10.0.0.1:5678/v2.0 ' }
V2_ENVIRON_WITH_VERSION = dict ( V2_ENVIRON , OS_IDENTITY_API_VERSION = ' 2 ' )
@ -102,3 +111,124 @@ class KeystoneCredentialsTest(unit.TobikoUnitTest):
credentials = make_credentials ( V2_PARAMS , password = None )
self . assertRaises ( keystone . InvalidKeystoneCredentials ,
credentials . validate )
class EnvironKeystoneCredentialsFixtureTest ( unit . TobikoUnitTest ) :
def test_init ( self ) :
fixture = _credentials . EnvironKeystoneCredentialsFixture ( )
self . assertIsNone ( fixture . credentials )
def test_setup_v2 ( self ) :
self . patch ( ' os.environ ' , V2_ENVIRON )
fixture = _credentials . EnvironKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v2_with_tenant_name ( self ) :
self . patch ( ' os.environ ' , V2_ENVIRON_WITH_TENANT_NAME )
fixture = _credentials . EnvironKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v2_with_api_version ( self ) :
self . patch ( ' os.environ ' , V2_ENVIRON_WITH_VERSION )
fixture = _credentials . EnvironKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v3 ( self ) :
self . patch ( ' os.environ ' , V3_ENVIRON )
fixture = _credentials . EnvironKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V3_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v3_without_api_version ( self ) :
self . patch ( ' os.environ ' , V3_ENVIRON_WITH_VERSION )
fixture = _credentials . EnvironKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V3_PARAMS , fixture . credentials . to_dict ( ) )
class ConfigKeystoneCredentialsFixtureTest ( unit . TobikoUnitTest ) :
def patch_config ( self , params , * * kwargs ) :
credentials = make_credentials ( params , * * kwargs )
return self . patch_object ( config . CONF . tobiko , ' keystone ' , credentials )
def test_init ( self ) :
fixture = _credentials . ConfigKeystoneCredentialsFixture ( )
self . assertIsNone ( fixture . credentials )
def test_setup_v2 ( self ) :
self . patch_config ( V2_PARAMS , api_version = None )
fixture = _credentials . ConfigKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v2_with_api_version ( self ) :
self . patch_config ( V2_PARAMS , api_version = 2 )
fixture = _credentials . ConfigKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v3 ( self ) :
self . patch_config ( V3_PARAMS , api_version = None )
fixture = _credentials . ConfigKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V3_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_v3_with_api_version ( self ) :
self . patch_config ( V3_PARAMS , api_version = 3 )
fixture = _credentials . ConfigKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V3_PARAMS , fixture . credentials . to_dict ( ) )
class DefaultKeystoneCredentialsFixtureTest ( unit . TobikoUnitTest ) :
def setUp ( self ) :
super ( DefaultKeystoneCredentialsFixtureTest , self ) . setUp ( )
self . patch_config ( { } )
self . patch ( ' os.environ ' , { } )
tobiko . remove_fixture ( _credentials . ConfigKeystoneCredentialsFixture )
tobiko . remove_fixture ( _credentials . EnvironKeystoneCredentialsFixture )
def patch_config ( self , params , * * kwargs ) :
credentials = make_credentials ( params , * * kwargs )
return self . patch_object ( config . CONF . tobiko , ' keystone ' , credentials )
def test_init ( self ) :
fixture = _credentials . DefaultKeystoneCredentialsFixture ( )
self . assertIsNone ( fixture . credentials )
def test_setup_from_environ ( self ) :
self . patch ( ' os.environ ' , V2_ENVIRON )
fixture = _credentials . DefaultKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_from_config ( self ) :
self . patch_config ( V2_PARAMS )
fixture = _credentials . DefaultKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V2_PARAMS , fixture . credentials . to_dict ( ) )
def test_setup_from_environ_and_confif ( self ) :
self . patch ( ' os.environ ' , V3_ENVIRON )
self . patch_config ( V2_PARAMS )
fixture = _credentials . DefaultKeystoneCredentialsFixture ( )
fixture . setUp ( )
fixture . credentials . validate ( )
self . assertEqual ( V3_PARAMS , fixture . credentials . to_dict ( ) )