def test_validate_registration_token(self): registration_token = Registrations.generate_registration_token('*****@*****.**') token_email = Registrations.validate_registration_token(registration_token) self.assertEqual(token_email, '*****@*****.**') registration_token = Registrations.generate_registration_token('*****@*****.**') token_email = Registrations.validate_registration_token(registration_token) self.assertNotEqual(token_email, '*****@*****.**')
def test_with_valid_token_and_capitalized_email(self): response = self.client.get( _get_registration_token_url( Registrations.generate_registration_token("*****@*****.**") ) ) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get("email"), "*****@*****.**")
def test_with_valid_token(self): response = self.client.get( _get_registration_token_url( Registrations.generate_registration_token("*****@*****.**") ) ) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get("email"), "*****@*****.**")
def create(self, request, *args, **kwargs): """ Attempts to create a registration token and email it to the user. """ serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) email = serializer.validated_data.get('email') token = Registrations.generate_registration_token(email) send_email.delay( to_email=email, context={ "token": token, }, subject='Velkommen til Abakus.no', plain_template='users/email/registration.txt', html_template='users/email/registration.html', from_email=None ) return Response(status=status.HTTP_202_ACCEPTED)
def create_token(self, email=None): token_email = email or self.new_email return Registrations.generate_registration_token(token_email)
def test_with_valid_token_and_capitalized_email(self): response = self.client.get( _get_registration_token_url( Registrations.generate_registration_token('*****@*****.**'))) self.assertEqual(response.status_code, 200) self.assertEqual(response.data.get('email'), '*****@*****.**')
def test_with_valid_token(self): response = self.client.get( _get_registration_token_url( Registrations.generate_registration_token('*****@*****.**'))) self.assertEqual(response.status_code, 200) self.assertEqual(response.data.get('email'), '*****@*****.**')