#NEWLINE# @ mock . patch ( 'novaclient.client.Client' ) #NEWLINE# def test_get_api_version( self , nova ) : #NEWLINE# #INDENT# context = mock . NonCallableMock ( session = mock . sentinel . session ) #NEWLINE# v2 = mock . NonCallableMock ( ) #NEWLINE# v2 . configure_mock ( id = 'v2' , version = '' , links = [ { #NEWLINE# #INDENT# 'href' : 'http://host:port/path/v2/' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# v2_1 = mock . NonCallableMock ( ) #NEWLINE# v2_1 . configure_mock ( id = 'v2.1' , version = '2.11' , links = [ { #NEWLINE# #INDENT# 'href' : 'http://host:port/path/v2.1/' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# nova . return_value . versions . get_current . return_value = v2_1 #NEWLINE# with fixtures . LoggerFixture ( format = '[%(levelname)s] %(message)s' ) as logs : #NEWLINE# #INDENT# res = clients . _get_nova_api_version ( context ) #NEWLINE# #UNINDENT# self . assertEqual ( clients . REQUIRED_NOVA_API_MICROVERSION , res ) #NEWLINE# nova . assert_called_with ( '2.1' , service_type = 'compute' , session = mock . sentinel . session ) #NEWLINE# nova . return_value . versions . get_current . assert_called_with ( ) #NEWLINE# self . assertTrue ( logs . output . startswith ( '[INFO]' ) ) #NEWLINE# v2_1 . version = '2.2' #NEWLINE# with fixtures . LoggerFixture ( format = '[%(levelname)s] %(message)s' ) as logs : #NEWLINE# #INDENT# res = clients . _get_nova_api_version ( context ) #NEWLINE# #UNINDENT# self . assertEqual ( '2.2' , res ) #NEWLINE# self . assertTrue ( logs . output . startswith ( '[WARNING]' ) ) #NEWLINE# nova . return_value . versions . get_current . return_value = v2 #NEWLINE# self . configure ( nova_service_type = 'compute_legacy' ) #NEWLINE# with fixtures . LoggerFixture ( format = '[%(levelname)s] %(message)s' ) as logs : #NEWLINE# #INDENT# res = clients . _get_nova_api_version ( v2 ) #NEWLINE# #UNINDENT# self . assertEqual ( '2' , res ) #NEWLINE# self . assertTrue ( logs . output . startswith ( '[WARNING]' ) ) #NEWLINE# self . configure ( nova_service_type = 'compute' ) #NEWLINE# nova . return_value . versions . get_current . return_value = None #NEWLINE# with fixtures . LoggerFixture ( format = '[%(levelname)s] %(message)s' ) as logs : #NEWLINE# #INDENT# res = clients . _get_nova_api_version ( context ) #NEWLINE# #UNINDENT# self . assertEqual ( clients . REQUIRED_NOVA_API_MICROVERSION , res ) #NEWLINE# self . assertTrue ( logs . output . startswith ( '[WARNING]' ) )