Ejemplo n.º 1
0
def test_org_user_registers_with_email_already_in_use(
    client,
    sample_org_invite,
    mock_email_is_already_in_use,
    mock_get_user_by_email,
    mock_accept_org_invite,
    mock_add_user_to_organisation,
    mock_send_already_registered_email,
    mock_register_user
):
    invited_org_user = InvitedOrgUser(**sample_org_invite)
    with client.session_transaction() as session:
        session['invited_org_user'] = invited_org_user.serialize()

    response = client.post(url_for('main.register_from_org_invite'), data={
        'name': 'Test User',
        'mobile_number': '+4407700900460',
        'password': '******',
        'email_address': session['invited_org_user']['email_address'],
        'organisation': session['invited_org_user']['organisation']
    })

    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)

    mock_get_user_by_email.assert_called_once_with(
        session['invited_org_user']['email_address']
    )
    assert mock_register_user.called is False
    assert mock_send_already_registered_email.called is False
Ejemplo n.º 2
0
def test_registration_from_org_invite_has_bad_data(client, sample_org_invite,
                                                   data, error):
    invited_org_user = InvitedOrgUser(**sample_org_invite)
    with client.session_transaction() as session:
        session['invited_org_user'] = invited_org_user.serialize()

    response = client.post(url_for('main.register_from_org_invite'), data=data)

    assert response.status_code == 200
    assert error in response.get_data(as_text=True)
Ejemplo n.º 3
0
def test_org_user_registration(
    client,
    sample_org_invite,
    mock_email_is_not_already_in_use,
    mock_register_user,
    mock_send_verify_code,
    mock_get_user_by_email,
    mock_send_verify_email,
    mock_accept_org_invite,
    mock_add_user_to_organisation,
):
    invited_org_user = InvitedOrgUser(**sample_org_invite)
    with client.session_transaction() as session:
        session['invited_org_user'] = invited_org_user.serialize()

    response = client.post(url_for('main.register_from_org_invite'),
                           data={
                               'name':
                               'Test User',
                               'email_address':
                               session['invited_org_user']['email_address'],
                               'mobile_number':
                               '+4407700900460',
                               'password':
                               '******',
                               'organisation':
                               session['invited_org_user']['organisation']
                           })

    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)

    mock_get_user_by_email.called is False
    mock_register_user.assert_called_once_with(
        'Test User', session['invited_org_user']['email_address'],
        '+4407700900460', 'validPassword!', 'sms_auth')
    mock_send_verify_code.assert_called_once_with(
        '6ce466d0-fd6a-11e5-82f5-e0accb9d11a6',
        'sms',
        '+4407700900460',
    )
Ejemplo n.º 4
0
def test_registration_from_org_invite_has_different_email_or_organisation(
    client,
    sample_org_invite,
    diff_data
):
    invited_org_user = InvitedOrgUser(**sample_org_invite)
    with client.session_transaction() as session:
        session['invited_org_user'] = invited_org_user.serialize()

    for data in diff_data:
        session['invited_org_user'][data] = 'different'

    response = client.post(url_for('main.register_from_org_invite'), data={
        'name': 'Test User',
        'mobile_number': '+4407700900460',
        'password': '******',
        'email_address': session['invited_org_user']['email_address'],
        'organisation': session['invited_org_user']['organisation']
    })

    assert response.status_code == 400