def test_register_from_invite_when_user_registers_in_another_browser(
    client,
    api_user_active,
    mock_get_user_by_email,
    mock_accept_invite,
):
    invited_user = InvitedUser(
        {
            'id': api_user_active['id'],
            'service': api_user_active['id'],
            'from_user': "",
            'email_address': api_user_active['email_address'],
            'permissions': ["manage_users"],
            'status': "pending",
            'created_at': datetime.utcnow(),
            'auth_type': 'sms_auth',
            'folder_permissions': [],
            'blocked': False
        }
    )
    with client.session_transaction() as session:
        session['invited_user'] = invited_user.serialize()
    response = client.post(
        url_for('main.register_from_invite'),
        data={
            'name': 'Registered in another Browser',
            'email_address': api_user_active['email_address'],
            'mobile_number': api_user_active['mobile_number'],
            'service': str(api_user_active['id']),
            'password': '******',
            'auth_type': 'sms_auth'
        }
    )
    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)
def test_register_from_invite_when_user_registers_in_another_browser(
    client,
    api_user_active,
    mock_get_user_by_email,
    mock_accept_invite,
):
    invited_user = InvitedUser(api_user_active.id, api_user_active.id, "",
                               api_user_active.email_address,
                               ["manage_users"],
                               "pending",
                               datetime.utcnow(),
                               'sms_auth',
                               [])
    with client.session_transaction() as session:
        session['invited_user'] = invited_user.serialize()
    response = client.post(
        url_for('main.register_from_invite'),
        data={
            'name': 'Registered in another Browser',
            'email_address': api_user_active.email_address,
            'mobile_number': api_user_active.mobile_number,
            'service': str(api_user_active.id),
            'password': '******',
            'auth_type': 'sms_auth'
        }
    )
    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)
def test_register_from_invite(
    client,
    fake_uuid,
    mock_email_is_not_already_in_use,
    mock_register_user,
    mock_send_verify_code,
    mock_accept_invite,
):
    invited_user = InvitedUser(
        {
            'id': fake_uuid,
            'service': fake_uuid,
            'from_user': "",
            'email_address': "*****@*****.**",
            'permissions': ["manage_users"],
            'status': "pending",
            'created_at': datetime.utcnow(),
            'auth_type': 'sms_auth',
            'folder_permissions': [],
            'blocked': True
        }
    )
    with client.session_transaction() as session:
        session['invited_user'] = invited_user.serialize()
    response = client.post(
        url_for('main.register_from_invite'),
        data={
            'name': 'Registered in another Browser',
            'email_address': invited_user.email_address,
            'mobile_number': '+16502532222',
            'service': str(invited_user.id),
            'password': '******',
            'auth_type': 'sms_auth'
        }
    )
    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)
    mock_register_user.assert_called_once_with(
        'Registered in another Browser',
        invited_user.email_address,
        '+16502532222',
        'rZXdoBkuz6U37DDXIaAfpBR1OTJcSZOGICLCz4dMtmopS3KsVauIrtcgqs1eU02',
        'sms_auth',
    )
def test_register_from_invite(
    client,
    fake_uuid,
    mock_email_is_not_already_in_use,
    mock_register_user,
    mock_send_verify_code,
    mock_accept_invite,
):
    invited_user = InvitedUser({
        "id": fake_uuid,
        "service": fake_uuid,
        "from_user": "",
        "email_address": "*****@*****.**",
        "permissions": ["manage_users"],
        "status": "pending",
        "created_at": datetime.utcnow(),
        "auth_type": "sms_auth",
        "folder_permissions": [],
        "blocked": True,
    })
    with client.session_transaction() as session:
        session["invited_user"] = invited_user.serialize()
    response = client.post(
        url_for("main.register_from_invite"),
        data={
            "name": "Registered in another Browser",
            "email_address": invited_user.email_address,
            "mobile_number": "+16502532222",
            "service": str(invited_user.id),
            "password":
            "******",
            "auth_type": "sms_auth",
        },
    )
    assert response.status_code == 302
    assert response.location == url_for("main.verify", _external=True)
    mock_register_user.assert_called_once_with(
        "Registered in another Browser",
        invited_user.email_address,
        "+16502532222",
        "rZXdoBkuz6U37DDXIaAfpBR1OTJcSZOGICLCz4dMtmopS3KsVauIrtcgqs1eU02",
        "sms_auth",
    )
def test_register_from_invite_when_user_registers_in_another_browser(
    client,
    api_user_active,
    mock_get_user_by_email,
    mock_accept_invite,
):
    invited_user = InvitedUser({
        "id":
        api_user_active["id"],
        "service":
        api_user_active["id"],
        "from_user":
        "",
        "email_address":
        api_user_active["email_address"],
        "permissions": ["manage_users"],
        "status":
        "pending",
        "created_at":
        datetime.utcnow(),
        "auth_type":
        "sms_auth",
        "folder_permissions": [],
        "blocked":
        False,
    })
    with client.session_transaction() as session:
        session["invited_user"] = invited_user.serialize()
    response = client.post(
        url_for("main.register_from_invite"),
        data={
            "name": "Registered in another Browser",
            "email_address": api_user_active["email_address"],
            "mobile_number": api_user_active["mobile_number"],
            "service": str(api_user_active["id"]),
            "password":
            "******",
            "auth_type": "sms_auth",
        },
    )
    assert response.status_code == 302
    assert response.location == url_for("main.verify", _external=True)
def test_register_from_invite(
    client,
    fake_uuid,
    mock_email_is_not_already_in_use,
    mock_register_user,
    mock_send_verify_code,
    mock_accept_invite,
    extra_data,
):
    invited_user = InvitedUser({
        'id': fake_uuid,
        'service': fake_uuid,
        'from_user': "",
        'email_address': "*****@*****.**",
        'permissions': ["manage_users"],
        'status': "pending",
        'created_at': datetime.utcnow(),
        'auth_type': 'sms_auth',
        'folder_permissions': [],
    })
    with client.session_transaction() as session:
        session['invited_user'] = invited_user.serialize()
    response = client.post(
        url_for('main.register_from_invite'),
        data=dict(name='Registered in another Browser',
                  email_address=invited_user.email_address,
                  mobile_number='+4407700900460',
                  service=str(invited_user.id),
                  password='******',
                  auth_type='sms_auth',
                  **extra_data),
    )
    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)
    mock_register_user.assert_called_once_with(
        'Registered in another Browser',
        invited_user.email_address,
        '+4407700900460',
        'somreallyhardthingtoguess',
        'sms_auth',
    )
def test_register_from_invite(
    client,
    fake_uuid,
    mock_email_is_not_already_in_use,
    mock_register_user,
    mock_send_verify_code,
    mock_accept_invite,
):
    invited_user = InvitedUser(fake_uuid, fake_uuid, "",
                               "*****@*****.**",
                               ["manage_users"],
                               "pending",
                               datetime.utcnow(),
                               'sms_auth',
                               [])
    with client.session_transaction() as session:
        session['invited_user'] = invited_user.serialize()
    response = client.post(
        url_for('main.register_from_invite'),
        data={
            'name': 'Registered in another Browser',
            'email_address': invited_user.email_address,
            'mobile_number': '+4407700900460',
            'service': str(invited_user.id),
            'password': '******',
            'auth_type': 'sms_auth'
        }
    )
    assert response.status_code == 302
    assert response.location == url_for('main.verify', _external=True)
    mock_register_user.assert_called_once_with(
        'Registered in another Browser',
        invited_user.email_address,
        '+4407700900460',
        'somreallyhardthingtoguess',
        'sms_auth',
    )