Esempio n. 1
0
def collection_batch_no_projects():
    """Create and commit a batch of Collection instances
    without projects, for testing the update API - we cannot
    assign projects to collections, only the other way around."""
    collections = [CollectionFactory() for _ in range(randint(3, 5))]
    for collection in collections:
        ClientFactory.create_batch(randint(0, 3), collection=collection)
        RoleFactory.create_batch(randint(0, 3), collection=collection)
    return collections
Esempio n. 2
0
def collection_batch():
    """Create and commit a batch of Collection instances,
    with associated projects, clients and roles."""
    collections = [CollectionFactory() for _ in range(randint(3, 5))]
    ProjectFactory.create_batch(randint(0, 3), collections=collections)
    for collection in collections:
        ClientFactory.create_batch(randint(0, 3), collection=collection)
        RoleFactory.create_batch(randint(0, 3), collection=collection)
    return collections
Esempio n. 3
0
def test_update_user_not_found(api, user_batch):
    scopes = [ODPScope.USER_ADMIN]
    user = UserFactory.build(
        id='foo',
        name=user_batch[2].name,
        email=user_batch[2].email,
        verified=user_batch[2].verified,
        roles=RoleFactory.create_batch(randint(0, 3)),
    )
    r = api(scopes).put('/user/',
                        json=dict(
                            id=user.id,
                            active=user.active,
                            role_ids=role_ids(user),
                        ))
    assert_not_found(r)
    assert_db_state(user_batch)
Esempio n. 4
0
def test_update_user(api, user_batch, scopes):
    authorized = ODPScope.USER_ADMIN in scopes
    modified_user_batch = user_batch.copy()
    modified_user_batch[2] = (user := UserFactory.build(
        id=user_batch[2].id,
        name=user_batch[2].name,
        email=user_batch[2].email,
        verified=user_batch[2].verified,
        roles=RoleFactory.create_batch(randint(0, 3)),
    ))
    r = api(scopes).put('/user/',
                        json=dict(
                            id=user.id,
                            active=user.active,
                            role_ids=role_ids(user),
                        ))
    if authorized:
        assert_empty_result(r)
        assert_db_state(modified_user_batch)
    else:
        assert_forbidden(r)
        assert_db_state(user_batch)
Esempio n. 5
0
def test_create_user_with_roles():
    roles = RoleFactory.create_batch(5)
    user = UserFactory(roles=roles)
    result = Session.execute(select(UserRole)).scalars()
    assert [(row.user_id, row.role_id) for row in result] \
           == [(user.id, role.id) for role in roles]
Esempio n. 6
0
def user_batch():
    """Create and commit a batch of User instances."""
    return [
        UserFactory(roles=RoleFactory.create_batch(randint(0, 3)))
        for _ in range(randint(3, 5))
    ]