Skip to content

Commit 4e2b4bb

Browse files
authored
Merge pull request #9 from bugov/test-refact
Make tests more readable
2 parents f84136f + 55913c7 commit 4e2b4bb

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

example/some_app_login_required/tests.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def assertLoginRequiredRedirect(self):
2424
self.assertEqual(resp['location'], f'{settings.LOGIN_URL}?next={self.url}')
2525
return resp
2626

27+
28+
class TestAutoLogoutSessionTime(TestAutoLogout):
2729
def _logout_session_time(self):
2830
self.assertLoginRequiredRedirect()
2931

@@ -65,6 +67,20 @@ def test_logout_session_time_using_tz_non_utc_timedelta(self):
6567
settings.TIME_ZONE = 'Asia/Yekaterinburg'
6668
self._logout_session_time()
6769

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):
6884
def _test_logout_idle_time_no_idle(self):
6985
self.client.force_login(self.user)
7086
self.assertLoginRequiredIsOk()
@@ -96,6 +112,20 @@ def test_logout_idle_time_timedelta(self):
96112
settings.AUTO_LOGOUT = {'IDLE_TIME': timedelta(seconds=1)}
97113
self._test_logout_idle_time()
98114

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):
99129
def test_combine_idle_and_session_time(self):
100130
settings.AUTO_LOGOUT = {
101131
'IDLE_TIME': 1,
@@ -114,30 +144,6 @@ def test_combine_idle_and_session_time(self):
114144
sleep(0.5)
115145
self.assertLoginRequiredRedirect()
116146

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-
141147
def test_combine_idle_and_session_time_but_session_less_than_idle(self):
142148
settings.AUTO_LOGOUT = {
143149
'IDLE_TIME': 2,
@@ -163,6 +169,8 @@ def test_combine_idle_and_session_time_but_session_less_than_idle(self):
163169
sleep(1)
164170
self.assertLoginRequiredRedirect()
165171

172+
173+
class TestAutoLogoutMessage(TestAutoLogout):
166174
def test_message_on_auto_logout(self):
167175
settings.AUTO_LOGOUT = {
168176
'SESSION_TIME': 1,

0 commit comments

Comments
 (0)