def test_pre_registration_send_sms_code(client, mocker, User, before_registration_window): email = '*****@*****.**' phone_number = '5554443333' token = generate_pre_registration_token(email) url = reverse_registration_url(email, phone_number) url = '?'.join(( url, urllib.urlencode({'token': token}), )) target_url = reverse('dashboard') send_twilio_sms = mocker.patch('ladder.apps.accounts.utils.send_twilio_sms') response = client.post(url) target_url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) target_url = '?'.join(( target_url, urllib.urlencode({'token': token}), )) assert response.get('location', '').endswith(target_url)
def test_registration_confirm_phone_number(client, mocker, active_registration_window): email = '*****@*****.**' phone_number = '5554443333' url = reverse_registration_url(email, phone_number) send_twilio_sms = mocker.patch( 'ladder.apps.accounts.utils.send_twilio_sms') response = client.post(url) target_url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) assert response.get('location', '').endswith(target_url) assert send_twilio_sms.called message = send_twilio_sms.call_args[0][1] code = generate_phone_number_code(phone_number) formatted_code = "{0} {1}".format(code[:3], code[3:]) assert formatted_code in message
def test_pre_registration_phone_confirmation_step(client, mocker, User, before_registration_window): email = '*****@*****.**' phone_number = '5554443333' token = generate_pre_registration_token(email) url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) url = '?'.join(( url, urllib.urlencode({'token': token}), )) target_url = reverse('dashboard') code = generate_phone_number_code(phone_number) response = client.post(url, { 'sms_code': code, 'display_name': 'test-display_name', 'password': '******', }) assert response.get('location', '').endswith(target_url) assert User.objects.filter(email=email).exists()
def test_pre_registration_send_sms_code(client, mocker, User, before_registration_window): email = '*****@*****.**' phone_number = '5554443333' token = generate_pre_registration_token(email) url = reverse_registration_url(email, phone_number) url = '?'.join(( url, urllib.urlencode({'token': token}), )) target_url = reverse('dashboard') send_twilio_sms = mocker.patch( 'ladder.apps.accounts.utils.send_twilio_sms') response = client.post(url) target_url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) target_url = '?'.join(( target_url, urllib.urlencode({'token': token}), )) assert response.get('location', '').endswith(target_url)
def test_initiate_registration(client, mocker, active_registration_window): url = reverse('register') email = '*****@*****.**' phone_number = '5554443333' token = generate_registration_token(email, phone_number) mocker.patch('django.core.signing.dumps', return_value=token) response = client.post( url, { 'email': '*****@*****.**', 'phone_number': '555-444-3333', # The form takes care of formatting. }) target_url = reverse('register-success') assert response.get('location', '').endswith(target_url) assert len(mail.outbox) == 1 message = mail.outbox[0] p1, p2, p3 = token.split(':') assert p1 in message.body assert p2 in message.body assert p3 in message.body
def test_pre_registration_phone_confirmation_step(client, mocker, User, before_registration_window): email = '*****@*****.**' phone_number = '5554443333' token = generate_pre_registration_token(email) url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) url = '?'.join(( url, urllib.urlencode({'token': token}), )) target_url = reverse('dashboard') code = generate_phone_number_code(phone_number) response = client.post( url, { 'sms_code': code, 'display_name': 'test-display_name', 'password': '******', }) assert response.get('location', '').endswith(target_url) assert User.objects.filter(email=email).exists()
def test_initiate_registration(client, mocker, active_registration_window): url = reverse('register') email = '*****@*****.**' phone_number = '5554443333' token = generate_registration_token(email, phone_number) mocker.patch('django.core.signing.dumps', return_value=token) response = client.post(url, { 'email': '*****@*****.**', 'phone_number': '555-444-3333', # The form takes care of formatting. }) target_url = reverse('register-success') assert response.get('location', '').endswith(target_url) assert len(mail.outbox) == 1 message = mail.outbox[0] p1, p2, p3 = token.split(':') assert p1 in message.body assert p2 in message.body assert p3 in message.body
def test_registration_link_reversing(frozen_now): email = '*****@*****.**' phone = '555-444-3333' token = generate_registration_token(email, phone) path = reverse_registration_url(email, phone) p1, p2, p3 = token.split(':') assert p1 in path assert p2 in path assert p3 in path
def test_token_unsigning(): email = '*****@*****.**' phone = '555-444-3333' token = generate_registration_token(email, phone) assert token unsigned_email, unsigned_phone = unsign_registration_token(token) assert unsigned_email == email assert unsigned_phone == phone
def test_registration_link_reversing(frozen_now): email = '*****@*****.**' phone = '555-444-3333' token = generate_registration_token(email, phone) path = reverse_registration_url(email, phone) p1, p2, p3 = token.split(':') assert p1 in path assert p2 in path assert p3 in path
def test_token_unsigning(): email = '*****@*****.**' phone = '555-444-3333' token = generate_registration_token(email, phone) assert token unsigned_email, unsigned_phone = unsign_registration_token(token) assert unsigned_email == email assert unsigned_phone == phone
def test_registration_special_case_regression(User, client, factories, active_registration_window): factories.UserWithProfileFactory(_profile__phone_number='') email = '*****@*****.**' phone_number = '5554443333' url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) target_url = reverse('dashboard') code = generate_phone_number_code(phone_number) response = client.post( url, { 'sms_code': code, 'display_name': 'test-display_name', 'password': '******', }) assert response.get('location', '').endswith(target_url) assert User.objects.filter(email=email).exists() user = User.objects.get(email=email) assert user.check_password('secret') assert user.is_active assert client.login( username=user.email, password='******', ) assert user.is_active assert user.display_name == 'test-display_name' assert user.profile.phone_number == phone_number
def test_registration_special_case_regression(User, client, factories, active_registration_window): factories.UserWithProfileFactory(_profile__phone_number='') email = '*****@*****.**' phone_number = '5554443333' url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) target_url = reverse('dashboard') code = generate_phone_number_code(phone_number) response = client.post(url, { 'sms_code': code, 'display_name': 'test-display_name', 'password': '******', }) assert response.get('location', '').endswith(target_url) assert User.objects.filter(email=email).exists() user = User.objects.get(email=email) assert user.check_password('secret') assert user.is_active assert client.login( username=user.email, password='******', ) assert user.is_active assert user.display_name == 'test-display_name' assert user.profile.phone_number == phone_number
def test_registration_confirm_phone_number(client, mocker, active_registration_window): email = '*****@*****.**' phone_number = '5554443333' url = reverse_registration_url(email, phone_number) send_twilio_sms = mocker.patch('ladder.apps.accounts.utils.send_twilio_sms') response = client.post(url) target_url = reverse( 'register-verify-phone-number', kwargs={ 'token': generate_registration_token(email, phone_number), }, ) assert response.get('location', '').endswith(target_url) assert send_twilio_sms.called message = send_twilio_sms.call_args[0][1] code = generate_phone_number_code(phone_number) formatted_code = "{0} {1}".format(code[:3], code[3:]) assert formatted_code in message