or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/gcloud@0.7.x
tile.json

tessl/pypi-gcloud

tessl install tessl/pypi-gcloud@0.7.0

Python 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%

task.mdevals/scenario-4/

Hierarchical User Profile Manager

Problem Description

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:

  1. Creating user profiles with optional parent relationships
  2. Retrieving all profiles within a specific organizational hierarchy
  3. Querying profiles based on attributes while respecting hierarchical boundaries

Requirements

Data Model

Each user profile should contain:

  • A unique identifier (string)
  • Full name (string)
  • Department (string)
  • Role (string)
  • Email address (string)

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).

Core Functionality

Implement the following functions:

1. 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 instance
  • user_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:

  • The created profile entity

2. 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 instance
  • root_user_id: The identifier of the root user in the hierarchy

Returns:

  • A list of all profile entities in the hierarchy

3. 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 instance
  • root_user_id: The identifier of the root user defining the hierarchy
  • department: The department name to filter by (string)

Returns:

  • A list of profile entities matching the criteria

Implementation Notes

  • Use appropriate data structures to represent hierarchical relationships
  • Ensure queries respect organizational boundaries
  • Handle edge cases such as non-existent users gracefully
  • Consider consistency requirements when reading hierarchical data

Test Cases { .test }

Create a test file test_profile_manager.py with the following test cases:

Test Case 1: Create and Retrieve Simple Hierarchy { .test-case @test }

# 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

Test Case 2: Query by Department in Hierarchy { .test-case @test }

# 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

Test Case 3: Multi-Level Hierarchy { .test-case @test }

# 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) == 2

Dependencies { .dependencies }

gcloud { .dependency }

Python client library for Google Cloud Platform services. Provides datastore functionality for NoSQL data storage with support for hierarchical data structures and consistent queries.