1- # -- coding: utf-8 --
2-
1+ # encoding: utf-8
32from __future__ import unicode_literals
43from django .conf .urls import patterns , url
5- from io import BytesIO
6-
74from django .contrib .auth .models import User
85from django .shortcuts import redirect
96from django .test import TestCase
107from rest_framework .decorators import api_view
118from rest_framework .response import Response
129from rest_framework .test import APIClient , APIRequestFactory , force_authenticate
10+ from io import BytesIO
1311
1412
1513@api_view (['GET' , 'POST' ])
@@ -109,7 +107,7 @@ def test_explicitly_enforce_csrf_checks(self):
109107
110108 def test_can_logout (self ):
111109 """
112- `logout()` reset stored credentials
110+ `logout()` resets stored credentials
113111 """
114112 self .client .credentials (HTTP_AUTHORIZATION = 'example' )
115113 response = self .client .get ('/view/' )
@@ -118,6 +116,18 @@ def test_can_logout(self):
118116 response = self .client .get ('/view/' )
119117 self .assertEqual (response .data ['auth' ], b'' )
120118
119+ def test_logout_resets_force_authenticate (self ):
120+ """
121+ `logout()` resets any `force_authenticate`
122+ """
123+ user = User .
objects .
create_user (
'example' ,
'[email protected] ' ,
'password' )
124+ self .client .force_authenticate (user )
125+ response = self .client .get ('/view/' )
126+ self .assertEqual (response .data ['user' ], 'example' )
127+ self .client .logout ()
128+ response = self .client .get ('/view/' )
129+ self .assertEqual (response .data ['user' ], '' )
130+
121131 def test_follow_redirect (self ):
122132 """
123133 Follow redirect by setting follow argument.
0 commit comments