Exemplo n.º 1
0
def test_create_user_with_profile(dao: Dao, user_without_profile):

    user = dao.create_user_with_profile(
        user_without_profile.username,
        provider="github",
        identity_id="1",
        name="new user",
        avatar_url="http://avatar",
        emails=None,
        role=None,
        exist_ok=True,
    )

    assert user.profile

    with pytest.raises(IntegrityError):
        dao.create_user_with_profile(
            user_without_profile.username,
            provider="github",
            identity_id="1",
            name="new user",
            avatar_url="http://avatar",
            role=None,
            exist_ok=False,
        )
Exemplo n.º 2
0
def create_user_with_identity(
    dao: Dao,
    provider: str,
    profile: 'base.UserProfile',
    default_role: Optional[str],
    default_channels: Optional[List[str]],
) -> User:

    username = profile["login"]
    user = dao.create_user_with_profile(
        username=username,
        provider=provider,
        emails=profile.get("emails", []),
        identity_id=profile["id"],
        name=profile["name"],
        avatar_url=profile["avatar_url"],
        role=default_role,
        exist_ok=False,
    )

    if default_channels is not None:

        for channel_name in default_channels:

            i = 0

            while (dao.db.query(Channel).filter(
                    Channel.name == channel_name).one_or_none()):

                channel_name = f"{username}-{i}"

                i += 1

            channel_meta = rest_models.Channel(
                name=channel_name,
                description=f"{username}'s default channel",
                private=True,
            )

            dao.create_channel(channel_meta, user.id, OWNER)

    return user