<s> from socket import timeout as socket_timeout <EOL> import django <EOL> from django . core . urlresolvers import reverse <EOL> from django import http <EOL> from django . test . utils import override_settings <EOL> from mox3 . mox import IgnoreArg <EOL> from mox3 . mox import IsA <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . test import helpers as test <EOL> USERS_INDEX_URL = reverse ( '<STR_LIT>' ) <EOL> USER_CREATE_URL = reverse ( '<STR_LIT>' ) <EOL> USER_UPDATE_URL = reverse ( '<STR_LIT>' , args = [ <NUM_LIT:1> ] ) <EOL> USER_DETAIL_URL = reverse ( '<STR_LIT>' , args = [ <NUM_LIT:1> ] ) <EOL> USER_CHANGE_PASSWORD_URL = reverse ( '<STR_LIT>' , <EOL> args = [ <NUM_LIT:1> ] ) <EOL> class UsersViewTests ( test . BaseAdminViewTests ) : <EOL> def _get_default_domain ( self ) : <EOL> domain = { "<STR_LIT:id>" : self . request . session . get ( '<STR_LIT>' , <EOL> None ) , <EOL> "<STR_LIT:name>" : self . request . session . get ( '<STR_LIT>' , <EOL> None ) } <EOL> return api . base . APIDictWrapper ( domain ) <EOL> def _get_users ( self , domain_id ) : <EOL> if not domain_id : <EOL> users = self . users . list ( ) <EOL> else : <EOL> users = [ user for user in self . users . list ( ) <EOL> if user . domain_id == domain_id ] <EOL> return users <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_index ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> users = self . _get_users ( domain_id ) <EOL> api . keystone . get_effective_domain_id ( IgnoreArg ( ) ) . AndReturn ( domain_id ) <EOL> api . keystone . user_list ( IgnoreArg ( ) , <EOL> domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { domain . id : <EOL> domain . name } ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( USERS_INDEX_URL ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertItemsEqual ( res . context [ '<STR_LIT>' ] . data , users ) <EOL> if domain_id : <EOL> for user in res . context [ '<STR_LIT>' ] . data : <EOL> self . assertItemsEqual ( user . domain_id , domain_id ) <EOL> def test_index_with_domain ( self ) : <EOL> domain = self . domains . get ( id = "<STR_LIT:1>" ) <EOL> self . setSessionValues ( domain_context = domain . id , <EOL> domain_context_name = domain . name ) <EOL> self . test_index ( ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_create ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> role = self . roles . first ( ) <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) ) . AndReturn ( domain ) <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) , False ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . user_create ( IgnoreArg ( ) , <EOL> name = user . name , <EOL> description = user . description , <EOL> email = user . email , <EOL> password = user . password , <EOL> project = self . tenant . id , <EOL> enabled = True , <EOL> domain = domain_id ) . AndReturn ( user ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( role ) <EOL> api . keystone . roles_for_user ( IgnoreArg ( ) , user . id , self . tenant . id ) <EOL> api . keystone . add_tenant_user_role ( IgnoreArg ( ) , self . tenant . id , <EOL> user . id , role . id ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : domain_id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:description>' : user . description , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT:password>' : user . password , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : self . roles . first ( ) . id , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : user . password } <EOL> res = self . client . post ( USER_CREATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> def test_create_with_domain ( self ) : <EOL> domain = self . domains . get ( id = "<STR_LIT:1>" ) <EOL> self . setSessionValues ( domain_context = domain . id , <EOL> domain_context_name = domain . name ) <EOL> self . test_create ( ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_create_with_empty_email ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:5>" ) <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> role = self . roles . first ( ) <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) ) . AndReturn ( domain ) <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) , False ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = user . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . user_create ( IgnoreArg ( ) , <EOL> name = user . name , <EOL> description = user . description , <EOL> email = user . email , <EOL> password = user . password , <EOL> project = self . tenant . id , <EOL> enabled = True , <EOL> domain = domain_id ) . AndReturn ( user ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( role ) <EOL> api . keystone . add_tenant_user_role ( IgnoreArg ( ) , self . tenant . id , <EOL> user . id , role . id ) <EOL> api . keystone . roles_for_user ( IgnoreArg ( ) , user . id , self . tenant . id ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : domain_id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:description>' : user . description , <EOL> '<STR_LIT:email>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:password>' : user . password , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : self . roles . first ( ) . id , <EOL> '<STR_LIT>' : user . password } <EOL> res = self . client . post ( USER_CREATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( success = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_create_with_password_mismatch ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) ) . MultipleTimes ( ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> if django . VERSION >= ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : domain_id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT:password>' : user . password , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : self . roles . first ( ) . id , <EOL> '<STR_LIT>' : "<STR_LIT>" } <EOL> res = self . client . post ( USER_CREATE_URL , formData ) <EOL> self . assertFormError ( res , "<STR_LIT>" , None , [ '<STR_LIT>' ] ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_create_validation_for_password_too_short ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) ) . MultipleTimes ( ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> if django . VERSION >= ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : domain_id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : self . roles . first ( ) . id , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( USER_CREATE_URL , formData ) <EOL> self . assertFormError ( <EOL> res , "<STR_LIT>" , '<STR_LIT:password>' , <EOL> [ '<STR_LIT>' ] ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_create_validation_for_password_too_long ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) ) . MultipleTimes ( ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> if django . VERSION >= ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : domain_id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . tenant . id , <EOL> '<STR_LIT>' : self . roles . first ( ) . id , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( USER_CREATE_URL , formData ) <EOL> self . assertFormError ( <EOL> res , "<STR_LIT>" , '<STR_LIT:password>' , <EOL> [ '<STR_LIT>' ] ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_update ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain_id = user . domain_id <EOL> domain = self . domains . get ( id = domain_id ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . domain_get ( IsA ( http . HttpRequest ) , <EOL> domain_id ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = user . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . user_update ( IsA ( http . HttpRequest ) , <EOL> user . id , <EOL> email = user . email , <EOL> name = user . name ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:description>' : user . description , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT>' : self . tenant . id } <EOL> res = self . client . post ( USER_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_update_default_project ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain_id = user . domain_id <EOL> domain = self . domains . get ( id = domain_id ) <EOL> new_project_id = self . tenants . get ( id = "<STR_LIT:3>" ) . id <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . domain_get ( IsA ( http . HttpRequest ) , <EOL> domain_id ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = user . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . user_update ( IsA ( http . HttpRequest ) , <EOL> user . id , <EOL> email = user . email , <EOL> name = user . name , <EOL> project = new_project_id ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:description>' : user . description , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT>' : new_project_id } <EOL> res = self . client . post ( USER_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_update_with_no_email_attribute ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:5>" ) <EOL> domain_id = user . domain_id <EOL> domain = self . domains . get ( id = domain_id ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . domain_get ( IsA ( http . HttpRequest ) , <EOL> domain_id ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = user . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . user_update ( IsA ( http . HttpRequest ) , <EOL> user . id , <EOL> email = user . email , <EOL> name = user . name , <EOL> project = self . tenant . id ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:description>' : user . description , <EOL> '<STR_LIT:email>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : self . tenant . id } <EOL> res = self . client . post ( USER_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_update_with_keystone_can_edit_user_false ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain_id = user . domain_id <EOL> domain = self . domains . get ( id = domain_id ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , <EOL> '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . domain_get ( IsA ( http . HttpRequest ) , domain_id ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain_id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = user . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . keystone_can_edit_user ( ) . AndReturn ( False ) <EOL> api . keystone . keystone_can_edit_user ( ) . AndReturn ( False ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT>' : self . tenant . id , } <EOL> res = self . client . post ( USER_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> self . assertMessageCount ( error = <NUM_LIT:1> ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_change_password ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:5>" ) <EOL> test_password = '<STR_LIT>' <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . user_update_password ( IsA ( http . HttpRequest ) , <EOL> user . id , <EOL> test_password ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:password>' : test_password , <EOL> '<STR_LIT>' : test_password } <EOL> res = self . client . post ( USER_CHANGE_PASSWORD_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> @ override_settings ( ENFORCE_PASSWORD_CHECK = True ) <EOL> def test_change_password_validation_for_admin_password ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> test_password = '<STR_LIT>' <EOL> admin_password = '<STR_LIT>' <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . user_verify_admin_password ( <EOL> IsA ( http . HttpRequest ) , admin_password ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:password>' : test_password , <EOL> '<STR_LIT>' : test_password , <EOL> '<STR_LIT>' : admin_password } <EOL> res = self . client . post ( USER_CHANGE_PASSWORD_URL , formData ) <EOL> self . assertFormError ( res , "<STR_LIT>" , None , <EOL> [ '<STR_LIT>' ] ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_update_validation_for_password_too_short ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:password>' : '<STR_LIT:t>' , <EOL> '<STR_LIT>' : '<STR_LIT:t>' } <EOL> res = self . client . post ( USER_CHANGE_PASSWORD_URL , formData ) <EOL> self . assertFormError ( <EOL> res , "<STR_LIT>" , '<STR_LIT:password>' , <EOL> [ '<STR_LIT>' ] ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_update_validation_for_password_too_long ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> res = self . client . post ( USER_CHANGE_PASSWORD_URL , formData ) <EOL> self . assertFormError ( <EOL> res , "<STR_LIT>" , '<STR_LIT:password>' , <EOL> [ '<STR_LIT>' ] ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_enable_user ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> user = self . users . get ( id = "<STR_LIT:2>" ) <EOL> users = self . _get_users ( domain_id ) <EOL> user . enabled = False <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . user_update_enabled ( IgnoreArg ( ) , <EOL> user . id , <EOL> True ) . AndReturn ( user ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { domain . id : <EOL> domain . name } ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , USERS_INDEX_URL ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_disable_user ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> user = self . users . get ( id = "<STR_LIT:2>" ) <EOL> users = self . _get_users ( domain_id ) <EOL> self . assertTrue ( user . enabled ) <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . user_update_enabled ( IgnoreArg ( ) , <EOL> user . id , <EOL> False ) . AndReturn ( user ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { domain . id : <EOL> domain . name } ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , USERS_INDEX_URL ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_enable_disable_user_exception ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> user = self . users . get ( id = "<STR_LIT:2>" ) <EOL> users = self . _get_users ( domain_id ) <EOL> user . enabled = False <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . user_update_enabled ( IgnoreArg ( ) , user . id , True ) . AndRaise ( self . exceptions . keystone ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { domain . id : <EOL> domain . name } ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData ) <EOL> self . assertRedirectsNoFollow ( res , USERS_INDEX_URL ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_disabling_current_user ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> users = self . _get_users ( domain_id ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { domain . id : <EOL> domain . name } ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % self . request . user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData , follow = True ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] . message , <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_disabling_current_user_domain_name ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domains = self . domains . list ( ) <EOL> domain_id = domain . id <EOL> users = self . _get_users ( domain_id ) <EOL> domain_lookup = dict ( ( d . id , d . name ) for d in domains ) <EOL> for u in users : <EOL> u . domain_name = domain_lookup . get ( u . domain_id ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( domain_lookup ) <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % self . request . user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData , follow = True ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] . message , <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_delete_user_with_improper_permissions ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domain_id = domain . id <EOL> users = self . _get_users ( domain_id ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { domain . id : <EOL> domain . name } ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % self . request . user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData , follow = True ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] . message , <EOL> u'<STR_LIT>' <EOL> % self . request . user . username ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_delete_user_with_improper_permissions_domain_name ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> domains = self . domains . list ( ) <EOL> domain_id = domain . id <EOL> users = self . _get_users ( domain_id ) <EOL> domain_lookup = dict ( ( d . id , d . name ) for d in domains ) <EOL> for u in users : <EOL> u . domain_name = domain_lookup . get ( u . domain_id ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = domain_id ) . AndReturn ( users ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( domain_lookup ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT:action>' : '<STR_LIT>' % self . request . user . id } <EOL> res = self . client . post ( USERS_INDEX_URL , formData , follow = True ) <EOL> self . assertEqual ( list ( res . context [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] . message , <EOL> u'<STR_LIT>' <EOL> % self . request . user . username ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , '<STR_LIT>' ) } ) <EOL> def test_detail_view ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> tenant = self . tenants . get ( id = user . project_id ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' ) . AndReturn ( user ) <EOL> api . keystone . tenant_get ( IsA ( http . HttpRequest ) , user . project_id ) . AndReturn ( tenant ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( USER_DETAIL_URL , args = [ user . id ] ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT:user>' ] . name , user . name ) <EOL> self . assertEqual ( res . context [ '<STR_LIT:user>' ] . id , user . id ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] , tenant . name ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_detail_view_with_exception ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' ) . AndRaise ( self . exceptions . keystone ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( USER_DETAIL_URL , args = [ user . id ] ) <EOL> self . assertRedirectsNoFollow ( res , USERS_INDEX_URL ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_get_update_form_init_values ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain_id = user . domain_id <EOL> domain = self . domains . get ( id = domain_id ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . domain_get ( IsA ( http . HttpRequest ) , <EOL> domain_id ) . AndReturn ( domain ) <EOL> api . keystone . tenant_list ( IgnoreArg ( ) , <EOL> domain = domain_id , <EOL> user = user . id ) . AndReturn ( [ self . tenants . list ( ) , False ] ) <EOL> self . mox . ReplayAll ( ) <EOL> res = self . client . get ( USER_UPDATE_URL ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] . value ( ) , user . name ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT:email>' ] . value ( ) , user . email ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT:description>' ] . value ( ) , <EOL> user . description ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . value ( ) , <EOL> user . project_id ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . value ( ) , <EOL> user . domain_id ) <EOL> self . assertEqual ( res . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . value ( ) , <EOL> domain . name ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) } ) <EOL> def test_update_different_description ( self ) : <EOL> user = self . users . get ( id = "<STR_LIT:1>" ) <EOL> domain_id = user . domain_id <EOL> domain = self . domains . get ( id = domain_id ) <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( user ) <EOL> api . keystone . domain_get ( IsA ( http . HttpRequest ) , <EOL> domain_id ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = domain . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = user . id ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . user_update ( IsA ( http . HttpRequest ) , <EOL> user . id , <EOL> email = user . email , <EOL> name = user . name , <EOL> description = '<STR_LIT>' ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> formData = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : user . id , <EOL> '<STR_LIT:name>' : user . name , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : user . email , <EOL> '<STR_LIT>' : self . tenant . id } <EOL> res = self . client . post ( USER_UPDATE_URL , formData ) <EOL> self . assertNoFormErrors ( res ) <EOL> class SeleniumTests ( test . SeleniumAdminTestCase ) : <EOL> def _get_default_domain ( self ) : <EOL> domain = { "<STR_LIT:id>" : None , "<STR_LIT:name>" : None } <EOL> return api . base . APIDictWrapper ( domain ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) } ) <EOL> def test_modal_create_user_with_passwords_not_matching ( self ) : <EOL> domain = self . _get_default_domain ( ) <EOL> api . keystone . get_default_domain ( IgnoreArg ( ) ) . MultipleTimes ( ) . AndReturn ( domain ) <EOL> if api . keystone . VERSIONS . active >= <NUM_LIT:3> : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , domain = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> else : <EOL> api . keystone . tenant_list ( <EOL> IgnoreArg ( ) , user = None ) . AndReturn ( <EOL> [ self . tenants . list ( ) , False ] ) <EOL> api . keystone . role_list ( IgnoreArg ( ) ) . AndReturn ( self . roles . list ( ) ) <EOL> api . keystone . user_list ( IgnoreArg ( ) , domain = None ) . AndReturn ( self . users . list ( ) ) <EOL> api . keystone . domain_lookup ( IgnoreArg ( ) ) . AndReturn ( { None : None } ) <EOL> api . keystone . get_default_role ( IgnoreArg ( ) ) . AndReturn ( self . roles . first ( ) ) <EOL> self . mox . ReplayAll ( ) <EOL> self . selenium . get ( "<STR_LIT>" % ( self . live_server_url , USERS_INDEX_URL ) ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT:\n>" ) <EOL> wait = self . ui . WebDriverWait ( self . selenium , <NUM_LIT:10> , <EOL> ignored_exceptions = [ socket_timeout ] ) <EOL> wait . until ( lambda x : self . selenium . find_element_by_id ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( self . _is_element_present ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT:test>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT>" ) <EOL> wait . until ( lambda x : self . selenium . find_element_by_id ( <EOL> "<STR_LIT>" ) ) <EOL> self . assertTrue ( self . _is_element_present ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> @ test . create_stubs ( { api . keystone : ( '<STR_LIT>' , ) } ) <EOL> def test_update_user_with_passwords_not_matching ( self ) : <EOL> api . keystone . user_get ( IsA ( http . HttpRequest ) , '<STR_LIT:1>' , <EOL> admin = True ) . AndReturn ( self . user ) <EOL> self . mox . ReplayAll ( ) <EOL> self . selenium . get ( "<STR_LIT>" % ( self . live_server_url , <EOL> USER_CHANGE_PASSWORD_URL ) ) <EOL> self . assertFalse ( self . _is_element_present ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT:test>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . send_keys ( "<STR_LIT>" ) <EOL> self . selenium . find_element_by_id ( "<STR_LIT>" ) . click ( ) <EOL> self . assertTrue ( self . _is_element_present ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> def _is_element_present ( self , element_id ) : <EOL> try : <EOL> self . selenium . find_element_by_id ( element_id ) <EOL> return True <EOL> except Exception : <EOL> return False </s>
