def auth(request): try: auth_token = AuthenticationStrategy().authenticate(request) request.session['authentication'] = auth_token except AuthenticationError: request.session['authentication'] = Authentication(None, None) return HTTPUnauthorized() if (auth_token.is_authenticated()): return HTTPFound(location=request.route_url('view_all_elections'))
def test_auth_strategy(self): request = self._get_request() request.POST['username'] = '******' request.POST['password'] = '******' auth_token = AuthenticationStrategy().authenticate(request) self.assertTrue(auth_token.is_authenticated())