#NEWLINE# @ pytest . mark . django_db #NEWLINE# def test_backend_for_failed_auth( monkeypatch , django_user_model ) : #NEWLINE# #INDENT# '\n    Test CAS authentication failure.\n    ' #NEWLINE# factory = RequestFactory ( ) #NEWLINE# request = factory . get ( '/login/' ) #NEWLINE# request . session = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# def mock_verify( ticket , service ) : #NEWLINE# #INDENT# return ( None , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , None ) #NEWLINE# #UNINDENT# monkeypatch . setattr ( 'cas.CASClientV2.verify_ticket' , mock_verify ) #NEWLINE# assert ( not django_user_model . objects . filter ( username = 'test@example.com' ) . exists ( ) ) #NEWLINE# backend = backends . CASBackend ( ) #NEWLINE# user = backend . authenticate ( ticket = 'fake-ticket' , service = 'fake-service' , request = request ) #NEWLINE# assert ( user is None ) #NEWLINE# assert ( not django_user_model . objects . filter ( username = 'test@example.com' ) . exists ( ) )