Beispiel #1
0
 def test_manacheck_failed_redirects_to_login_or_custom_url(self):
     request = mock.MagicMock()
     view_func = mock.MagicMock(return_value=HttpResponse())
     view = mana_check(view_func, 10)
     request.user.is_authenticated = lambda: True
     request.user.mana = 0
     response = view(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, settings.LOGIN_URL)
     view = mana_check(view_func, 10, redirect_url='/random')
     response = view(request)
     self.assertEqual(response.url, '/random')
Beispiel #2
0
 def test_decorator_can_be_applied(self):
     # The basic assumption is that most mana-related operations will be on views.
     request = mock.MagicMock()
     view_func = mock.MagicMock(return_value=HttpResponse())
     view = mana_check(view_func)
     response = view(request)
     self.assertTrue(view_func.called)
     self.assertEqual(response.status_code, 200)
Beispiel #3
0
 def test_decorated_views_require_minimum_mana_and_login(self):
     request = mock.MagicMock()
     view_func = mock.MagicMock(return_value=HttpResponse())
     view = mana_check(view_func, 10)
     # Not authenticated
     request.user.is_authenticated = lambda: False
     response = view(request)
     self.assertFalse(view_func.called)
     # Authenticated but not enough mana
     request.user.is_authenticated = lambda: True
     request.user.mana = 0
     response = view(request)
     self.assertFalse(view_func.called)
     # Authenticated and enough mana -> view called
     request.user.mana = 100
     response = view(request)
     self.assertTrue(view_func.called)