def test_collection_ownership_filtering(client: R2RClient):
    """Test the ownerOnly filter parameter in collections list endpoint."""
    # Create two test users
    user1_email = f"user1_{uuid.uuid4()}@test.com"
    user1_password = "password123"
    user2_email = f"user2_{uuid.uuid4()}@test.com"
    user2_password = "password123"

    # Register users
    client.users.create(user1_email, user1_password)
    client.users.create(user2_email, user2_password)

    # Login as user1 and create a collection
    client.users.login(user1_email, user1_password)
    user1_id = client.users.me().results.id
    user1_collection = client.collections.create(name="User1 Collection").results
    user1_collection_id = user1_collection.id

    # Login as user2 and create a collection
    client.users.logout()
    client.users.login(user2_email, user2_password)
    user2_id = client.users.me().results.id
    user2_collection = client.collections.create(name="User2 Collection").results
    user2_collection_id = user2_collection.id

    # User2 adds user1 to their collection
    client.collections.add_user(user2_collection_id, user1_id)

    # Login as user1 and check collections
    client.users.logout()
    client.users.login(user1_email, user1_password)

    # List all collections
    all_collections = client.collections.list().results
    all_collection_ids = [str(col.id) for col in all_collections]

    # Verify user1 can see their own collection
    assert str(user1_collection_id) in all_collection_ids, "User1 can't see their own collection"

    # Verify user1 can see user2's shared collection
    assert str(user2_collection_id) in all_collection_ids, "User1 can't see shared collection"

    # List only owned collections
    owned_collections = client.collections.list(owner_only=True).results
    owned_collection_ids = [str(col.id) for col in owned_collections]

    # Verify user1's collection is in the owned list
    assert str(user1_collection_id) in owned_collection_ids, "User1's collection not in owned list"

    # Verify user2's collection is NOT in the owned list
    assert str(user2_collection_id) not in owned_collection_ids, "Shared collection should not be in owned list"

    # User1 adds user2 to their collection
    client.collections.add_user(user1_collection_id, user2_id)

    # Login as user2 and check collections
    client.users.logout()
    client.users.login(user2_email, user2_password)

    # List all collections
    all_collections = client.collections.list().results
    all_collection_ids = [str(col.id) for col in all_collections]

    # Verify user2 can see their own collection
    assert str(user2_collection_id) in all_collection_ids, "User2 can't see their own collection"

    # Verify user2 can see user1's shared collection
    assert str(user1_collection_id) in all_collection_ids, "User2 can't see shared collection"

    # List only owned collections
    owned_collections = client.collections.list(owner_only=True).results
    owned_collection_ids = [str(col.id) for col in owned_collections]

    # Verify user2's collection is in the owned list
    assert str(user2_collection_id) in owned_collection_ids, "User2's collection not in owned list"

    # Verify user1's collection is NOT in the owned list
    assert str(user1_collection_id) not in owned_collection_ids, "Shared collection should not be in owned list"

    # Cleanup
    client.users.logout()
Test the ownerOnly filter parameter in collections list endpoint.
py/tests/integration/test_users.py