Skip to content

Commit 5f35249

Browse files
committed
Update test_admin.py
Added test for allowing Anonymous user when using HistoryRequestMiddleware.
1 parent 1abb4f8 commit 5f35249

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

simple_history/tests/tests/test_admin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ def test_middleware_saves_user(self):
185185
self.assertEqual(historical_poll.history_user, self.user,
186186
"Middleware should make the request available to "
187187
"retrieve history_user.")
188+
189+
def test_middleware_anonymous_user(self):
190+
overridden_settings = {
191+
'MIDDLEWARE_CLASSES':
192+
settings.MIDDLEWARE_CLASSES
193+
+ ['simple_history.middleware.HistoryRequestMiddleware'],
194+
}
195+
with override_settings(**overridden_settings):
196+
poll = Poll.objects.create(question="why?", pub_date=today)
197+
historical_poll = poll.history.all()[0]
198+
self.assertEqual(historical_poll.history_user, None,
199+
"Middleware request user should be able to "
200+
"be anonymous.")
188201

189202
def test_other_admin(self):
190203
"""Test non-default admin instances.

0 commit comments

Comments
 (0)