def test_can_properly_consume_the_token(self): # Setup actions.register(TestAction) token = AccountActionTokenFactory.create(action='test-consumed') form_data = { 'username': faker.simple_profile().get('username'), 'email': faker.email(), 'first_name': faker.first_name(), 'last_name': faker.last_name(), 'password1': 'not_secret', 'password2': 'not_secret', } # Run & check form = AccountActionRegisterForm(form_data, token=token) self.assertTrue(form.is_valid()) form.save() global consumed self.assertTrue(consumed)
def test_cannot_be_validated_if_a_user_with_the_same_email_address_already_exists(self): # Setup User.objects.create_user( username='******', password='******', email='*****@*****.**') token = AccountActionTokenFactory.create(email='*****@*****.**') form_data = { 'username': faker.simple_profile().get('username'), 'email': '*****@*****.**', 'first_name': faker.first_name(), 'last_name': faker.last_name(), 'password1': 'not_secret', 'password2': 'not_secret', } # Run form = AccountActionRegisterForm(form_data, token=token) # Check self.assertFalse(form.is_valid()) self.assertTrue('email' in form.errors)
def test_cannot_be_validated_if_a_user_with_the_same_email_address_already_exists( self): # Setup User.objects.create_user(username='******', password='******', email='*****@*****.**') token = AccountActionTokenFactory.create(email='*****@*****.**') form_data = { 'username': faker.simple_profile().get('username'), 'email': '*****@*****.**', 'first_name': faker.first_name(), 'last_name': faker.last_name(), 'password1': 'not_secret', 'password2': 'not_secret', } # Run form = AccountActionRegisterForm(form_data, token=token) # Check self.assertFalse(form.is_valid()) self.assertTrue('email' in form.errors)
def test_can_properly_create_a_user(self): # Setup token = AccountActionTokenFactory.create() form_data = { 'username': faker.simple_profile().get('username'), 'email': faker.email(), 'first_name': faker.first_name(), 'last_name': faker.last_name(), 'password1': 'not_secret', 'password2': 'not_secret', } # Run & check form = AccountActionRegisterForm(form_data, token=token) self.assertTrue(form.is_valid()) form.save() user = User.objects.first() self.assertEqual(user.username, form_data['username']) self.assertEqual(user.email, form_data['email']) self.assertEqual(user.first_name, form_data['first_name']) self.assertEqual(user.last_name, form_data['last_name']) self.assertTrue(user.check_password('not_secret'))