Example #1
0
def test_facebook(client, db, facebook_auth):
    # Step 1: login
    response = client.get('/login/facebook/')
    assert response.status_code == 302
    assert 'facebook.com' in response['Location']

    # Step 2: returning from facebook
    state = re.search(r'state=([^&]+)', response['Location']).group(1)
    data = {
        'redirect_state': state,
        'code': 'test_code',
        'state': state,
    }
    response = client.get('/complete/facebook/', data=data)
    assert response.status_code == 302
    assert response['Location'].endswith('/register/details/')

    # Step 3: complete profile
    profile_data = profile_complete_form_data(email='*****@*****.**')
    response = client.post('/register/details/', data=profile_data)
    assert response.status_code == 302
    assert response['Location'].endswith('/complete/facebook/')
    assert 'details' in client.session['partial_pipeline']['kwargs']
    assert client.session['partial_pipeline']['kwargs']['details']['email'] == '*****@*****.**'

    # Step 4: complete
    response = client.get('/complete/facebook/')
    assert response.status_code == 302
    assert response['Location'] == 'http://testserver/'

    # We did send out an email validation mail
    assert Code.objects.all().count() == 1
    assert len(mail.outbox) == 1
    assert len(get_messages_from_cookie(response.cookies)) == 1

    user = User.objects.get(social_auth__uid='12345')
    assert user.is_active
    assert not user.email_verified

    # Step 5: Complete email validation
    code = Code.objects.all().get()
    response = client.get('/register/confirm_email/%s/' % code.code)
    assert response.status_code == 302
    assert response['Location'] == 'http://testserver/'

    # Check data
    user = User.objects.get(social_auth__uid='12345')
    assert user.is_active
    assert user.email_verified
    assert user.social_auth.get(provider='facebook')
    assert SESSION_KEY in client.session
Example #2
0
def test_twitter(client, db, twitter_auth):
    # Step 1: login
    response = client.get('/login/twitter/')
    assert response.status_code == 302
    assert 'twitter.com' in response['Location']
    data = {
        'oauth_token': twitter_auth['oauth_token'],
        'oauth_verifier': 'test_oauth_verifier'
    }

    # Step 2: returning from twitter
    response = client.get('/complete/twitter/', data=data)
    assert response.status_code == 302
    assert response['Location'].endswith('/register/details/')

    # Step 3: complete profile
    profile_data = profile_complete_form_data(email='*****@*****.**')
    response = client.post('/register/details/', data=profile_data)
    assert response.status_code == 302
    assert response['Location'].endswith('/complete/twitter/')
    assert 'details' in client.session['partial_pipeline']['kwargs']
    assert client.session['partial_pipeline']['kwargs']['details']['email'] == '*****@*****.**'

    # Step 4: complete
    response = client.get('/complete/twitter/')
    assert response.status_code == 302
    assert response['Location'] == 'http://testserver/'

    # We did send out an email validation mail
    assert Code.objects.all().count() == 1
    assert len(mail.outbox) == 1
    assert len(get_messages_from_cookie(response.cookies)) == 1

    user = User.objects.get(social_auth__uid='12345')
    assert user.is_active
    assert not user.email_verified

    # Step 5: Complete email validation
    code = Code.objects.all().get()
    response = client.get('/register/confirm_email/%s/' % code.code)
    assert response.status_code == 302
    assert response['Location'] == 'http://testserver/'

    # Check data
    user = User.objects.get(social_auth__uid='12345')
    assert user.is_active
    assert user.email_verified
    assert user.social_auth.get(provider='twitter')
    assert SESSION_KEY in client.session
Example #3
0
def test_username_handle_social_exception(do_complete_mock, client, db):
    do_complete_mock.side_effect = SocialAuthBaseException('test123')

    # Step 1: login
    response = client.get('/login/')
    assert response.status_code == 200

    user = UserFactory.create(usersocialauth='username')

    # Step 2: enter all data
    data = {
        'username': user.username,
        'password': '******',
    }

    response = client.post('/login/', data=data)
    assert response.status_code == 302
    assert len(get_messages_from_cookie(response.cookies)) == 1
Example #4
0
def test_username_registration(client, db):
    # Step 1: login
    response = client.get('/register/')
    assert response.status_code == 200

    # Step 2: enter all data
    data = {
        'username': '******',
        'email': '*****@*****.**',
        'password1': 'pass12',
        'password2': 'pass12',
    }
    response = client.post('/register/', data=data)
    assert response.status_code == 302

    # For username backend we already have all the information we need
    # in the initial form.
    assert not response['Location'].endswith('/register/details/')

    assert response.status_code == 302
    assert response['Location'] == 'http://testserver/'

    # We did send out an email validation mail
    assert Code.objects.all().count() == 1
    assert len(mail.outbox) == 1
    assert len(get_messages_from_cookie(response.cookies)) == 1

    user = User.objects.get(social_auth__uid='foo')
    assert user.is_active
    assert not user.email_verified

    # Step 5: Complete email validation
    code = Code.objects.all().get()
    response = client.get('/register/confirm_email/%s/' % code.code)
    assert response.status_code == 302
    assert response['Location'] == 'http://testserver/'

    # Check data
    user = User.objects.get(social_auth__uid='foo')
    assert user.is_active
    assert user.email_verified
    assert user.social_auth.get(provider='username')
    assert SESSION_KEY in client.session