コード例 #1
0
ファイル: test_user.py プロジェクト: sambacha/kodiak
def test_sync_accounts_new_and_existing_accounts(
        user: User, successful_installation_response: object) -> None:
    user_account = Account.objects.create(
        github_installation_id=1066615,
        github_account_login=user.github_login,
        github_account_id=user.github_id,
        github_account_type="User",
    )
    AccountMembership.objects.create(user=user,
                                     account=user_account,
                                     role="member")

    # the user should get removed from this account when we sync. This tests
    # that our membership removal of installations a user no longer has access
    # to works.
    acme_corp_account = Account.objects.create(
        github_installation_id=79233,
        github_account_login="******",
        github_account_id=33803,
        github_account_type="Organization",
    )
    AccountMembership.objects.create(user=user,
                                     account=acme_corp_account,
                                     role="member")

    assert Account.objects.count() == 2
    assert AccountMembership.objects.filter(user=user).count() == 2
    user.sync_accounts()

    assert Account.objects.filter(
        github_account_login__in=["recipeyak", "chdsbd", "ghost", "acme-corp"])
    assert (Account.objects.count() == 4
            ), "we should have a new account for recipeyak and chdsbd."
    assert (AccountMembership.objects.filter(user=user).exclude(
        account__github_account_login__in=["recipeyak", "chdsbd", "ghost"]).
            count() == 0), "we should have removed acme-corp."
    assert (AccountMembership.objects.filter(
        user=user, role="member",
        account__github_account_login="******").count() == 1)
    assert (AccountMembership.objects.filter(
        user=user, role="admin",
        account__github_account_login="******").count() == 1)

    assert (
        AccountMembership.objects.filter(
            user=user, account=acme_corp_account).exists() is False
    ), "the user should no longer be a member of the organization if is no longer returned from `/user/installations` endpoint."
    assert (
        Account.objects.filter(id=acme_corp_account.id).exists() is True
    ), "account that we are no longer a member of should not be deleted."
コード例 #2
0
ファイル: test_user.py プロジェクト: sambacha/kodiak
def test_sync_accounts_failing_api_request_collaborator(
        user: User,
        failing_installation_response_membership_check: object) -> None:
    """
    If the user is a collaborator of an organization they will get an API error
    when testing membership. We should ignore the error and not add them to that organization.
    """
    assert Account.objects.count() == 0
    assert AccountMembership.objects.count() == 0
    assert User.objects.count() == 1
    user.sync_accounts()

    assert (Account.objects.filter(
        github_account_login__in=["ghost", "chdsbd", "recipeyak"]).count() ==
            Account.objects.count() == 3)
    assert AccountMembership.objects.count() == 3
    assert User.objects.count() == 1
コード例 #3
0
    def post(self):
        args = parser.parse_args()
        email = args['email']
        password = args['password']
        first_name = args['first_name']
        last_name = args['last_name']

        user = User(email, password, first_name, last_name)

        db.session.add(user)
        db.session.commit()
        user_id = user.id
        return args, 201
コード例 #4
0
def init():
    """Init application, create database tables
    and create a new user named admin with password admin
    """
    from web_api.extensions import db
    from web_api.models import User
    click.echo("create database")
    db.create_all()
    click.echo("done")

    click.echo("create user")
    user = User(username='******',
                email='*****@*****.**',
                password=config.ADMIN_PW,
                active=True)
    db.session.add(user)
    db.session.commit()
    click.echo("created user admin")
コード例 #5
0
ファイル: test_user.py プロジェクト: sambacha/kodiak
def test_sync_accounts_failing_api_request(
        user: User, failing_installation_response: object) -> None:
    with pytest.raises(SyncAccountsError):
        user.sync_accounts()