Skip to content

MPT-20324: Added endpoints and e2e tests for program documents#304

Merged
robcsegal merged 1 commit intomainfrom
MPT-20324-add-endpoints-and-e-2-e-tests-for-program-documents
Apr 16, 2026
Merged

MPT-20324: Added endpoints and e2e tests for program documents#304
robcsegal merged 1 commit intomainfrom
MPT-20324-add-endpoints-and-e-2-e-tests-for-program-documents

Conversation

@robcsegal
Copy link
Copy Markdown
Contributor

@robcsegal robcsegal commented Apr 16, 2026

This pull request introduces a comprehensive "Document" resource for the Program domain in the API client, including full support for creating, retrieving, updating, deleting, publishing, and downloading program documents both synchronously and asynchronously. The implementation includes new service classes, mixins, and extensive end-to-end and unit test coverage to ensure robustness and correctness.

Key changes include:

Program Document Resource Implementation

  • Added Document model and corresponding DocumentService and AsyncDocumentService classes, providing CRUD, publish/unpublish, and file upload/download capabilities for program documents. These services are now accessible via the documents() method on both sync and async ProgramsService classes. [1] [2] [3] [4]

  • Introduced DocumentMixin and AsyncDocumentMixin to encapsulate document-specific logic, including file handling and publishing features, and registered them in the program mixins module. [1] [2]

Configuration and Test Data

  • Updated e2e_config.test.json to include a new test document file ID for use in end-to-end tests.

End-to-End and Unit Testing

  • Added extensive end-to-end tests (sync and async) for all document operations, including create (from file and URL), update, get, download, iteration, filtering, error handling, publishing, and unpublishing. [1] [2] [3]

  • Implemented unit tests for the new document mixins, validating correct multipart request construction for both file and URL-based document creation, for both sync and async services.

  • Extended unit tests for ProgramsService and AsyncProgramsService to verify the new documents() service property returns the correct service class and endpoint parameters. [1] [2]

These changes together provide a robust, fully-tested document management feature for program resources in the API client.

