def test_if_user_exists_already_raise_error(self, render, User): User.objects.filter.return_value = [mock.Mock()] request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret' } response = sign_up(request) render.assert_called_once_with(request, 'brent/sign-in.html', {'sign_up_email': '*****@*****.**', 'sign_up_errors': ['This email address is already registered']})
def test_raises_error_when_passwords_do_not_match(self, render, User): ''' it should raise an error when the password and password-confirmation do not match ''' request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret2' } response = sign_up(request) render.assert_called_once_with(request, 'brent/sign-in.html', {'sign_up_email': '*****@*****.**', 'sign_up_errors': ['Password confirmation does not match']}) response = render.return_value
def test_creates_user_object_with_email_and_password(self, User): ''' it should create and save a user object with the email and password provided ''' request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret' } User.objects.filter.return_value = [] response = sign_up(request) User.objects.create_user.assert_called_once_with(username='******', password='******')
def test_creates_user_object_with_email_and_password(self, User): ''' it should create and save a user object with the email and password provided ''' request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret' } User.objects.filter.return_value = [] response = sign_up(request) User.objects.create_user.assert_called_once_with( username='******', password='******')
def test_renders_sign_in_page_with_context_when_error_occurs(self, render, User): '''it should return the sign_in page with the context when sign up fails ''' request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret' } User.objects.create_user.side_effect = Exception('sign_up failure') response = sign_up(request) render.assert_called_once_with(request, 'brent/sign-in.html', {'sign_up_email': '*****@*****.**', 'sign_up_errors': ['sign_up failure']}) response = render.return_value
def test_if_user_exists_already_raise_error(self, render, User): User.objects.filter.return_value = [mock.Mock()] request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret' } response = sign_up(request) render.assert_called_once_with( request, 'brent/sign-in.html', { 'sign_up_email': '*****@*****.**', 'sign_up_errors': ['This email address is already registered'] })
def test_raises_error_when_passwords_do_not_match(self, render, User): ''' it should raise an error when the password and password-confirmation do not match ''' request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret2' } response = sign_up(request) render.assert_called_once_with( request, 'brent/sign-in.html', { 'sign_up_email': '*****@*****.**', 'sign_up_errors': ['Password confirmation does not match'] }) response = render.return_value
def test_renders_sign_in_page_with_context_when_error_occurs( self, render, User): '''it should return the sign_in page with the context when sign up fails ''' request = mock.Mock() request.POST = { 'email': '*****@*****.**', 'password': '******', 'password-confirmation': 'secret' } User.objects.create_user.side_effect = Exception('sign_up failure') response = sign_up(request) render.assert_called_once_with( request, 'brent/sign-in.html', { 'sign_up_email': '*****@*****.**', 'sign_up_errors': ['sign_up failure'] }) response = render.return_value