def test_protect_project(self): middleware = RequireLoginMiddleware() request = HttpRequest() request.user = User() request.META["SERVER_NAME"] = "testserver" request.META["SERVER_PORT"] = "80" # No protection for not protected path self.assertIsNone(middleware.process_view(request, self.view_method, (), {})) request.path = "/project/foo/" # No protection for protected path and signed in user self.assertIsNone(middleware.process_view(request, self.view_method, (), {})) # Protection for protected path and not signed in user request.user = get_anonymous() self.assertIsInstance( middleware.process_view(request, self.view_method, (), {}), HttpResponseRedirect, ) # No protection for login and not signed in user request.path = "/accounts/login/" self.assertIsNone(middleware.process_view(request, self.view_method, (), {}))
def test_protect_project(self): middleware = RequireLoginMiddleware() request = HttpRequest() request.user = User() request.META['SERVER_NAME'] = 'testserver' request.META['SERVER_PORT'] = '80' # No protection for not protected path self.assertIsNone(middleware.process_view(request, self.view_method, (), {})) request.path = '/project/foo/' # No protection for protected path and logged in user self.assertIsNone(middleware.process_view(request, self.view_method, (), {})) # Protection for protected path and not logged in user request.user = get_anonymous() self.assertIsInstance( middleware.process_view(request, self.view_method, (), {}), HttpResponseRedirect, ) # No protection for login and not logged in user request.path = '/accounts/login/' self.assertIsNone(middleware.process_view(request, self.view_method, (), {}))
def get_request(self): request = super(RateLimitUserTest, self).get_request() request.user = User() return request
def get_request(self): request = super().get_request() request.user = User() return request