tessl install tessl/pypi-gcloud@0.7.0Python client library for Google Cloud Platform services including Datastore, Storage, and Pub/Sub
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.19x
Baseline
Agent success rate without this tile
78%
Build a system to manage user profiles with hierarchical relationships in a NoSQL datastore. The system should support organizing users into organizational structures where profiles can have parent-child relationships (e.g., managers and their direct reports).
Your implementation must support:
Each user profile should contain:
User profiles can be organized hierarchically where one profile can be the parent of another (e.g., a manager is the parent of their direct reports).
Implement the following functions:
create_profile(client, user_id, parent_user_id=None, **attributes)Create a new user profile with the given attributes. If parent_user_id is provided, establish a hierarchical relationship with that parent profile.
Parameters:
client: The datastore client instanceuser_id: Unique identifier for the user (string)parent_user_id: Optional identifier of the parent user (string or None)**attributes: User attributes (name, department, role, email)Returns:
get_hierarchy(client, root_user_id)Retrieve all profiles within a specific organizational hierarchy starting from a root user. This should return the root user and all their descendants (direct and indirect reports).
Parameters:
client: The datastore client instanceroot_user_id: The identifier of the root user in the hierarchyReturns:
query_by_department_in_hierarchy(client, root_user_id, department)Find all profiles in a specific department within a given organizational hierarchy. This should only return profiles that are part of the specified hierarchy and match the department filter.
Parameters:
client: The datastore client instanceroot_user_id: The identifier of the root user defining the hierarchydepartment: The department name to filter by (string)Returns:
Create a test file test_profile_manager.py with the following test cases:
# Create a manager and two direct reports
manager = create_profile(
client,
'mgr001',
None,
name='Alice Manager',
department='Engineering',
role='Manager',
email='alice@example.com'
)
report1 = create_profile(
client,
'eng001',
'mgr001',
name='Bob Engineer',
department='Engineering',
role='Engineer',
email='bob@example.com'
)
report2 = create_profile(
client,
'eng002',
'mgr001',
name='Carol Engineer',
department='Engineering',
role='Senior Engineer',
email='carol@example.com'
)
# Retrieve the hierarchy
hierarchy = get_hierarchy(client, 'mgr001')
# Expected: 3 profiles (manager + 2 reports)
assert len(hierarchy) == 3# Create organizational structure:
# CEO (Sales)
# ├─ Sales Manager (Sales)
# │ ├─ Sales Rep 1 (Sales)
# │ └─ Sales Rep 2 (Sales)
# └─ Engineering Manager (Engineering)
# └─ Engineer 1 (Engineering)
create_profile(client, 'ceo001', None,
name='Dave CEO', department='Sales', role='CEO', email='dave@example.com')
create_profile(client, 'smgr001', 'ceo001',
name='Eve SalesManager', department='Sales', role='Manager', email='eve@example.com')
create_profile(client, 'srep001', 'smgr001',
name='Frank Rep', department='Sales', role='Representative', email='frank@example.com')
create_profile(client, 'srep002', 'smgr001',
name='Grace Rep', department='Sales', role='Representative', email='grace@example.com')
create_profile(client, 'emgr001', 'ceo001',
name='Helen EngManager', department='Engineering', role='Manager', email='helen@example.com')
create_profile(client, 'eng003', 'emgr001',
name='Ivan Engineer', department='Engineering', role='Engineer', email='ivan@example.com')
# Query for Sales department within CEO's hierarchy
sales_profiles = query_by_department_in_hierarchy(client, 'ceo001', 'Sales')
# Expected: 4 profiles (CEO + Sales Manager + 2 Reps)
assert len(sales_profiles) == 4
# Query for Engineering department within Sales Manager's hierarchy
eng_under_sales = query_by_department_in_hierarchy(client, 'smgr001', 'Engineering')
# Expected: 0 profiles (no Engineering under Sales Manager)
assert len(eng_under_sales) == 0# Create 3-level hierarchy
create_profile(client, 'vp001', None,
name='Jane VP', department='Product', role='VP', email='jane@example.com')
create_profile(client, 'dir001', 'vp001',
name='Karl Director', department='Product', role='Director', email='karl@example.com')
create_profile(client, 'pm001', 'dir001',
name='Laura PM', department='Product', role='Product Manager', email='laura@example.com')
# Get hierarchy from top
full_hierarchy = get_hierarchy(client, 'vp001')
assert len(full_hierarchy) == 3
# Get hierarchy from middle
partial_hierarchy = get_hierarchy(client, 'dir001')
assert len(partial_hierarchy) == 2Python client library for Google Cloud Platform services. Provides datastore functionality for NoSQL data storage with support for hierarchical data structures and consistent queries.