#NEWLINE# def testRegister( self ) : #NEWLINE# #INDENT# 'Create master and register other servers.' #NEWLINE# m = master . DataMaster ( self . ports [ 0 ] , self . mock_service ) #NEWLINE# self . assertNotEqual ( m , None ) #NEWLINE# self . assertFalse ( m . AllRegistered ( ) ) #NEWLINE# servers = [ None ] #NEWLINE# for ( i , port ) in enumerate ( self . ports ) : #NEWLINE# #INDENT# if ( i == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# self . assertFalse ( m . AllRegistered ( ) ) #NEWLINE# server = m . RegisterServer ( pool_class . host , port ) #NEWLINE# servers . append ( server ) #NEWLINE# self . assertNotEqual ( server , None ) #NEWLINE# self . assertEqual ( server . Address ( ) , self . host ) #NEWLINE# self . assertEqual ( server . Port ( ) , port ) #NEWLINE# self . assertEqual ( server . Index ( ) , i ) #NEWLINE# #UNINDENT# self . assertTrue ( m . AllRegistered ( ) ) #NEWLINE# self . assertFalse ( m . RegisterServer ( self . host , 7004 ) ) #NEWLINE# m . DeregisterServer ( servers [ 1 ] ) #NEWLINE# self . assertFalse ( m . AllRegistered ( ) ) #NEWLINE# m . RegisterServer ( servers [ 1 ] . Address ( ) , servers [ 1 ] . Port ( ) ) #NEWLINE# self . assertTrue ( m . AllRegistered ( ) ) #NEWLINE# for port in self . ports : #NEWLINE# #INDENT# for response_sequence in [ [ constants . RESPONSE_OK , constants . RESPONSE_SERVER_NOT_AUTHORIZED ] , [ constants . RESPONSE_OK , constants . RESPONSE_SERVER_NOT_ALLOWED ] , [ constants . RESPONSE_OK , constants . RESPONSE_NOT_MASTER_SERVER ] ] : #NEWLINE# #INDENT# response_mocks = [ ] #NEWLINE# for response_status in response_sequence : #NEWLINE# #INDENT# response_mocks . append ( MockResponse ( response_status ) ) #NEWLINE# #UNINDENT# pool_class = GetMockHTTPConnectionPoolClass ( response_mocks ) #NEWLINE# with libutils . Stubber ( connectionpool , 'HTTPConnectionPool' , pool_class ) : #NEWLINE# #INDENT# m = data_server . StandardDataServer ( port , data_server . DataServerHandler ) #NEWLINE# m . handler_cls . NONCE_STORE = auth . NonceStore ( ) #NEWLINE# self . assertRaises ( errors . DataServerError , m . _DoRegister ) #NEWLINE# self . assertEqual ( len ( pool_class . requests ) , 2 ) #NEWLINE# self . assertTrue ( pool_class . requests [ 1 ] [ 'body' ] ) #NEWLINE# rdf_data_server . DataStoreRegistrationRequest ( pool_class . requests [ 1 ] [ 'body' ] ) #NEWLINE# self . assertEqual ( pool_class . requests [ 0 ] [ 'method' ] , 'POST' ) #NEWLINE# self . assertEqual ( pool_class . requests [ 1 ] [ 'method' ] , 'POST' ) #NEWLINE# self . assertEqual ( pool_class . requests [ 0 ] [ 'url' ] , '/server/handshake' ) #NEWLINE# self . assertEqual ( pool_class . requests [ 1 ] [ 'url' ] , '/server/register' )