def test_get_with_an_unauthenticated_user_renders_sign_in_sign_up_form(self, render, login, authenticate): request = mock.Mock() request.method = 'GET' request.user = mock.Mock() request.user.is_authenticated.return_value = False response = sign_in(request) render.assert_called_once_with(request, 'brent/sign-in.html')
def test_get_with_an_unauthenticated_user_renders_sign_in_sign_up_form( self, render, login, authenticate): request = mock.Mock() request.method = 'GET' request.user = mock.Mock() request.user.is_authenticated.return_value = False response = sign_in(request) render.assert_called_once_with(request, 'brent/sign-in.html')
def test_successful_authentication_logs_in_user(self, login, authenticate): request = mock.Mock() request.method = 'POST' request.POST = mock.Mock(__getitem__=mock.Mock()) user = mock.Mock() authenticate.return_value = user response = sign_in(request) login.assert_called_once_with(request, user)
def test_get_with_an_authenticated_user_without_permissions_redirects_to_user_permissions(self, redirect, login, authenticate): request = mock.Mock() request.method = 'GET' request.user = mock.Mock() request.user.is_authenticated.return_value = True request.user.has_perm.return_value = False response = sign_in(request) redirect.assert_called_once_with('/brent/user-permissions')
def test_get_with_an_authenticated_user_without_permissions_redirects_to_user_permissions( self, redirect, login, authenticate): request = mock.Mock() request.method = 'GET' request.user = mock.Mock() request.user.is_authenticated.return_value = True request.user.has_perm.return_value = False response = sign_in(request) redirect.assert_called_once_with('/brent/user-permissions')
def test_get_with_an_authenticated_user_with_permissions_redirect_to_homepage(self, redirect, login, authenticate): request = mock.Mock() request.method = 'GET' request.user = mock.Mock() request.user.is_authenticated.return_value = True request.user.has_perm.return_value = True response = sign_in(request) request.user.has_perm.assert_called_once_with('opentrv_sensor.view_measurement') redirect.assert_called_once_with('/brent')
def test_get_with_an_authenticated_user_with_permissions_redirect_to_homepage( self, redirect, login, authenticate): request = mock.Mock() request.method = 'GET' request.user = mock.Mock() request.user.is_authenticated.return_value = True request.user.has_perm.return_value = True response = sign_in(request) request.user.has_perm.assert_called_once_with( 'opentrv_sensor.view_measurement') redirect.assert_called_once_with('/brent')