@@ -24,6 +24,8 @@ def assertLoginRequiredRedirect(self):
24
24
self .assertEqual (resp ['location' ], f'{ settings .LOGIN_URL } ?next={ self .url } ' )
25
25
return resp
26
26
27
+
28
+ class TestAutoLogoutSessionTime (TestAutoLogout ):
27
29
def _logout_session_time (self ):
28
30
self .assertLoginRequiredRedirect ()
29
31
@@ -65,6 +67,20 @@ def test_logout_session_time_using_tz_non_utc_timedelta(self):
65
67
settings .TIME_ZONE = 'Asia/Yekaterinburg'
66
68
self ._logout_session_time ()
67
69
70
+ def test_session_time_wrong_type (self ):
71
+ settings .AUTO_LOGOUT = {
72
+ 'IDLE_TIME' : 1 ,
73
+ 'SESSION_TIME' : '2' ,
74
+ }
75
+
76
+ self .client .force_login (self .user )
77
+
78
+ exc_message = "AUTO_LOGOUT['SESSION_TIME'] should be `int` or `timedelta`, not `str`."
79
+ with self .assertRaisesMessage (TypeError , exc_message ):
80
+ self .client .get (self .url )
81
+
82
+
83
+ class TestAutoLogoutIdleTime (TestAutoLogout ):
68
84
def _test_logout_idle_time_no_idle (self ):
69
85
self .client .force_login (self .user )
70
86
self .assertLoginRequiredIsOk ()
@@ -96,6 +112,20 @@ def test_logout_idle_time_timedelta(self):
96
112
settings .AUTO_LOGOUT = {'IDLE_TIME' : timedelta (seconds = 1 )}
97
113
self ._test_logout_idle_time ()
98
114
115
+ def test_idle_time_wrong_type (self ):
116
+ settings .AUTO_LOGOUT = {
117
+ 'IDLE_TIME' : '1' ,
118
+ 'SESSION_TIME' : 2 ,
119
+ }
120
+
121
+ self .client .force_login (self .user )
122
+
123
+ exc_message = "AUTO_LOGOUT['IDLE_TIME'] should be `int` or `timedelta`, not `str`."
124
+ with self .assertRaisesMessage (TypeError , exc_message ):
125
+ self .client .get (self .url )
126
+
127
+
128
+ class TestAutoLogoutCombineConfigs (TestAutoLogout ):
99
129
def test_combine_idle_and_session_time (self ):
100
130
settings .AUTO_LOGOUT = {
101
131
'IDLE_TIME' : 1 ,
@@ -114,30 +144,6 @@ def test_combine_idle_and_session_time(self):
114
144
sleep (0.5 )
115
145
self .assertLoginRequiredRedirect ()
116
146
117
- def test_session_time_config_time (self ):
118
- settings .AUTO_LOGOUT = {
119
- 'IDLE_TIME' : 1 ,
120
- 'SESSION_TIME' : '2' ,
121
- }
122
-
123
- self .client .force_login (self .user )
124
-
125
- exc_message = "AUTO_LOGOUT['SESSION_TIME'] should be `int` or `timedelta`, not `str`."
126
- with self .assertRaisesMessage (TypeError , exc_message ):
127
- self .client .get ('/login-required/' )
128
-
129
- def test_idle_time_config_time (self ):
130
- settings .AUTO_LOGOUT = {
131
- 'IDLE_TIME' : '1' ,
132
- 'SESSION_TIME' : 2 ,
133
- }
134
-
135
- self .client .force_login (self .user )
136
-
137
- exc_message = "AUTO_LOGOUT['IDLE_TIME'] should be `int` or `timedelta`, not `str`."
138
- with self .assertRaisesMessage (TypeError , exc_message ):
139
- self .client .get ('/login-required/' )
140
-
141
147
def test_combine_idle_and_session_time_but_session_less_than_idle (self ):
142
148
settings .AUTO_LOGOUT = {
143
149
'IDLE_TIME' : 2 ,
@@ -163,6 +169,8 @@ def test_combine_idle_and_session_time_but_session_less_than_idle(self):
163
169
sleep (1 )
164
170
self .assertLoginRequiredRedirect ()
165
171
172
+
173
+ class TestAutoLogoutMessage (TestAutoLogout ):
166
174
def test_message_on_auto_logout (self ):
167
175
settings .AUTO_LOGOUT = {
168
176
'SESSION_TIME' : 1 ,
0 commit comments