Commit 7b07dcd
authored
MPT-20684 introduce shared base models for file-like resources (#325)
🤖 AI-generated PR — Please review carefully.
## Summary
Reduces duplicated field declarations across the model layer by
extracting a
shared `FileResourceModel` base for attachments, documents, media, and
term
variants, plus four specialized subclasses (`AttachmentModel`,
`DocumentModel`,
`MediaModel`, `TermVariantModel`). Resource classes across billing,
catalog,
commerce, helpdesk, integration, and program domains now inherit from
the new
base models instead of redeclaring the same fields locally.
## What changed
### New base models (`mpt_api_client/models/`)
- `file_resource_model.py` — shared fields: `name`, `type`, `size`,
`description`, `content_type`
- `attachment_model.py` — attachment-specific fields on top of the base
- `document_model.py` — document-specific fields
- `media_model.py` — media-specific fields
- `term_variant_model.py` — term-variant-specific fields
- `__init__.py` re-exports the new classes
### Migrated resource classes
- `billing/`: credit_memo_attachments, custom_ledger_attachments,
invoice_attachments, journal_attachments, ledger_attachments,
statement_attachments
- `catalog/`: pricing_policy_attachments, product_term_variants,
products_documents, products_media
- `helpdesk/`: chat_attachments
- `integration/`: extension_documents, extension_media,
extension_term_variants
- `program/`: enrollments_attachments, programs_documents,
programs_media, programs_terms_variant
Resource-specific fields (parent references, audit, language, revision,
etc.)
remain on the subclasses.
### Tests
- New `tests/unit/conftest.py` fixtures for inherited-field coverage
- New unit test files for each base model under `tests/unit/models/`
- Updated existing unit tests to reflect the new convention where
missing
optional fields default to `None` instead of raising `AttributeError`
## Testing
- [ ] `make check` (lint + types)
- [ ] `make test` (unit suite)
- [ ] Smoke-run a few e2e tests touching the migrated resources to
confirm
response parsing still works against the live API
## Jira
MPT-20684
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
Closes [MPT-20684](https://softwareone.atlassian.net/browse/MPT-20684)
## Release Notes
- **Introduced shared base models** to reduce code duplication for
file-like resources:
- `FileResourceModel`: Base class with common fields (`name`, `type`,
`size`, `description`, `content_type`)
- `AttachmentModel`: Specialization of `FileResourceModel` for
attachment resources
- `DocumentModel`: Extends `FileResourceModel` with document-specific
fields (`status`, `filename`, `url`)
- `MediaModel`: Extends `FileResourceModel` with media-specific fields
(`status`, `filename`, `display_order`, `url`)
- `TermVariantModel`: Extends `FileResourceModel` with term variant
fields (`asset_url`, `language_code`, `status`, `filename`, `file_id`)
- **Updated resource classes** across multiple modules to inherit from
appropriate base models instead of directly from `Model`:
- Billing: `CreditMemoAttachment`, `CustomLedgerAttachment`,
`InvoiceAttachment`, `JournalAttachment`, `LedgerAttachment`,
`StatementAttachment`
- Catalog: `PricingPolicyAttachment`, `TermVariant`, `Document`, `Media`
- Helpdesk: Removed `ChatAttachment` and updated service to use
`AttachmentModel` directly
- Integration: `ExtensionDocument`, `ExtensionMedia`,
`ExtensionTermVariant`
- Program: `Document`, `Media`, `TermVariant`, `EnrollmentAttachment`
- **Eliminated duplicate field declarations** by migrating resource
classes to inherit shared fields from their respective base models
- **Added comprehensive unit test coverage** for new base models
including field initialization, camelCase-to-snake_case mapping,
serialization round-trips, and `repr()` formatting
- **Updated existing resource tests** to validate inherited field
behavior with optional fields defaulting to `None` instead of being
absent
- **Updated E2E tests** for chat attachments to validate against
`AttachmentModel` instead of the removed `ChatAttachment` class
- **Expanded module exports** in `mpt_api_client/models/__init__.py` to
include new model classes for public API access
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
[MPT-20684]:
https://softwareone.atlassian.net/browse/MPT-20684?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ48 files changed
Lines changed: 729 additions & 319 deletions
File tree
- mpt_api_client
- models
- resources
- billing
- catalog
- helpdesk
- integration
- program
- tests
- e2e/helpdesk/chats/attachment
- unit
- models
- resources
- billing
- catalog
- integration
- program
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
| 4 | + | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
| 9 | + | |
5 | 10 | | |
6 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments