Fix tests broken by caching 'is user admin'
Created by: SunilMohanAdapa
@Marauderer97 , unfortunately, your patch in #803 broke a few tests. While the patch is okay, the test cases need updating. Could you please look into it?
======================================================================
ERROR: test_common (plinth.tests.test_context_processors.ContextProcessorsTestCase)
Verify that the common() function returns the correct values.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/freedombox/Plinth/plinth/tests/test_context_processors.py", line 41, in test_common
response = cp.common(request)
File "/home/travis/build/freedombox/Plinth/plinth/context_processors.py", line 46, in common
'user_is_admin': is_user_admin(request, True)
File "/home/travis/build/freedombox/Plinth/plinth/utils.py", line 60, in is_user_admin
if 'cache_user_is_admin' in request.session and cached:
AttributeError: 'HttpRequest' object has no attribute 'session'
======================================================================
ERROR: test_common_border_conditions (plinth.tests.test_context_processors.ContextProcessorsTestCase)
Verify that the common() function works for border conditions.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/freedombox/Plinth/plinth/tests/test_context_processors.py", line 68, in test_common_border_conditions
response = cp.common(request)
File "/home/travis/build/freedombox/Plinth/plinth/context_processors.py", line 46, in common
File "/home/travis/build/freedombox/Plinth/plinth/utils.py", line 60, in is_user_admin
if 'cache_user_is_admin' in request.session and cached:
AttributeError: 'HttpRequest' object has no attribute 'session'
======================================================================
ERROR: test_that_admin_view_is_allowed_for_admin_user (plinth.tests.test_middleware.TestAdminMiddleware)
Test that admin user is allowed for an admin view
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/freedombox/Plinth/plinth/tests/test_middleware.py", line 173, in test_that_admin_view_is_allowed_for_admin_user
response = self.middleware.process_view(self.request, **self.kwargs)
File "/home/travis/build/freedombox/Plinth/plinth/middleware.py", line 105, in process_view
if not is_user_admin(request):
File "/home/travis/build/freedombox/Plinth/plinth/utils.py", line 60, in is_user_admin
if 'cache_user_is_admin' in request.session and cached:
AttributeError: 'WSGIRequest' object has no attribute 'session'
======================================================================
ERROR: test_that_admin_view_is_denied_for_usual_user (plinth.tests.test_middleware.TestAdminMiddleware)
Test that normal user is denied for an admin view
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/freedombox/Plinth/plinth/tests/test_middleware.py", line 167, in test_that_admin_view_is_denied_for_usual_user
self.request, **self.kwargs)
File "/usr/lib/python3.4/unittest/case.py", line 704, in assertRaises
return context.handle('assertRaises', callableObj, args, kwargs)
File "/usr/lib/python3.4/unittest/case.py", line 162, in handle
callable_obj(*args, **kwargs)
File "/home/travis/build/freedombox/Plinth/plinth/middleware.py", line 105, in process_view
if not is_user_admin(request):
File "/home/travis/build/freedombox/Plinth/plinth/utils.py", line 60, in is_user_admin
if 'cache_user_is_admin' in request.session and cached:
AttributeError: 'WSGIRequest' object has no attribute 'session'
----------------------------------------------------------------------