#NEWLINE# def test_protected_role( ) : #NEWLINE# #INDENT# ( auth , app , user ) = get_flask_app ( roles = True ) #NEWLINE# client = app . test_client ( ) #NEWLINE# @ app . route ( '/admin1/' ) #NEWLINE# @ auth . protected ( role = 'admin' ) #NEWLINE# def admin1( ) : #NEWLINE# #INDENT# return 'admin1' #NEWLINE# #UNINDENT# @ app . route ( '/admin2/' ) #NEWLINE# @ auth . protected ( roles = [ 'editor' , 'admin' ] ) #NEWLINE# def admin2( ) : #NEWLINE# #INDENT# return 'admin2' #NEWLINE# #UNINDENT# client . get ( '/login/' ) #NEWLINE# resp = client . get ( '/admin1/' ) #NEWLINE# assert ( resp . status == '403 FORBIDDEN' ) #NEWLINE# resp = client . get ( '/admin2/' ) #NEWLINE# assert ( resp . status == '403 FORBIDDEN' ) #NEWLINE# user . add_role ( 'admin' ) #NEWLINE# auth . db . commit ( ) #NEWLINE# client . get ( '/login/' ) #NEWLINE# resp = client . get ( '/admin1/?r=123/' ) #NEWLINE# assert ( resp . status == '200 OK' ) #NEWLINE# assert ( resp . data == b'admin1' ) #NEWLINE# resp = client . get ( '/admin2/?r=456/' ) #NEWLINE# print ( user . roles . all ( ) ) #NEWLINE# assert ( resp . status == '200 OK' ) #NEWLINE# assert ( resp . data == b'admin2' )