def test_encode_decode_pk_reversible(self): """ Ensure that encoding a PK, then decoding it returns the original value """ for i in range(50): random_pk = randint(1, 10000) encoded = encode_pk(random_pk) decoded = decode_pk(encoded) if str(random_pk) != decoded: self.fail(("Encoding then decoding PK '%d' did not return " "original value.\nEncoded: %s\tDecoded: %s") % \ (random_pk, encoded, decoded))
def _send_verification_email(request, to_email, verify_email): """ Sends an email (to to_email) containing a link to verify the target email (verify_email) as a linked email address for the user. Expects to_email as a string, and verify_email as a LinkedEmail model instance. """ subject = "Verify your email address." message = render_to_string( 'uniauth/verification-email.html', { 'protocol': get_protocol(request), 'domain': get_current_site(request), 'pk': encode_pk(verify_email.pk), 'token': token_generator.make_token(verify_email), 'query_params': _get_global_context(request)["query_params"], }) email = EmailMessage(subject, message, to=[to_email], from_email=get_setting('UNIAUTH_FROM_EMAIL')) email.send()