Skip to content

Conversation

@btoron
Copy link
Owner

@btoron btoron commented Dec 31, 2025

I

btoron and others added 4 commits December 31, 2025 12:32
Implemented 12 async GET methods for Activities in Core API module with
comprehensive test coverage and Pydantic model validation.

Changes:
- Added 12 new Pydantic models for activities endpoints in ofsc/models.py
  (ActivityListResponse, SubmittedForm, ResourcePreference, Inventory, etc.)
- Implemented 12 async GET methods in ofsc/async_client/core.py:
  * get_activities - List with pagination
  * get_activity - Single activity by ID
  * get_capacity_categories - Capacity categories
  * get_customer_inventories - Customer inventories
  * get_deinstalled_inventories - Deinstalled inventories
  * get_file_property - File property content
  * get_installed_inventories - Installed inventories
  * get_linked_activities - Linked activities
  * get_activity_link - Specific link details
  * get_required_inventories - Required inventories
  * get_resource_preferences - Resource preferences
  * get_submitted_forms - Submitted forms
- Added error handling helpers (_parse_error_response, _handle_http_error)
- Created comprehensive test suite with 21 passing tests:
  * 11 live API tests validating against actual OFSC API
  * 10 saved response validation tests for Pydantic models
  * Error handling test for 404 responses
- Updated scripts/capture_api_responses.py with activities endpoints
- Captured 12 API responses to tests/saved_responses/activities/
- Updated docs/ENDPOINTS.md with new async implementations

All endpoints follow existing async patterns with PEP 287 docstrings,
type hints, and comprehensive exception handling.

Test Results: 21 passed, 2 skipped in 4.73s

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implemented a Pydantic model for get_activities query parameters based on
Swagger specification with proper validation and type safety.

Changes:
- Renamed GetActivityRequest → GetActivitiesParams in ofsc/models.py
- Added missing svcWorkOrderId parameter
- Made resources optional (was incorrectly required)
- Used Literal["none", "immediate", "all"] for includeChildren enum
- Fixed validator bug (unreachable code after return)
- Changed extra="allow" to extra="forbid" for stricter validation
- Added to_api_params() method for API parameter conversion

Integration:
- Updated get_activities() in ofsc/async_client/core.py to accept
  GetActivitiesParams | dict for backward compatibility
- Added validation logic to convert dict to model internally

Testing:
- Created tests/test_get_activities_params.py with 13 comprehensive tests:
  * Valid params with various combinations
  * Invalid params (missing dateTo, dateFrom > dateTo, etc.)
  * API parameter conversion validation
  * Enum validation
  * Extra fields forbidden
- Updated existing live API test to use date objects and list for resources
- All 13 tests passing + live API test passing

Validation Rules:
- dateFrom and dateTo must both be specified or both omitted
- dateFrom must be <= dateTo
- Must have one of: dateFrom/dateTo, svcWorkOrderId, or includeNonScheduled=True

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…e results

Updated the live API test to:
- Use includeChildren="all" parameter to include child resources
- Increase limit from 5 to 100 activities
- Assert that more than 5 activities are returned
- Ensure results don't exceed limit

This provides better test coverage for the GetActivitiesParams model
and validates pagination with includeChildren parameter.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated test_get_activities to calculate date range dynamically:
- dateFrom: First day of current month (day 1)
- dateTo: Last day of current month (day 28/29/30/31 depending on month)

Uses calendar.monthrange() to determine the correct last day for any month.
This ensures the test always queries relevant current data from the API.

Example: For December 2025, queries 2025-12-01 to 2025-12-31

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@btoron btoron linked an issue Dec 31, 2025 that may be closed by this pull request
btoron and others added 2 commits December 31, 2025 13:18
Implemented 18 async GET methods for the Resources API in AsyncOFSCore,
with comprehensive Pydantic models and test coverage.

**Methods Implemented:**
1. get_assigned_locations() - Get assigned locations for a resource
2. get_calendars() - Get all calendars
3. get_position_history() - Get position history for a resource
4. get_resource() - Get a single resource by ID (with expand support)
5. get_resource_assistants() - Get assistant resources
6. get_resource_calendar() - Get calendar view for a resource
7. get_resource_children() - Get child resources
8. get_resource_descendants() - Get descendant resources (with expand support)
9. get_resource_inventories() - Get inventories assigned to a resource
10. get_resource_location() - Get a single location for a resource
11. get_resource_locations() - Get all locations for a resource
12. get_resource_plans() - Get routing plans for a resource
13. get_resource_route() - Get route for a resource on a specific date
14. get_resource_users() - Get users assigned to a resource
15. get_resource_workschedules() - Get workschedules for a resource
16. get_resource_workskills() - Get workskills assigned to a resource
17. get_resource_workzones() - Get workzones assigned to a resource
18. get_resources() - Get all resources with pagination (with expand support)

**Models Added** (ofsc/models.py):
- ResourceListResponse - Paginated resource list
- ResourceAssistant, ResourceAssistantsResponse
- ResourceWorkskillAssignment, ResourceWorkskillListResponse
- ResourceWorkzoneAssignment, ResourceWorkzoneListResponse
- PositionHistoryItem, PositionHistoryResponse
- ResourceRouteActivity, ResourceRouteResponse
- ResourcePlan, ResourcePlansResponse
- Calendar, CalendarsListResponse

**Key Features:**
- Python date objects for all date parameters (converted to ISO internally)
- Expand parameter support (inventories, workSkills, workZones, workSchedules)
- Proper error handling (404, validation, network errors)
- Comprehensive exception hierarchy usage
- Helper method _build_expand_param() for clean parameter construction

**Testing:**
- Created tests/async/test_async_resources_get.py with 23 tests
- Live API tests for all 18 methods
- Saved response validation tests
- Error handling tests (404 not found)
- All tests passing ✅

**API Responses Captured:**
- Added 21 resource endpoints to scripts/capture_api_responses.py
- Captured responses for: individual, bucket, group resources
- Captured responses for all sub-entities (users, inventories, etc.)
- Captured routes, calendars, locations, workskills, workzones

**Test Resources Used:**
- Individual: 33001
- Bucket: FLUSA
- Group: ACMECONTRACTOR
- Parent (for hierarchy): SUNRISE

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Reorganize models.py into clearly defined sections:
- Core / Activities: Activity models and related responses
- Core / Resources: Resource instance models and related responses
- Metadata / Resource Types: ResourceType metadata definitions

This improves code organization and makes it easier to find and
maintain related models.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add pytest-xdist for parallel test execution to reduce test time by 50%+.

Changes:
- Add pytest-xdist dependency to pyproject.toml
- Configure pytest with `-n auto --dist worksteal` for parallel execution
- Add `@pytest.mark.serial` marker for tests that modify shared API state
- Mark 13 state-modifying tests (subscriptions, workzones, properties)
- Create CI workflow (.github/workflows/test.yml) for automated testing
- Update README.md with comprehensive testing documentation

Test Results:
- 541 total tests
- 13 marked as serial (run sequentially)
- 528 can run in parallel
- Mocked tests run in ~17s (vs ~2min sequential)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove stub tests for get_activities and get_resource from
test_async_ofsc.py since these methods are now fully implemented
(in #117 and #121) and tested in their respective test files.

The stub tests were checking for NotImplementedError but the methods
now make actual API calls, causing network errors in tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@btoron btoron linked an issue Dec 31, 2025 that may be closed by this pull request
…n permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants