Ejemplo n.º 1
0
def test_authentication_method(app, db, rf, hooks):
    activation_url = utils.build_activation_url(
        rf.post('/accounts/register/'),
        email='*****@*****.**',
        next_url='/',
        first_name='John',
        last_name='Doe',
        no_password=True,
        confirm_data=False)
    app.get(activation_url)

    assert len(hooks.calls['event']) == 2
    assert hooks.calls['event'][-2]['kwargs']['name'] == 'registration'
    assert hooks.calls['event'][-2]['kwargs']['authentication_method'] == 'email'
    assert hooks.calls['event'][-1]['kwargs']['name'] == 'login'
    assert hooks.calls['event'][-1]['kwargs']['how'] == 'email'

    activation_url = utils.build_activation_url(
        rf.post('/accounts/register/'),
        email='*****@*****.**',
        next_url='/',
        first_name='Jane',
        last_name='Doe',
        no_password=True,
        authentication_method='another',
        confirm_data=False)
    app.get(activation_url)

    assert len(hooks.calls['event']) == 4
    assert hooks.calls['event'][-2]['kwargs']['name'] == 'registration'
    assert hooks.calls['event'][-2]['kwargs']['authentication_method'] == 'another'
    assert hooks.calls['event'][-1]['kwargs']['name'] == 'login'
    assert hooks.calls['event'][-1]['kwargs']['how'] == 'another'
Ejemplo n.º 2
0
def test_revalidate_email(app, rf, db, settings, mailoutbox):
    settings.LANGUAGE_CODE = 'en-us'
    settings.A2_VALIDATE_EMAIL_DOMAIN = can_resolve_dns()

    # disable existing attributes
    models.Attribute.objects.update(disabled=True)
    url = utils.build_activation_url(
        rf.get('/'),
        '*****@*****.**',
        next_url=None,
        valid_email=False,
        franceconnect=True)

    assert len(mailoutbox) == 0
    # register
    response = app.get(url)
    response.form.set('email', '*****@*****.**')
    response.form.set('password1', 'T0==toto')
    response.form.set('password2', 'T0==toto')
    response = response.form.submit()
    assert urlparse(response['Location']).path == reverse('registration_complete')
    response = response.follow()
    assert '2 days' in response.content
    assert '*****@*****.**' in response.content
    assert len(mailoutbox) == 1
Ejemplo n.º 3
0
def test_registration_confirm_data(app, settings, db, rf):
    # make first name not required
    models.Attribute.objects.filter(
        name='first_name').update(
            required=False)

    activation_url = utils.build_activation_url(
        rf.post('/accounts/register/'),
        email='*****@*****.**',
        next_url='/',
        first_name='John',
        last_name='Doe',
        no_password=True,
        confirm_data=False)

    response = app.get(activation_url, status=302)

    activation_url = utils.build_activation_url(
        rf.post('/accounts/register/'),
        email='*****@*****.**',
        next_url='/',
        last_name='Doe',
        no_password=True,
        confirm_data=False)

    response = app.get(activation_url, status=200)
    assert 'form' in response.context
    assert set(response.context['form'].fields.keys()) == set(['first_name', 'last_name'])

    activation_url = utils.build_activation_url(
        rf.post('/accounts/register/'),
        email='*****@*****.**',
        next_url='/',
        last_name='Doe',
        no_password=True,
        confirm_data='required')
    response = app.get(activation_url, status=302)
Ejemplo n.º 4
0
def test_email_is_unique_multiple_objects_returned(app, db, settings, mailoutbox, rf):
    settings.LANGUAGE_CODE = 'en-us'
    settings.A2_VALIDATE_EMAIL_DOMAIN = can_resolve_dns()
    settings.A2_REGISTRATION_EMAIL_IS_UNIQUE = True

    # Create two user objects
    User = get_user_model()
    User.objects.create(email='*****@*****.**')
    User.objects.create(email='*****@*****.**')

    url = utils.build_activation_url(
        rf.get('/'),
        '*****@*****.**',
        first_name='Test',
        last_name='Bot',
        password='******',
        next_url=None,
        valid_email=False,
        franceconnect=True)

    response = app.get(url)
    assert 'This email address is already in use.' in response.content