#NEWLINE# @ raises ( AccessDenied ) #NEWLINE# def test_ensure( ) : #NEWLINE# #INDENT# @ authorization_method #NEWLINE# def authorize( user , abilities ) : #NEWLINE# #INDENT# if user . is_admin : #NEWLINE# #INDENT# abilities . append ( MANAGE , ALL ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# abilities . append ( READ , ALL ) #NEWLINE# def if_author( article ) : #NEWLINE# #INDENT# return ( article . author == user ) #NEWLINE# #UNINDENT# abilities . append ( EDIT , Article , if_author ) #NEWLINE# #UNINDENT# #UNINDENT# sally = User ( name = 'sally' , admin = False ) #NEWLINE# billy = User ( name = 'billy' , admin = True ) #NEWLINE# article = Article ( author = sally ) #NEWLINE# billys_article = Article ( author = authorize ) #NEWLINE# ensure ( sally , EDIT , billys_article )