#NEWLINE# def test_auth_required( rf ) : #NEWLINE# #INDENT# class RestrictedPersonViewSet ( PersonViewSet ) : #NEWLINE# #INDENT# permission_classes = [ IsAuthenticated ] #NEWLINE# #UNINDENT# data = dump_json ( { #NEWLINE# #INDENT# 'people' : { #NEWLINE# #INDENT# 'name' : 'Jason Api' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# request = rf . post ( reverse ( 'person-list' ) , data = data , content_type = 'application/vnd.api+json' ) #NEWLINE# view = RestrictedPersonViewSet . as_view ( { #NEWLINE# #INDENT# 'post' : 'create' , #NEWLINE# #UNINDENT# } ) #NEWLINE# response = view ( request ) #NEWLINE# response . render ( ) #NEWLINE# assert ( response . status_code == 403 ) , request . content #NEWLINE# assert ( not models . Person . objects . exists ( ) ) #NEWLINE# results = { #NEWLINE# #INDENT# 'errors' : [ { #NEWLINE# #INDENT# 'status' : '403' , #NEWLINE# 'title' : 'Authentication credentials were not provided.' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# assert ( response . content == dump_json ( results ) )