Closes MPT-20324(https://softwareone.atlassian.net/browse/MPT-20324)

  • Added Document resource to Program domain with sync and async support (create, retrieve, update, delete, publish/unpublish, download)
  • Introduced Document model with typed metadata (name, type, description, status, filename, size, content_type, url, program, audit)
  • Implemented DocumentService and AsyncDocumentService with full CRUD, file upload/download, publish/unpublish operations
  • Added DocumentMixin and AsyncDocumentMixin composing file creation, download, and publish behavior; registered exports in program mixins
  • Exposed documents(program_id) on ProgramsService and AsyncProgramsService to scope document operations to a program
  • Updated e2e_config.test.json to include program.document.file.id ("PDM-9643-3741-0001") for e2e tests
  • Added comprehensive tests:
    • E2E sync and async tests for create (from file and URL), update, get, download, iterate/filter, publish/unpublish, and error cases
    • Unit tests for DocumentMixin/AsyncDocumentMixin verifying multipart request construction for file and URL-based creation
    • Unit tests for ProgramsService/AsyncProgramsService and Document/DocumentService path and API surface

@robcsegal robcsegal requested a review from a team as a code owner April 16, 2026 14:53
@robcsegal robcsegal requested review from albertsola and jentyk April 16, 2026 14:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 82532239-7ad7-476c-9503-92dfe79cd25b

📥 Commits

Reviewing files that changed from the base of the PR and between 6915df7 and ce11996.

📒 Files selected for processing (11)
  • e2e_config.test.json
  • mpt_api_client/resources/program/mixins/__init__.py
  • mpt_api_client/resources/program/mixins/document_mixin.py
  • mpt_api_client/resources/program/programs.py
  • mpt_api_client/resources/program/programs_documents.py
  • tests/e2e/program/program/document/conftest.py
  • tests/e2e/program/program/document/test_async_document.py
  • tests/e2e/program/program/document/test_sync_document.py
  • tests/unit/resources/program/mixin/test_document_mixin.py
  • tests/unit/resources/program/test_programs.py
  • tests/unit/resources/program/test_programs_documents.py
✅ Files skipped from review due to trivial changes (4)
  • tests/e2e/program/program/document/conftest.py
  • mpt_api_client/resources/program/mixins/document_mixin.py
  • tests/unit/resources/program/test_programs_documents.py
  • tests/unit/resources/program/test_programs.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • e2e_config.test.json
  • mpt_api_client/resources/program/programs_documents.py

📝 Walkthrough

Walkthrough

Adds document resource support: new Document model, sync/async DocumentService implementations and mixins, ProgramsService accessors, E2E and unit tests for document flows, and an e2e config update with a program document file ID.

Changes

Cohort / File(s) Summary
Configuration
e2e_config.test.json
Inserted top-level notifications.contact.id and replaced the previous final entry with program.document.file.id for E2E document tests.
Mixins
mpt_api_client/resources/program/mixins/__init__.py, mpt_api_client/resources/program/mixins/document_mixin.py
Added DocumentMixin and AsyncDocumentMixin classes (compose create/download/publish mixins) and re-exported them via __all__.
Program service accessor
mpt_api_client/resources/program/programs.py
Added documents(self, program_id: str) to ProgramsService and AsyncProgramsService returning (A)DocumentService with endpoint_params={"program_id": program_id}.
Document service & model
mpt_api_client/resources/program/programs_documents.py
Added Document model, DocumentServiceConfig, DocumentService, and AsyncDocumentService with endpoints, collection/upload config and composed mixins for CRUD, download, publish/unpublish, and iteration.
E2E tests (fixtures & tests)
tests/e2e/program/program/document/conftest.py, tests/e2e/program/program/document/test_async_document.py, tests/e2e/program/program/document/test_sync_document.py
Added fixtures (document_id, invalid id, data factory, service fixtures) and comprehensive sync/async E2E tests for create (file/URL), update, get, download, iterate/filter, not-found behavior, and publish/unpublish flows; includes teardown deletion handling.
Unit tests
tests/unit/resources/program/mixin/test_document_mixin.py, tests/unit/resources/program/test_programs.py, tests/unit/resources/program/test_programs_documents.py
Added unit tests verifying multipart create behavior for mixins, ProgramsService.documents accessor returns correct service type and endpoint params, service path resolution, expected method presence, and Document serialization/field behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed The PR title contains exactly one Jira issue key in the format MPT-XXXX: MPT-20324.
Test Coverage Required ✅ Passed 5 code files modified with 6 test files (523+ lines) providing comprehensive coverage for document operations including e2e and unit tests.
Single Commit Required ✅ Passed Git commands provided to count commits in PR by comparing current branch to main branch using 'git log --oneline main..HEAD | wc -l'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/e2e/program/program/document/conftest.py (1)

10-11: Remove unused fixture dependency in invalid_document_id.

e2e_config is not used here; dropping it will keep fixture dependencies minimal.

♻️ Suggested simplification
 `@pytest.fixture`
-def invalid_document_id(e2e_config):
+def invalid_document_id():
     return "PDM-0000-0000-0000"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/program/program/document/conftest.py` around lines 10 - 11, The
fixture function invalid_document_id currently declares an unused parameter
e2e_config; remove that unused dependency by changing the function signature to
invalid_document_id() (no parameters) and keep the same return value, and update
any tests or fixtures that call or reference invalid_document_id to not pass
e2e_config when invoking it.
tests/unit/resources/program/mixin/test_document_mixin.py (1)

63-64: Assert mock call count before indexing calls for clearer failures.

A missing request currently fails with IndexError; asserting call_count == 1 first gives a precise test failure reason.

🧪 Suggested assertion hardening
-    result = mock_route.calls[0].request
+    assert mock_route.call_count == 1
+    result = mock_route.calls[0].request
...
-    request = mock_route.calls[0].request
+    assert mock_route.call_count == 1
+    request = mock_route.calls[0].request
...
-    request = mock_route.calls[0].request
+    assert mock_route.call_count == 1
+    request = mock_route.calls[0].request
...
-    request = mock_route.calls[0].request
+    assert mock_route.call_count == 1
+    request = mock_route.calls[0].request

Also applies to: 88-89, 120-121, 144-145

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/resources/program/mixin/test_document_mixin.py` around lines 63 -
64, Add explicit assertions on the mock call count before indexing into
mock_route.calls to avoid IndexError and give clearer failures: e.g., assert
mock_route.call_count == 1 (or >= 1 as appropriate) immediately before each
occurrence that dereferences mock_route.calls[0].request in the test methods in
test_document_mixin.py (the occurrences around the lines with result =
mock_route.calls[0].request and the similar places at the other noted
locations). This ensures tests fail with a clear assertion message if the
expected call wasn't made.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/e2e/program/program/document/conftest.py`:
- Around line 10-11: The fixture function invalid_document_id currently declares
an unused parameter e2e_config; remove that unused dependency by changing the
function signature to invalid_document_id() (no parameters) and keep the same
return value, and update any tests or fixtures that call or reference
invalid_document_id to not pass e2e_config when invoking it.

In `@tests/unit/resources/program/mixin/test_document_mixin.py`:
- Around line 63-64: Add explicit assertions on the mock call count before
indexing into mock_route.calls to avoid IndexError and give clearer failures:
e.g., assert mock_route.call_count == 1 (or >= 1 as appropriate) immediately
before each occurrence that dereferences mock_route.calls[0].request in the test
methods in test_document_mixin.py (the occurrences around the lines with result
= mock_route.calls[0].request and the similar places at the other noted
locations). This ensures tests fail with a clear assertion message if the
expected call wasn't made.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: bb3e4f74-4354-4ba5-8ed9-f16437a5ec44

📥 Commits

Reviewing files that changed from the base of the PR and between 2bf0eb1 and 6915df7.

📒 Files selected for processing (11)
  • e2e_config.test.json
  • mpt_api_client/resources/program/mixins/__init__.py
  • mpt_api_client/resources/program/mixins/document_mixin.py
  • mpt_api_client/resources/program/programs.py
  • mpt_api_client/resources/program/programs_documents.py
  • tests/e2e/program/program/document/conftest.py
  • tests/e2e/program/program/document/test_async_document.py
  • tests/e2e/program/program/document/test_sync_document.py
  • tests/unit/resources/program/mixin/test_document_mixin.py
  • tests/unit/resources/program/test_programs.py
  • tests/unit/resources/program/test_programs_documents.py

@robcsegal robcsegal changed the title [MPT-20324] Added endpoints and e2e tests for program documents MPT-20324 Added endpoints and e2e tests for program documents Apr 16, 2026
@robcsegal robcsegal force-pushed the MPT-20324-add-endpoints-and-e-2-e-tests-for-program-documents branch from 6915df7 to db185d1 Compare April 16, 2026 15:15
@robcsegal robcsegal changed the title MPT-20324 Added endpoints and e2e tests for program documents MPT-20324: Added endpoints and e2e tests for program documents Apr 16, 2026
@robcsegal robcsegal force-pushed the MPT-20324-add-endpoints-and-e-2-e-tests-for-program-documents branch from db185d1 to ce11996 Compare April 16, 2026 15:16
@sonarqubecloud
Copy link
Copy Markdown

@robcsegal robcsegal merged commit c1d8456 into main Apr 16, 2026
4 checks passed
@robcsegal robcsegal deleted the MPT-20324-add-endpoints-and-e-2-e-tests-for-program-documents branch April 16, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants