From 7d25b3d3532867fd41e30333b76b6ad84eb17793 Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Fri, 11 Oct 2019 13:48:39 +0200 Subject: [PATCH 1/7] Fix. --- connect/resources/usage_file_automation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/connect/resources/usage_file_automation.py b/connect/resources/usage_file_automation.py index fe8ff43..56444a2 100644 --- a/connect/resources/usage_file_automation.py +++ b/connect/resources/usage_file_automation.py @@ -3,6 +3,7 @@ # This file is part of the Ingram Micro Cloud Blue Connect SDK. # Copyright (c) 2019 Ingram Micro. All Rights Reserved. +import json import logging from abc import ABCMeta @@ -62,9 +63,9 @@ def dispatch(self, request): except UsageFileAction as usage: self._api.post( path='{}/{}'.format(request.id, usage.code), - json=usage.obj.json - if isinstance(usage.obj, BaseModel) - else getattr(usage.obj, '__dict__', str(usage.obj))) + data=json.dumps(usage.obj.json + if isinstance(usage.obj, BaseModel) + else getattr(usage.obj, '__dict__', str(usage.obj)))) processing_result = usage.code # Catch skip From 278468348437677847bea39116cbe9deb7fcb686 Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Fri, 11 Oct 2019 13:50:08 +0200 Subject: [PATCH 2/7] Fix. --- connect/resources/usage_file_automation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect/resources/usage_file_automation.py b/connect/resources/usage_file_automation.py index fe8ff43..3f2806c 100644 --- a/connect/resources/usage_file_automation.py +++ b/connect/resources/usage_file_automation.py @@ -32,7 +32,7 @@ def filters(self, status='ready', **kwargs): """ filters = super(UsageFileAutomation, self).filters(status, **kwargs) if self.config.products: - filters['product__id'] = ','.join(self.config.products) + filters['product_id'] = ','.join(self.config.products) return filters def dispatch(self, request): From 8ca0517e1f1e9bb0515dfd65a6359b41947fa6e3 Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Fri, 11 Oct 2019 13:57:55 +0200 Subject: [PATCH 3/7] Fix. --- connect/resources/usage_file_automation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect/resources/usage_file_automation.py b/connect/resources/usage_file_automation.py index 56444a2..f5f3e4d 100644 --- a/connect/resources/usage_file_automation.py +++ b/connect/resources/usage_file_automation.py @@ -65,7 +65,7 @@ def dispatch(self, request): path='{}/{}'.format(request.id, usage.code), data=json.dumps(usage.obj.json if isinstance(usage.obj, BaseModel) - else getattr(usage.obj, '__dict__', str(usage.obj)))) + else usage.obj)) processing_result = usage.code # Catch skip From d3abae3c92414a8747eea3a89d222e966bf4ef3e Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Mon, 21 Oct 2019 12:32:23 +0200 Subject: [PATCH 4/7] Added a few missing methods and properties --- CHANGES.md | 18 ++++++++++++++++++ connect/models/asset.py | 3 +++ connect/models/schemas.py | 1 + connect/models/tier_config.py | 11 +++++++++++ 4 files changed, 33 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f6c480f..ed9a3a1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,23 @@ # Connect SDK Changes History +## v17.3 + +* HTTP timeout request to Connect platform should be not less than 300 seconds. +* Accept Usage File is sending wrong parameter in post request. +* Usage processor filter "product__id" is not filtering by product id. + +## v17.2 + +* external_id is sometimes returned as an integer by Connect API, which breaks Python SDK parsing. + +## v17.1 + +* Add custom loggers to the automation classes, that automatically add relevant info of the request being processed. Legacy global logger still working in order to have a context-independent logger. +* Get product templates and configuration params. +* Put each model in its own Python file, to reduce the chance of having circular references on imports. +* Tier requests are not filtering by product id by default. +* Fulfillment assignee not receiving the right type. + ## v17.0 * Fixed bugs when listing and working with usage files. diff --git a/connect/models/asset.py b/connect/models/asset.py index f347584..a02ef43 100644 --- a/connect/models/asset.py +++ b/connect/models/asset.py @@ -57,6 +57,9 @@ class Asset(BaseModel): - suspended: Asset becomes suspended once 'suspend' request type is fulfilled. """ + events = None # type: Events + """ (:py:class:`.Events`) Events occurred on this asset. """ + external_id = None # type: str """ (str) Identification for asset object on eCommerce. """ diff --git a/connect/models/schemas.py b/connect/models/schemas.py index d96c8f2..27f523a 100644 --- a/connect/models/schemas.py +++ b/connect/models/schemas.py @@ -536,6 +536,7 @@ def make_object(self, data): class AssetSchema(BaseSchema): status = fields.Str() external_id = ExternalIdField() + events = fields.Nested(EventsSchema, allow_none=True) external_uid = fields.Str(allow_none=True) external_name = fields.Str(allow_none=True) product = fields.Nested(ProductSchema, only=('id', 'name')) diff --git a/connect/models/tier_config.py b/connect/models/tier_config.py index 7491199..651028a 100644 --- a/connect/models/tier_config.py +++ b/connect/models/tier_config.py @@ -17,6 +17,17 @@ from .tier_account import TierAccount from .schemas import TierConfigSchema + def get_param_by_id(self, param_id): + """ + :param str param_id: Id of the parameter. + :return: A Param by ID, or None if it was not found. + :rtype: Param + """ + try: + return list(filter(lambda p: p.id == param_id, self.params))[0] + except IndexError: + return None + class TierConfig(BaseModel): """ Full representation of Tier object. """ From f0949e8e619a327f3c4c10be5d08ef073b6b6f92 Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Mon, 21 Oct 2019 12:48:39 +0200 Subject: [PATCH 5/7] null accepted on JSON fields. --- CHANGES.md | 1 + connect/models/asset.py | 1 + connect/models/schemas.py | 402 +++++++++++++++++----------------- connect/models/tier_config.py | 11 - 4 files changed, 203 insertions(+), 212 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ed9a3a1..7de666a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ * HTTP timeout request to Connect platform should be not less than 300 seconds. * Accept Usage File is sending wrong parameter in post request. * Usage processor filter "product__id" is not filtering by product id. +* All fields accept null to avoid parsing errors. ## v17.2 diff --git a/connect/models/asset.py b/connect/models/asset.py index a02ef43..06ea5c1 100644 --- a/connect/models/asset.py +++ b/connect/models/asset.py @@ -9,6 +9,7 @@ from .configuration import Configuration from .connection import Connection from .contract import Contract +from .events import Events from .item import Item from .marketplace import Marketplace from .param import Param diff --git a/connect/models/schemas.py b/connect/models/schemas.py index 27f523a..8b4abf9 100644 --- a/connect/models/schemas.py +++ b/connect/models/schemas.py @@ -18,7 +18,7 @@ def make_object(self, data): class ActivationSchema(BaseSchema): link = fields.Str(allow_none=True) - message = fields.Str() + message = fields.Str(allow_none=True) date = fields.DateTime(allow_none=True) @post_load @@ -29,7 +29,7 @@ def make_object(self, data): class AgreementStatsSchema(BaseSchema): contracts = fields.Int(allow_none=True) - versions = fields.Int() + versions = fields.Int(allow_none=True) @post_load def make_object(self, data): @@ -38,7 +38,7 @@ def make_object(self, data): class CompanySchema(BaseSchema): - name = fields.Str() + name = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -59,10 +59,10 @@ def make_object(self, data): class ContactSchema(BaseSchema): - email = fields.Str() + email = fields.Str(allow_none=True) first_name = fields.Str(allow_none=True) last_name = fields.Str(allow_none=True) - phone_number = fields.Nested(PhoneNumberSchema) + phone_number = fields.Nested(PhoneNumberSchema, allow_none=True) @post_load def make_object(self, data): @@ -71,12 +71,12 @@ def make_object(self, data): class ContactInfoSchema(BaseSchema): - address_line1 = fields.Str() + address_line1 = fields.Str(allow_none=True) address_line2 = fields.Str(allow_none=True) - city = fields.Str() - contact = fields.Nested(ContactSchema) - country = fields.Str() - postal_code = fields.Str() + city = fields.Str(allow_none=True) + contact = fields.Nested(ContactSchema, allow_none=True) + country = fields.Str(allow_none=True) + postal_code = fields.Str(allow_none=True) state = fields.Str(allow_none=True) @post_load @@ -86,8 +86,8 @@ def make_object(self, data): class ValueChoiceSchema(Schema): - value = fields.Str() - label = fields.Str() + value = fields.Str(allow_none=True) + label = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -96,10 +96,10 @@ def make_object(self, data): class ConstraintsSchema(BaseSchema): - hidden = fields.Bool() - required = fields.Bool() - choices = fields.Nested(ValueChoiceSchema, many=True) - unique = fields.Bool() + hidden = fields.Bool(allow_none=True) + required = fields.Bool(allow_none=True) + choices = fields.Nested(ValueChoiceSchema, many=True, allow_none=True) + unique = fields.Bool(allow_none=True) @post_load def make_object(self, data): @@ -108,8 +108,8 @@ def make_object(self, data): class DocumentSchema(BaseSchema): - title = fields.Str() - url = fields.Str() + title = fields.Str(allow_none=True) + url = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -118,9 +118,9 @@ def make_object(self, data): class DownloadLinkSchema(BaseSchema): - title = fields.Str() - url = fields.Str() - visible_for = fields.Str() + title = fields.Str(allow_none=True) + url = fields.Str(allow_none=True) + visible_for = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -129,7 +129,7 @@ def make_object(self, data): class UserSchema(BaseSchema): - name = fields.Str() + name = fields.Str(allow_none=True) email = fields.Str(allow_none=True) @post_load @@ -149,17 +149,17 @@ def make_object(self, data): class EventsSchema(BaseSchema): - created = fields.Nested(EventSchema) - inquired = fields.Nested(EventSchema) - pended = fields.Nested(EventSchema) - validated = fields.Nested(EventSchema) - updated = fields.Nested(EventSchema) - approved = fields.Nested(EventSchema) - uploaded = fields.Nested(EventSchema) - submitted = fields.Nested(EventSchema) - accepted = fields.Nested(EventSchema) - rejected = fields.Nested(EventSchema) - closed = fields.Nested(EventSchema) + created = fields.Nested(EventSchema, allow_none=True) + inquired = fields.Nested(EventSchema, allow_none=True) + pended = fields.Nested(EventSchema, allow_none=True) + validated = fields.Nested(EventSchema, allow_none=True) + updated = fields.Nested(EventSchema, allow_none=True) + approved = fields.Nested(EventSchema, allow_none=True) + uploaded = fields.Nested(EventSchema, allow_none=True) + submitted = fields.Nested(EventSchema, allow_none=True) + accepted = fields.Nested(EventSchema, allow_none=True) + rejected = fields.Nested(EventSchema, allow_none=True) + closed = fields.Nested(EventSchema, allow_none=True) @post_load def make_object(self, data): @@ -168,7 +168,7 @@ def make_object(self, data): class HubInstanceSchema(BaseSchema): - type = fields.Str() + type = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -177,8 +177,8 @@ def make_object(self, data): class HubStatsSchema(BaseSchema): - connections = fields.Int() - marketplaces = fields.Int() + connections = fields.Int(allow_none=True) + marketplaces = fields.Int(allow_none=True) @post_load def make_object(self, data): @@ -187,12 +187,12 @@ def make_object(self, data): class HubSchema(BaseSchema): - name = fields.Str() - company = fields.Nested(CompanySchema) + name = fields.Str(allow_none=True) + company = fields.Nested(CompanySchema, allow_none=True) description = fields.Str(allow_none=True) - instance = fields.Nested(HubInstanceSchema) - events = fields.Nested(EventsSchema) - stats = fields.Nested(HubStatsSchema) + instance = fields.Nested(HubInstanceSchema, allow_none=True) + events = fields.Nested(EventsSchema, allow_none=True) + stats = fields.Nested(HubStatsSchema, allow_none=True) @post_load def make_object(self, data): @@ -211,8 +211,8 @@ def _deserialize(self, value, attr, obj, **kwargs): class ExtIdHubSchema(Schema): - hub = fields.Nested(HubSchema, only=('id', 'name')) - external_id = ExternalIdField() + hub = fields.Nested(HubSchema, only=('id', 'name'), allow_none=True) + external_id = ExternalIdField(allow_none=True) @post_load def make_object(self, data): @@ -221,10 +221,10 @@ def make_object(self, data): class RenewalSchema(BaseSchema): - from_ = fields.DateTime(load_from='from') - to = fields.DateTime() - period_delta = fields.Int() - period_uom = fields.Str() + from_ = fields.DateTime(load_from='from', allow_none=True) + to = fields.DateTime(allow_none=True) + period_delta = fields.Int(allow_none=True) + period_uom = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -253,13 +253,13 @@ def _deserialize(self, value, attr, obj, **kwargs): class MarketplaceSchema(BaseSchema): - name = fields.Str() - description = fields.Str() - active_contracts = fields.Int() - icon = fields.Str() - owner = fields.Nested(CompanySchema, only=('id', 'name')) - hubs = fields.Nested(ExtIdHubSchema, many=True) - zone = fields.Str() + name = fields.Str(allow_none=True) + description = fields.Str(allow_none=True) + active_contracts = fields.Int(allow_none=True) + icon = fields.Str(allow_none=True) + owner = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) + hubs = fields.Nested(ExtIdHubSchema, many=True, allow_none=True) + zone = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -268,9 +268,9 @@ def make_object(self, data): class CountrySchema(BaseSchema): - name = fields.Str() - icon = fields.Str() - zone = fields.Str() + name = fields.Str(allow_none=True) + icon = fields.Str(allow_none=True) + zone = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -279,9 +279,9 @@ def make_object(self, data): class ParamSchema(BaseSchema): - name = fields.Str() - description = fields.Str() - type = fields.Str() + name = fields.Str(allow_none=True) + description = fields.Str(allow_none=True) + type = fields.Str(allow_none=True) value = fields.Str(allow_none=True) value_error = fields.Str(allow_none=True) value_choice = fields.Str(many=True, allow_none=True) @@ -303,8 +303,8 @@ def make_object(self, data): class ItemSchema(BaseSchema): - mpn = fields.Str() - quantity = QuantityField() + mpn = fields.Str(allow_none=True) + quantity = QuantityField(allow_none=True) old_quantity = QuantityField(allow_none=True) renewal = fields.Nested(RenewalSchema, allow_none=True) params = fields.Nested(ParamSchema, many=True, allow_none=True) @@ -322,20 +322,20 @@ def make_object(self, data): class AgreementSchema(BaseSchema): - type = fields.Str() - title = fields.Str() - description = fields.Str() - created = fields.DateTime() - updated = fields.DateTime() - owner = fields.Nested(CompanySchema) + type = fields.Str(allow_none=True) + title = fields.Str(allow_none=True) + description = fields.Str(allow_none=True) + created = fields.DateTime(allow_none=True) + updated = fields.DateTime(allow_none=True) + owner = fields.Nested(CompanySchema, allow_none=True) stats = fields.Nested(AgreementStatsSchema, allow_none=True) author = fields.Nested(UserSchema, allow_none=True) - version = fields.Int() - active = fields.Bool() - link = fields.Str() - version_created = fields.DateTime() - version_contracts = fields.Int() - agreements = fields.Nested('AgreementSchema', many=True) + version = fields.Int(allow_none=True) + active = fields.Bool(allow_none=True) + link = fields.Str(allow_none=True) + version_created = fields.DateTime(allow_none=True) + version_contracts = fields.Int(allow_none=True) + agreements = fields.Nested('AgreementSchema', many=True, allow_none=True) parent = fields.Nested('AgreementSchema', only=('id', 'name'), allow_none=True) marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'), allow_none=True) name = fields.Str(allow_none=True) @@ -347,19 +347,19 @@ def make_object(self, data): class ContractSchema(BaseSchema): - name = fields.Str() - version = fields.Int() - type = fields.Str() - status = fields.Str() - agreement = fields.Nested(AgreementSchema, only=('id', 'name')) + name = fields.Str(allow_none=True) + version = fields.Int(allow_none=True) + type = fields.Str(allow_none=True) + status = fields.Str(allow_none=True) + agreement = fields.Nested(AgreementSchema, only=('id', 'name'), allow_none=True) marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'), allow_none=True) owner = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) - creator = fields.Nested(UserSchema, only=('id', 'name')) - created = fields.DateTime() - updated = fields.DateTime() + creator = fields.Nested(UserSchema, only=('id', 'name'), allow_none=True) + created = fields.DateTime(allow_none=True) + updated = fields.DateTime(allow_none=True) enrolled = fields.DateTime(allow_none=True) - version_created = fields.DateTime() - activation = fields.Nested(ActivationSchema) + version_created = fields.DateTime(allow_none=True) + activation = fields.Nested(ActivationSchema, allow_none=True) signee = fields.Nested(UserSchema, only=('id', 'name'), allow_none=True) @post_load @@ -369,8 +369,8 @@ def make_object(self, data): class ProductConfigurationSchema(BaseSchema): - suspend_resume_supported = fields.Bool() - requires_reseller_information = fields.Bool() + suspend_resume_supported = fields.Bool(allow_none=True) + requires_reseller_information = fields.Bool(allow_none=True) @post_load def make_object(self, data): @@ -379,10 +379,10 @@ def make_object(self, data): class CustomerUiSettingsSchema(BaseSchema): - description = fields.Str() - getting_started = fields.Str() - download_links = fields.Nested(DownloadLinkSchema, many=True) - documents = fields.Nested(DocumentSchema, many=True) + description = fields.Str(allow_none=True) + getting_started = fields.Str(allow_none=True) + download_links = fields.Nested(DownloadLinkSchema, many=True, allow_none=True) + documents = fields.Nested(DocumentSchema, many=True, allow_none=True) @post_load def make_object(self, data): @@ -391,7 +391,7 @@ def make_object(self, data): class ProductFamilySchema(BaseSchema): - name = fields.Str() + name = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -400,7 +400,7 @@ def make_object(self, data): class ProductCategorySchema(BaseSchema): - name = fields.Str() + name = fields.Str(allow_none=True) parent = fields.Nested('ProductCategorySchema', allow_none=True) children = fields.Nested('ProductCategorySchema', many=True, allow_none=True) family = fields.Nested(ProductFamilySchema, allow_none=True) @@ -412,8 +412,8 @@ def make_object(self, data): class ProductStatsInfoSchema(BaseSchema): - distribution = fields.Int() - sourcing = fields.Int() + distribution = fields.Int(allow_none=True) + sourcing = fields.Int(allow_none=True) @post_load def make_object(self, data): @@ -422,9 +422,9 @@ def make_object(self, data): class ProductStatsSchema(BaseSchema): - listing = fields.Int() - agreements = fields.Nested(ProductStatsInfoSchema) - contracts = fields.Nested(ProductStatsInfoSchema) + listing = fields.Int(allow_none=True) + agreements = fields.Nested(ProductStatsInfoSchema, allow_none=True) + contracts = fields.Nested(ProductStatsInfoSchema, allow_none=True) @post_load def make_object(self, data): @@ -434,10 +434,10 @@ def make_object(self, data): class ProductConfigurationParameterSchema(BaseSchema): value = fields.Str(allow_none=True) - parameter = fields.Nested(ParamSchema) + parameter = fields.Nested(ParamSchema, allow_none=True) marketplace = fields.Nested(MarketplaceSchema, allow_none=True) item = fields.Nested(ItemSchema, allow_none=True) - events = fields.Nested(EventsSchema) + events = fields.Nested(EventsSchema, allow_none=True) constraints = fields.Nested(ConstraintsSchema, allow_none=True) @post_load @@ -447,14 +447,14 @@ def make_object(self, data): class ProductSchema(BaseSchema): - name = fields.Str() - icon = fields.Str() - short_description = fields.Str() - detailed_description = fields.Str() - version = fields.Int() + name = fields.Str(allow_none=True) + icon = fields.Str(allow_none=True) + short_description = fields.Str(allow_none=True) + detailed_description = fields.Str(allow_none=True) + version = fields.Int(allow_none=True) published_at = fields.DateTime(allow_none=True) - configurations = fields.Nested(ProductConfigurationSchema) - customer_ui_settings = fields.Nested(CustomerUiSettingsSchema) + configurations = fields.Nested(ProductConfigurationSchema, allow_none=True) + customer_ui_settings = fields.Nested(CustomerUiSettingsSchema, allow_none=True) category = fields.Nested(ProductCategorySchema, allow_none=True) owner = fields.Nested(CompanySchema, allow_none=True) latest = fields.Bool(allow_none=True) @@ -467,9 +467,9 @@ def make_object(self, data): class ServerErrorResponseSchema(Schema): - error_code = fields.Str() + error_code = fields.Str(allow_none=True) params = fields.Dict(allow_none=True) - errors = fields.List(fields.Str()) + errors = fields.Str(many=True, allow_none=True) @post_load def make_object(self, data): @@ -478,9 +478,9 @@ def make_object(self, data): class TemplateSchema(BaseSchema): - name = fields.Str() - representation = fields.Str() - body = fields.Str() + name = fields.Str(allow_none=True) + representation = fields.Str(allow_none=True) + body = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -489,7 +489,7 @@ def make_object(self, data): class ConfigurationSchema(BaseSchema): - params = fields.Nested(ParamSchema, many=True) + params = fields.Nested(ParamSchema, many=True, allow_none=True) @post_load def make_object(self, data): @@ -498,10 +498,10 @@ def make_object(self, data): class TierAccountSchema(BaseSchema): - name = fields.Str() - contact_info = fields.Nested(ContactInfoSchema) - external_id = ExternalIdField() - external_uid = fields.Str() + name = fields.Str(allow_none=True) + contact_info = fields.Nested(ContactInfoSchema, allow_none=True) + external_id = ExternalIdField(allow_none=True) + external_uid = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -510,7 +510,7 @@ def make_object(self, data): class TierAccountsSchema(Schema): - customer = fields.Nested(TierAccountSchema) + customer = fields.Nested(TierAccountSchema, allow_none=True) tier1 = fields.Nested(TierAccountSchema, allow_none=True) tier2 = fields.Nested(TierAccountSchema, allow_none=True) @@ -521,11 +521,11 @@ def make_object(self, data): class ConnectionSchema(BaseSchema): - type = fields.Str() - provider = fields.Nested(CompanySchema, only=('id', 'name')) - vendor = fields.Nested(CompanySchema, only=('id', 'name')) - product = fields.Nested(ProductSchema) - hub = fields.Nested(HubSchema) + type = fields.Str(allow_none=True) + provider = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) + vendor = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) + product = fields.Nested(ProductSchema, allow_none=True) + hub = fields.Nested(HubSchema, allow_none=True) @post_load def make_object(self, data): @@ -534,20 +534,20 @@ def make_object(self, data): class AssetSchema(BaseSchema): - status = fields.Str() - external_id = ExternalIdField() + status = fields.Str(allow_none=True) + external_id = ExternalIdField(allow_none=True) events = fields.Nested(EventsSchema, allow_none=True) external_uid = fields.Str(allow_none=True) external_name = fields.Str(allow_none=True) - product = fields.Nested(ProductSchema, only=('id', 'name')) + product = fields.Nested(ProductSchema, only=('id', 'name'), allow_none=True) connection = fields.Nested( - ConnectionSchema, only=('id', 'type', 'provider', 'vendor'), + ConnectionSchema, only=('id', 'type', 'provider', 'vendor'), allow_none=True ) contract = fields.Nested(ContractSchema, allow_none=True) marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - params = fields.Nested(ParamSchema, many=True) - tiers = fields.Nested(TierAccountsSchema) - items = fields.Nested(ItemSchema, many=True) + params = fields.Nested(ParamSchema, many=True, allow_none=True) + tiers = fields.Nested(TierAccountsSchema, allow_none=True) + items = fields.Nested(ItemSchema, many=True, allow_none=True) configuration = fields.Nested(ConfigurationSchema, allow_none=True) @post_load @@ -566,17 +566,17 @@ def _deserialize(self, value, attr, obj, **kwargs): class FulfillmentSchema(BaseSchema): - type = fields.Str() - created = fields.DateTime() - updated = fields.DateTime() - status = fields.Str() - params_form_url = fields.Str() - activation_key = fields.Str() - reason = fields.Str() - note = fields.Str() - asset = fields.Nested(AssetSchema) - contract = fields.Nested(ContractSchema, only=('id', 'name')) - marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name')) + type = fields.Str(allow_none=True) + created = fields.DateTime(allow_none=True) + updated = fields.DateTime(allow_none=True) + status = fields.Str(allow_none=True) + params_form_url = fields.Str(allow_none=True) + activation_key = fields.Str(allow_none=True) + reason = fields.Str(allow_none=True) + note = fields.Str(allow_none=True) + asset = fields.Nested(AssetSchema, allow_none=True) + contract = fields.Nested(ContractSchema, only=('id', 'name'), allow_none=True) + marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'), allow_none=True) assignee = AssigneeField(allow_none=True) @post_load @@ -586,16 +586,16 @@ def make_object(self, data): class TierConfigSchema(BaseSchema): - name = fields.Str() - account = fields.Nested(TierAccountSchema) - product = fields.Nested(ProductSchema) - tier_level = fields.Int() - params = fields.Nested(ParamSchema, many=True) - connection = fields.Nested(ConnectionSchema) + name = fields.Str(allow_none=True) + account = fields.Nested(TierAccountSchema, allow_none=True) + product = fields.Nested(ProductSchema, allow_none=True) + tier_level = fields.Int(allow_none=True) + params = fields.Nested(ParamSchema, many=True, allow_none=True) + connection = fields.Nested(ConnectionSchema, allow_none=True) open_request = fields.Nested(BaseSchema, allow_none=True) - template = fields.Nested(TemplateSchema) - contract = fields.Nested(ContractSchema) - marketplace = fields.Nested(MarketplaceSchema) + template = fields.Nested(TemplateSchema, allow_none=True) + contract = fields.Nested(ContractSchema, allow_none=True) + marketplace = fields.Nested(MarketplaceSchema, allow_none=True) configuration = fields.Nested(ConfigurationSchema, allow_none=True) events = fields.Nested(EventsSchema, allow_none=True) status = fields.Str(allow_none=True) @@ -607,15 +607,15 @@ def make_object(self, data): class TierConfigRequestSchema(BaseSchema): - type = fields.Str() - status = fields.Str() - configuration = fields.Nested(TierConfigSchema) - parent_configuration = fields.Nested(TierConfigSchema) - account = fields.Nested(TierAccountSchema) - product = fields.Nested(ProductSchema) - tier_level = fields.Int() - params = fields.Nested(ParamSchema, many=True) - environment = fields.Str() + type = fields.Str(allow_none=True) + status = fields.Str(allow_none=True) + configuration = fields.Nested(TierConfigSchema, allow_none=True) + parent_configuration = fields.Nested(TierConfigSchema, allow_none=True) + account = fields.Nested(TierAccountSchema, allow_none=True) + product = fields.Nested(ProductSchema, allow_none=True) + tier_level = fields.Int(allow_none=True) + params = fields.Nested(ParamSchema, many=True, allow_none=True) + environment = fields.Str(allow_none=True) assignee = fields.Nested(UserSchema, allow_none=True) template = fields.Nested(TemplateSchema, allow_none=True) reason = fields.Str(allow_none=True) @@ -633,8 +633,8 @@ def make_object(self, data): class UsageRecordsSchema(BaseSchema): - valid = fields.Int() - invalid = fields.Int() + valid = fields.Int(allow_none=True) + invalid = fields.Int(allow_none=True) @post_load def make_object(self, data): @@ -643,24 +643,24 @@ def make_object(self, data): class UsageFileSchema(BaseSchema): - name = fields.Str() - description = fields.Str() - note = fields.Str() - status = fields.Str() - created_by = fields.Str() - created_at = fields.Str() - upload_file_uri = fields.Str() - processed_file_uri = fields.Str() - product = fields.Nested(ProductSchema) - contract = fields.Nested(ContractSchema) - marketplace = fields.Nested(MarketplaceSchema) - vendor = fields.Nested(CompanySchema) - provider = fields.Nested(CompanySchema) - acceptance_note = fields.Str() - rejection_note = fields.Str() - error_details = fields.Str() - records = fields.Nested(UsageRecordsSchema) - events = fields.Nested(EventsSchema) + name = fields.Str(allow_none=True) + description = fields.Str(allow_none=True) + note = fields.Str(allow_none=True) + status = fields.Str(allow_none=True) + created_by = fields.Str(allow_none=True) + created_at = fields.Str(allow_none=True) + upload_file_uri = fields.Str(allow_none=True) + processed_file_uri = fields.Str(allow_none=True) + product = fields.Nested(ProductSchema, allow_none=True) + contract = fields.Nested(ContractSchema, allow_none=True) + marketplace = fields.Nested(MarketplaceSchema, allow_none=True) + vendor = fields.Nested(CompanySchema, allow_none=True) + provider = fields.Nested(CompanySchema, allow_none=True) + acceptance_note = fields.Str(allow_none=True) + rejection_note = fields.Str(allow_none=True) + error_details = fields.Str(allow_none=True) + records = fields.Nested(UsageRecordsSchema, allow_none=True) + events = fields.Nested(EventsSchema, allow_none=True) @post_load def make_object(self, data): @@ -669,14 +669,14 @@ def make_object(self, data): class UsageListingSchema(BaseSchema): - status = fields.Str() - contract = fields.Nested(ContractSchema) - product = fields.Nested(ProductSchema) - created = fields.Str() + status = fields.Str(allow_none=True) + contract = fields.Nested(ContractSchema, allow_none=True) + product = fields.Nested(ProductSchema, allow_none=True) + created = fields.Str(allow_none=True) # Undocumented fields (they appear in PHP SDK) - vendor = fields.Nested(CompanySchema) - provider = fields.Nested(CompanySchema) + vendor = fields.Nested(CompanySchema, allow_none=True) + provider = fields.Nested(CompanySchema, allow_none=True) @post_load def make_object(self, data): @@ -685,14 +685,14 @@ def make_object(self, data): class UsageRecordSchema(BaseSchema): - usage_record_id = fields.Str() - item_search_criteria = fields.Str() - item_search_value = fields.Str() - quantity = fields.Int() - start_time_utc = fields.Str() - end_time_utc = fields.Str() - asset_search_criteria = fields.Str() - asset_search_value = fields.Str() + usage_record_id = fields.Str(allow_none=True) + item_search_criteria = fields.Str(allow_none=True) + item_search_value = fields.Str(allow_none=True) + quantity = fields.Int(allow_none=True) + start_time_utc = fields.Str(allow_none=True) + end_time_utc = fields.Str(allow_none=True) + asset_search_criteria = fields.Str(allow_none=True) + asset_search_value = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -701,10 +701,10 @@ def make_object(self, data): class ConversationMessageSchema(BaseSchema): - conversation = fields.Str() - created = fields.DateTime() - creator = fields.Nested(UserSchema) - text = fields.Str() + conversation = fields.Str(allow_none=True) + created = fields.DateTime(allow_none=True) + creator = fields.Nested(UserSchema, allow_none=True) + text = fields.Str(allow_none=True) @post_load def make_object(self, data): @@ -713,11 +713,11 @@ def make_object(self, data): class ConversationSchema(BaseSchema): - instance_id = fields.Str() - created = fields.DateTime() - topic = fields.Str() - messages = fields.Nested(ConversationMessageSchema, many=True) - creator = fields.Nested(UserSchema) + instance_id = fields.Str(allow_none=True) + created = fields.DateTime(allow_none=True) + topic = fields.Str(allow_none=True) + messages = fields.Nested(ConversationMessageSchema, many=True, allow_none=True) + creator = fields.Nested(UserSchema, allow_none=True) @post_load def make_object(self, data): diff --git a/connect/models/tier_config.py b/connect/models/tier_config.py index 651028a..7491199 100644 --- a/connect/models/tier_config.py +++ b/connect/models/tier_config.py @@ -17,17 +17,6 @@ from .tier_account import TierAccount from .schemas import TierConfigSchema - def get_param_by_id(self, param_id): - """ - :param str param_id: Id of the parameter. - :return: A Param by ID, or None if it was not found. - :rtype: Param - """ - try: - return list(filter(lambda p: p.id == param_id, self.params))[0] - except IndexError: - return None - class TierConfig(BaseModel): """ Full representation of Tier object. """ From c1da21d4c21371e11b9e7f98f1ea478dfe608c17 Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Tue, 22 Oct 2019 10:08:10 +0200 Subject: [PATCH 6/7] Improved Fulfillment example for the documentation. --- examples/fulfillment.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/fulfillment.py b/examples/fulfillment.py index 48856cd..35ede92 100644 --- a/examples/fulfillment.py +++ b/examples/fulfillment.py @@ -41,8 +41,7 @@ def process_request(self, request): if request.type == 'purchase': for item in request.asset.items: if item.quantity > 100000: - raise FailRequest( - message='Is Not possible to purchase product') + raise FailRequest('Is not possible to purchase product in such quantities') for param in request.asset.params: if param.name == 'email' and not param.value: @@ -50,17 +49,25 @@ def process_request(self, request): 'please provide one' raise InquireRequest(params=[param]) - # Approve by ActivationTile - return ActivationTileResponse('\n # Welcome to Fallball!\n\nYes, you decided ' - 'to have an account in our amazing service!') - # Or - # return TemplateResource().render(pk='TEMPLATE_ID', request_id=request.id) + # Find a param by its id + param = request.asset.get_param_by_id('purchase_id') + if param: + param.value = '...' # We can assign the id given by the external service here + self.update_parameters(request.id, [param]) # Update param on the platform + else: + raise FailRequest('The asset is expected to have a "purchase_id" param.') # Approve by Template - # return ActivationTemplateResponse('TL-497-535-242') + return ActivationTemplateResponse('TL-497-535-242') # Or # return TemplateResource().get(pk='TEMPLATE_ID') + # Approve by ActivationTile + # return ActivationTileResponse('\n # Welcome to Fallball!\n\nYes, you decided ' + # 'to have an account in our amazing service!') + # Or + # return TemplateResource().render(pk='TEMPLATE_ID', request_id=request.id) + elif request.type == 'change': # Fail raise FailRequest() From da6c37364402d53890ccfd7bb35faf05a32aa3b3 Mon Sep 17 00:00:00 2001 From: Javier San Juan Cervera Date: Tue, 22 Oct 2019 18:11:25 +0200 Subject: [PATCH 7/7] BaseSchema has been set to allow null on all fields. --- connect/models/schemas.py | 565 +++++++++++++++++++------------------- 1 file changed, 285 insertions(+), 280 deletions(-) diff --git a/connect/models/schemas.py b/connect/models/schemas.py index 8b4abf9..8411e00 100644 --- a/connect/models/schemas.py +++ b/connect/models/schemas.py @@ -10,6 +10,11 @@ class BaseSchema(Schema): id = fields.Str() + # Set allow_none to True in all fields + def on_bind_field(self, field_name, field_obj): + super(BaseSchema, self).on_bind_field(field_name, field_obj) + field_obj.allow_none = True + @post_load def make_object(self, data): from connect.models import BaseModel @@ -17,9 +22,9 @@ def make_object(self, data): class ActivationSchema(BaseSchema): - link = fields.Str(allow_none=True) - message = fields.Str(allow_none=True) - date = fields.DateTime(allow_none=True) + link = fields.Str() + message = fields.Str() + date = fields.DateTime() @post_load def make_object(self, data): @@ -28,8 +33,8 @@ def make_object(self, data): class AgreementStatsSchema(BaseSchema): - contracts = fields.Int(allow_none=True) - versions = fields.Int(allow_none=True) + contracts = fields.Int() + versions = fields.Int() @post_load def make_object(self, data): @@ -38,7 +43,7 @@ def make_object(self, data): class CompanySchema(BaseSchema): - name = fields.Str(allow_none=True) + name = fields.Str() @post_load def make_object(self, data): @@ -47,10 +52,10 @@ def make_object(self, data): class PhoneNumberSchema(BaseSchema): - country_code = fields.Str(allow_none=True) - area_code = fields.Str(allow_none=True) - phone_number = fields.Str(allow_none=True) - extension = fields.Str(allow_none=True) + country_code = fields.Str() + area_code = fields.Str() + phone_number = fields.Str() + extension = fields.Str() @post_load def make_object(self, data): @@ -59,10 +64,10 @@ def make_object(self, data): class ContactSchema(BaseSchema): - email = fields.Str(allow_none=True) - first_name = fields.Str(allow_none=True) - last_name = fields.Str(allow_none=True) - phone_number = fields.Nested(PhoneNumberSchema, allow_none=True) + email = fields.Str() + first_name = fields.Str() + last_name = fields.Str() + phone_number = fields.Nested(PhoneNumberSchema) @post_load def make_object(self, data): @@ -71,13 +76,13 @@ def make_object(self, data): class ContactInfoSchema(BaseSchema): - address_line1 = fields.Str(allow_none=True) - address_line2 = fields.Str(allow_none=True) - city = fields.Str(allow_none=True) - contact = fields.Nested(ContactSchema, allow_none=True) - country = fields.Str(allow_none=True) - postal_code = fields.Str(allow_none=True) - state = fields.Str(allow_none=True) + address_line1 = fields.Str() + address_line2 = fields.Str() + city = fields.Str() + contact = fields.Nested(ContactSchema) + country = fields.Str() + postal_code = fields.Str() + state = fields.Str() @post_load def make_object(self, data): @@ -86,8 +91,8 @@ def make_object(self, data): class ValueChoiceSchema(Schema): - value = fields.Str(allow_none=True) - label = fields.Str(allow_none=True) + value = fields.Str() + label = fields.Str() @post_load def make_object(self, data): @@ -96,10 +101,10 @@ def make_object(self, data): class ConstraintsSchema(BaseSchema): - hidden = fields.Bool(allow_none=True) - required = fields.Bool(allow_none=True) - choices = fields.Nested(ValueChoiceSchema, many=True, allow_none=True) - unique = fields.Bool(allow_none=True) + hidden = fields.Bool() + required = fields.Bool() + choices = fields.Nested(ValueChoiceSchema, many=True) + unique = fields.Bool() @post_load def make_object(self, data): @@ -108,8 +113,8 @@ def make_object(self, data): class DocumentSchema(BaseSchema): - title = fields.Str(allow_none=True) - url = fields.Str(allow_none=True) + title = fields.Str() + url = fields.Str() @post_load def make_object(self, data): @@ -118,9 +123,9 @@ def make_object(self, data): class DownloadLinkSchema(BaseSchema): - title = fields.Str(allow_none=True) - url = fields.Str(allow_none=True) - visible_for = fields.Str(allow_none=True) + title = fields.Str() + url = fields.Str() + visible_for = fields.Str() @post_load def make_object(self, data): @@ -129,8 +134,8 @@ def make_object(self, data): class UserSchema(BaseSchema): - name = fields.Str(allow_none=True) - email = fields.Str(allow_none=True) + name = fields.Str() + email = fields.Str() @post_load def make_object(self, data): @@ -139,8 +144,8 @@ def make_object(self, data): class EventSchema(BaseSchema): - at = fields.DateTime(allow_none=True) - by = fields.Nested(UserSchema, allow_none=True) + at = fields.DateTime() + by = fields.Nested(UserSchema) @post_load def make_object(self, data): @@ -149,17 +154,17 @@ def make_object(self, data): class EventsSchema(BaseSchema): - created = fields.Nested(EventSchema, allow_none=True) - inquired = fields.Nested(EventSchema, allow_none=True) - pended = fields.Nested(EventSchema, allow_none=True) - validated = fields.Nested(EventSchema, allow_none=True) - updated = fields.Nested(EventSchema, allow_none=True) - approved = fields.Nested(EventSchema, allow_none=True) - uploaded = fields.Nested(EventSchema, allow_none=True) - submitted = fields.Nested(EventSchema, allow_none=True) - accepted = fields.Nested(EventSchema, allow_none=True) - rejected = fields.Nested(EventSchema, allow_none=True) - closed = fields.Nested(EventSchema, allow_none=True) + created = fields.Nested(EventSchema) + inquired = fields.Nested(EventSchema) + pended = fields.Nested(EventSchema) + validated = fields.Nested(EventSchema) + updated = fields.Nested(EventSchema) + approved = fields.Nested(EventSchema) + uploaded = fields.Nested(EventSchema) + submitted = fields.Nested(EventSchema) + accepted = fields.Nested(EventSchema) + rejected = fields.Nested(EventSchema) + closed = fields.Nested(EventSchema) @post_load def make_object(self, data): @@ -168,7 +173,7 @@ def make_object(self, data): class HubInstanceSchema(BaseSchema): - type = fields.Str(allow_none=True) + type = fields.Str() @post_load def make_object(self, data): @@ -177,8 +182,8 @@ def make_object(self, data): class HubStatsSchema(BaseSchema): - connections = fields.Int(allow_none=True) - marketplaces = fields.Int(allow_none=True) + connections = fields.Int() + marketplaces = fields.Int() @post_load def make_object(self, data): @@ -187,12 +192,12 @@ def make_object(self, data): class HubSchema(BaseSchema): - name = fields.Str(allow_none=True) - company = fields.Nested(CompanySchema, allow_none=True) - description = fields.Str(allow_none=True) - instance = fields.Nested(HubInstanceSchema, allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) - stats = fields.Nested(HubStatsSchema, allow_none=True) + name = fields.Str() + company = fields.Nested(CompanySchema) + description = fields.Str() + instance = fields.Nested(HubInstanceSchema) + events = fields.Nested(EventsSchema) + stats = fields.Nested(HubStatsSchema) @post_load def make_object(self, data): @@ -211,8 +216,8 @@ def _deserialize(self, value, attr, obj, **kwargs): class ExtIdHubSchema(Schema): - hub = fields.Nested(HubSchema, only=('id', 'name'), allow_none=True) - external_id = ExternalIdField(allow_none=True) + hub = fields.Nested(HubSchema, only=('id', 'name')) + external_id = ExternalIdField() @post_load def make_object(self, data): @@ -221,10 +226,10 @@ def make_object(self, data): class RenewalSchema(BaseSchema): - from_ = fields.DateTime(load_from='from', allow_none=True) - to = fields.DateTime(allow_none=True) - period_delta = fields.Int(allow_none=True) - period_uom = fields.Str(allow_none=True) + from_ = fields.DateTime(load_from='from') + to = fields.DateTime() + period_delta = fields.Int() + period_uom = fields.Str() @post_load def make_object(self, data): @@ -253,13 +258,13 @@ def _deserialize(self, value, attr, obj, **kwargs): class MarketplaceSchema(BaseSchema): - name = fields.Str(allow_none=True) - description = fields.Str(allow_none=True) - active_contracts = fields.Int(allow_none=True) - icon = fields.Str(allow_none=True) - owner = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) - hubs = fields.Nested(ExtIdHubSchema, many=True, allow_none=True) - zone = fields.Str(allow_none=True) + name = fields.Str() + description = fields.Str() + active_contracts = fields.Int() + icon = fields.Str() + owner = fields.Nested(CompanySchema, only=('id', 'name')) + hubs = fields.Nested(ExtIdHubSchema, many=True) + zone = fields.Str() @post_load def make_object(self, data): @@ -268,9 +273,9 @@ def make_object(self, data): class CountrySchema(BaseSchema): - name = fields.Str(allow_none=True) - icon = fields.Str(allow_none=True) - zone = fields.Str(allow_none=True) + name = fields.Str() + icon = fields.Str() + zone = fields.Str() @post_load def make_object(self, data): @@ -279,22 +284,22 @@ def make_object(self, data): class ParamSchema(BaseSchema): - name = fields.Str(allow_none=True) - description = fields.Str(allow_none=True) - type = fields.Str(allow_none=True) - value = fields.Str(allow_none=True) - value_error = fields.Str(allow_none=True) - value_choice = fields.Str(many=True, allow_none=True) + name = fields.Str() + description = fields.Str() + type = fields.Str() + value = fields.Str() + value_error = fields.Str() + value_choice = fields.Str(many=True) # Undocumented fields (they appear in PHP SDK) - title = fields.Str(allow_none=True) - scope = fields.Str(allow_none=True) - constraints = fields.Nested(ConstraintsSchema, allow_none=True) - value_choices = fields.Nested(ValueChoiceSchema, many=True, allow_none=True) - phase = fields.Str(allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - countries = fields.Nested(CountrySchema, many=True, allow_none=True) + title = fields.Str() + scope = fields.Str() + constraints = fields.Nested(ConstraintsSchema) + value_choices = fields.Nested(ValueChoiceSchema, many=True) + phase = fields.Str() + events = fields.Nested(EventsSchema) + marketplace = fields.Nested(MarketplaceSchema) + countries = fields.Nested(CountrySchema, many=True) @post_load def make_object(self, data): @@ -303,17 +308,17 @@ def make_object(self, data): class ItemSchema(BaseSchema): - mpn = fields.Str(allow_none=True) - quantity = QuantityField(allow_none=True) - old_quantity = QuantityField(allow_none=True) - renewal = fields.Nested(RenewalSchema, allow_none=True) - params = fields.Nested(ParamSchema, many=True, allow_none=True) - display_name = fields.Str(allow_none=True) - global_id = fields.Str(allow_none=True) - item_type = fields.Str(allow_none=True) - period = fields.Str(allow_none=True) - type = fields.Str(allow_none=True) - name = fields.Str(allow_none=True) + mpn = fields.Str() + quantity = QuantityField() + old_quantity = QuantityField() + renewal = fields.Nested(RenewalSchema) + params = fields.Nested(ParamSchema, many=True) + display_name = fields.Str() + global_id = fields.Str() + item_type = fields.Str() + period = fields.Str() + type = fields.Str() + name = fields.Str() @post_load def make_object(self, data): @@ -322,23 +327,23 @@ def make_object(self, data): class AgreementSchema(BaseSchema): - type = fields.Str(allow_none=True) - title = fields.Str(allow_none=True) - description = fields.Str(allow_none=True) - created = fields.DateTime(allow_none=True) - updated = fields.DateTime(allow_none=True) - owner = fields.Nested(CompanySchema, allow_none=True) - stats = fields.Nested(AgreementStatsSchema, allow_none=True) - author = fields.Nested(UserSchema, allow_none=True) - version = fields.Int(allow_none=True) - active = fields.Bool(allow_none=True) - link = fields.Str(allow_none=True) - version_created = fields.DateTime(allow_none=True) - version_contracts = fields.Int(allow_none=True) - agreements = fields.Nested('AgreementSchema', many=True, allow_none=True) - parent = fields.Nested('AgreementSchema', only=('id', 'name'), allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'), allow_none=True) - name = fields.Str(allow_none=True) + type = fields.Str() + title = fields.Str() + description = fields.Str() + created = fields.DateTime() + updated = fields.DateTime() + owner = fields.Nested(CompanySchema) + stats = fields.Nested(AgreementStatsSchema) + author = fields.Nested(UserSchema) + version = fields.Int() + active = fields.Bool() + link = fields.Str() + version_created = fields.DateTime() + version_contracts = fields.Int() + agreements = fields.Nested('AgreementSchema', many=True) + parent = fields.Nested('AgreementSchema', only=('id', 'name')) + marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name')) + name = fields.Str() @post_load def make_object(self, data): @@ -347,20 +352,20 @@ def make_object(self, data): class ContractSchema(BaseSchema): - name = fields.Str(allow_none=True) - version = fields.Int(allow_none=True) - type = fields.Str(allow_none=True) - status = fields.Str(allow_none=True) - agreement = fields.Nested(AgreementSchema, only=('id', 'name'), allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'), allow_none=True) - owner = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) - creator = fields.Nested(UserSchema, only=('id', 'name'), allow_none=True) - created = fields.DateTime(allow_none=True) - updated = fields.DateTime(allow_none=True) - enrolled = fields.DateTime(allow_none=True) - version_created = fields.DateTime(allow_none=True) - activation = fields.Nested(ActivationSchema, allow_none=True) - signee = fields.Nested(UserSchema, only=('id', 'name'), allow_none=True) + name = fields.Str() + version = fields.Int() + type = fields.Str() + status = fields.Str() + agreement = fields.Nested(AgreementSchema, only=('id', 'name')) + marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name')) + owner = fields.Nested(CompanySchema, only=('id', 'name')) + creator = fields.Nested(UserSchema, only=('id', 'name')) + created = fields.DateTime() + updated = fields.DateTime() + enrolled = fields.DateTime() + version_created = fields.DateTime() + activation = fields.Nested(ActivationSchema) + signee = fields.Nested(UserSchema, only=('id', 'name')) @post_load def make_object(self, data): @@ -369,8 +374,8 @@ def make_object(self, data): class ProductConfigurationSchema(BaseSchema): - suspend_resume_supported = fields.Bool(allow_none=True) - requires_reseller_information = fields.Bool(allow_none=True) + suspend_resume_supported = fields.Bool() + requires_reseller_information = fields.Bool() @post_load def make_object(self, data): @@ -379,10 +384,10 @@ def make_object(self, data): class CustomerUiSettingsSchema(BaseSchema): - description = fields.Str(allow_none=True) - getting_started = fields.Str(allow_none=True) - download_links = fields.Nested(DownloadLinkSchema, many=True, allow_none=True) - documents = fields.Nested(DocumentSchema, many=True, allow_none=True) + description = fields.Str() + getting_started = fields.Str() + download_links = fields.Nested(DownloadLinkSchema, many=True) + documents = fields.Nested(DocumentSchema, many=True) @post_load def make_object(self, data): @@ -391,7 +396,7 @@ def make_object(self, data): class ProductFamilySchema(BaseSchema): - name = fields.Str(allow_none=True) + name = fields.Str() @post_load def make_object(self, data): @@ -400,10 +405,10 @@ def make_object(self, data): class ProductCategorySchema(BaseSchema): - name = fields.Str(allow_none=True) - parent = fields.Nested('ProductCategorySchema', allow_none=True) - children = fields.Nested('ProductCategorySchema', many=True, allow_none=True) - family = fields.Nested(ProductFamilySchema, allow_none=True) + name = fields.Str() + parent = fields.Nested('ProductCategorySchema') + children = fields.Nested('ProductCategorySchema', many=True) + family = fields.Nested(ProductFamilySchema) @post_load def make_object(self, data): @@ -412,8 +417,8 @@ def make_object(self, data): class ProductStatsInfoSchema(BaseSchema): - distribution = fields.Int(allow_none=True) - sourcing = fields.Int(allow_none=True) + distribution = fields.Int() + sourcing = fields.Int() @post_load def make_object(self, data): @@ -422,9 +427,9 @@ def make_object(self, data): class ProductStatsSchema(BaseSchema): - listing = fields.Int(allow_none=True) - agreements = fields.Nested(ProductStatsInfoSchema, allow_none=True) - contracts = fields.Nested(ProductStatsInfoSchema, allow_none=True) + listing = fields.Int() + agreements = fields.Nested(ProductStatsInfoSchema) + contracts = fields.Nested(ProductStatsInfoSchema) @post_load def make_object(self, data): @@ -433,12 +438,12 @@ def make_object(self, data): class ProductConfigurationParameterSchema(BaseSchema): - value = fields.Str(allow_none=True) - parameter = fields.Nested(ParamSchema, allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - item = fields.Nested(ItemSchema, allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) - constraints = fields.Nested(ConstraintsSchema, allow_none=True) + value = fields.Str() + parameter = fields.Nested(ParamSchema) + marketplace = fields.Nested(MarketplaceSchema) + item = fields.Nested(ItemSchema) + events = fields.Nested(EventsSchema) + constraints = fields.Nested(ConstraintsSchema) @post_load def make_object(self, data): @@ -447,18 +452,18 @@ def make_object(self, data): class ProductSchema(BaseSchema): - name = fields.Str(allow_none=True) - icon = fields.Str(allow_none=True) - short_description = fields.Str(allow_none=True) - detailed_description = fields.Str(allow_none=True) - version = fields.Int(allow_none=True) - published_at = fields.DateTime(allow_none=True) - configurations = fields.Nested(ProductConfigurationSchema, allow_none=True) - customer_ui_settings = fields.Nested(CustomerUiSettingsSchema, allow_none=True) - category = fields.Nested(ProductCategorySchema, allow_none=True) - owner = fields.Nested(CompanySchema, allow_none=True) - latest = fields.Bool(allow_none=True) - stats = fields.Nested(ProductStatsSchema, allow_none=True) + name = fields.Str() + icon = fields.Str() + short_description = fields.Str() + detailed_description = fields.Str() + version = fields.Int() + published_at = fields.DateTime() + configurations = fields.Nested(ProductConfigurationSchema) + customer_ui_settings = fields.Nested(CustomerUiSettingsSchema) + category = fields.Nested(ProductCategorySchema) + owner = fields.Nested(CompanySchema) + latest = fields.Bool() + stats = fields.Nested(ProductStatsSchema) @post_load def make_object(self, data): @@ -467,9 +472,9 @@ def make_object(self, data): class ServerErrorResponseSchema(Schema): - error_code = fields.Str(allow_none=True) - params = fields.Dict(allow_none=True) - errors = fields.Str(many=True, allow_none=True) + error_code = fields.Str() + params = fields.Dict() + errors = fields.Str(many=True) @post_load def make_object(self, data): @@ -478,9 +483,9 @@ def make_object(self, data): class TemplateSchema(BaseSchema): - name = fields.Str(allow_none=True) - representation = fields.Str(allow_none=True) - body = fields.Str(allow_none=True) + name = fields.Str() + representation = fields.Str() + body = fields.Str() @post_load def make_object(self, data): @@ -489,7 +494,7 @@ def make_object(self, data): class ConfigurationSchema(BaseSchema): - params = fields.Nested(ParamSchema, many=True, allow_none=True) + params = fields.Nested(ParamSchema, many=True) @post_load def make_object(self, data): @@ -498,10 +503,10 @@ def make_object(self, data): class TierAccountSchema(BaseSchema): - name = fields.Str(allow_none=True) - contact_info = fields.Nested(ContactInfoSchema, allow_none=True) - external_id = ExternalIdField(allow_none=True) - external_uid = fields.Str(allow_none=True) + name = fields.Str() + contact_info = fields.Nested(ContactInfoSchema) + external_id = ExternalIdField() + external_uid = fields.Str() @post_load def make_object(self, data): @@ -510,9 +515,9 @@ def make_object(self, data): class TierAccountsSchema(Schema): - customer = fields.Nested(TierAccountSchema, allow_none=True) - tier1 = fields.Nested(TierAccountSchema, allow_none=True) - tier2 = fields.Nested(TierAccountSchema, allow_none=True) + customer = fields.Nested(TierAccountSchema) + tier1 = fields.Nested(TierAccountSchema) + tier2 = fields.Nested(TierAccountSchema) @post_load def make_object(self, data): @@ -521,11 +526,11 @@ def make_object(self, data): class ConnectionSchema(BaseSchema): - type = fields.Str(allow_none=True) - provider = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) - vendor = fields.Nested(CompanySchema, only=('id', 'name'), allow_none=True) - product = fields.Nested(ProductSchema, allow_none=True) - hub = fields.Nested(HubSchema, allow_none=True) + type = fields.Str() + provider = fields.Nested(CompanySchema, only=('id', 'name')) + vendor = fields.Nested(CompanySchema, only=('id', 'name')) + product = fields.Nested(ProductSchema) + hub = fields.Nested(HubSchema) @post_load def make_object(self, data): @@ -534,21 +539,21 @@ def make_object(self, data): class AssetSchema(BaseSchema): - status = fields.Str(allow_none=True) - external_id = ExternalIdField(allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) - external_uid = fields.Str(allow_none=True) - external_name = fields.Str(allow_none=True) - product = fields.Nested(ProductSchema, only=('id', 'name'), allow_none=True) + status = fields.Str() + external_id = ExternalIdField() + events = fields.Nested(EventsSchema) + external_uid = fields.Str() + external_name = fields.Str() + product = fields.Nested(ProductSchema, only=('id', 'name')) connection = fields.Nested( - ConnectionSchema, only=('id', 'type', 'provider', 'vendor'), allow_none=True + ConnectionSchema, only=('id', 'type', 'provider', 'vendor') ) - contract = fields.Nested(ContractSchema, allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - params = fields.Nested(ParamSchema, many=True, allow_none=True) - tiers = fields.Nested(TierAccountsSchema, allow_none=True) - items = fields.Nested(ItemSchema, many=True, allow_none=True) - configuration = fields.Nested(ConfigurationSchema, allow_none=True) + contract = fields.Nested(ContractSchema) + marketplace = fields.Nested(MarketplaceSchema) + params = fields.Nested(ParamSchema, many=True) + tiers = fields.Nested(TierAccountsSchema) + items = fields.Nested(ItemSchema, many=True) + configuration = fields.Nested(ConfigurationSchema) @post_load def make_object(self, data): @@ -566,18 +571,18 @@ def _deserialize(self, value, attr, obj, **kwargs): class FulfillmentSchema(BaseSchema): - type = fields.Str(allow_none=True) - created = fields.DateTime(allow_none=True) - updated = fields.DateTime(allow_none=True) - status = fields.Str(allow_none=True) - params_form_url = fields.Str(allow_none=True) - activation_key = fields.Str(allow_none=True) - reason = fields.Str(allow_none=True) - note = fields.Str(allow_none=True) - asset = fields.Nested(AssetSchema, allow_none=True) - contract = fields.Nested(ContractSchema, only=('id', 'name'), allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'), allow_none=True) - assignee = AssigneeField(allow_none=True) + type = fields.Str() + created = fields.DateTime() + updated = fields.DateTime() + status = fields.Str() + params_form_url = fields.Str() + activation_key = fields.Str() + reason = fields.Str() + note = fields.Str() + asset = fields.Nested(AssetSchema) + contract = fields.Nested(ContractSchema, only=('id', 'name')) + marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name')) + assignee = AssigneeField() @post_load def make_object(self, data): @@ -586,19 +591,19 @@ def make_object(self, data): class TierConfigSchema(BaseSchema): - name = fields.Str(allow_none=True) - account = fields.Nested(TierAccountSchema, allow_none=True) - product = fields.Nested(ProductSchema, allow_none=True) - tier_level = fields.Int(allow_none=True) - params = fields.Nested(ParamSchema, many=True, allow_none=True) - connection = fields.Nested(ConnectionSchema, allow_none=True) - open_request = fields.Nested(BaseSchema, allow_none=True) - template = fields.Nested(TemplateSchema, allow_none=True) - contract = fields.Nested(ContractSchema, allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - configuration = fields.Nested(ConfigurationSchema, allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) - status = fields.Str(allow_none=True) + name = fields.Str() + account = fields.Nested(TierAccountSchema) + product = fields.Nested(ProductSchema) + tier_level = fields.Int() + params = fields.Nested(ParamSchema, many=True) + connection = fields.Nested(ConnectionSchema) + open_request = fields.Nested(BaseSchema) + template = fields.Nested(TemplateSchema) + contract = fields.Nested(ContractSchema) + marketplace = fields.Nested(MarketplaceSchema) + configuration = fields.Nested(ConfigurationSchema) + events = fields.Nested(EventsSchema) + status = fields.Str() @post_load def make_object(self, data): @@ -607,24 +612,24 @@ def make_object(self, data): class TierConfigRequestSchema(BaseSchema): - type = fields.Str(allow_none=True) - status = fields.Str(allow_none=True) - configuration = fields.Nested(TierConfigSchema, allow_none=True) - parent_configuration = fields.Nested(TierConfigSchema, allow_none=True) - account = fields.Nested(TierAccountSchema, allow_none=True) - product = fields.Nested(ProductSchema, allow_none=True) - tier_level = fields.Int(allow_none=True) - params = fields.Nested(ParamSchema, many=True, allow_none=True) - environment = fields.Str(allow_none=True) - assignee = fields.Nested(UserSchema, allow_none=True) - template = fields.Nested(TemplateSchema, allow_none=True) - reason = fields.Str(allow_none=True) - activation = fields.Nested(ActivationSchema, allow_none=True) - notes = fields.Str(allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) - tiers = fields.Nested(TierAccountsSchema, allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - contract = fields.Nested(ContractSchema, allow_none=True) + type = fields.Str() + status = fields.Str() + configuration = fields.Nested(TierConfigSchema) + parent_configuration = fields.Nested(TierConfigSchema) + account = fields.Nested(TierAccountSchema) + product = fields.Nested(ProductSchema) + tier_level = fields.Int() + params = fields.Nested(ParamSchema, many=True) + environment = fields.Str() + assignee = fields.Nested(UserSchema) + template = fields.Nested(TemplateSchema) + reason = fields.Str() + activation = fields.Nested(ActivationSchema) + notes = fields.Str() + events = fields.Nested(EventsSchema) + tiers = fields.Nested(TierAccountsSchema) + marketplace = fields.Nested(MarketplaceSchema) + contract = fields.Nested(ContractSchema) @post_load def make_object(self, data): @@ -633,8 +638,8 @@ def make_object(self, data): class UsageRecordsSchema(BaseSchema): - valid = fields.Int(allow_none=True) - invalid = fields.Int(allow_none=True) + valid = fields.Int() + invalid = fields.Int() @post_load def make_object(self, data): @@ -643,24 +648,24 @@ def make_object(self, data): class UsageFileSchema(BaseSchema): - name = fields.Str(allow_none=True) - description = fields.Str(allow_none=True) - note = fields.Str(allow_none=True) - status = fields.Str(allow_none=True) - created_by = fields.Str(allow_none=True) - created_at = fields.Str(allow_none=True) - upload_file_uri = fields.Str(allow_none=True) - processed_file_uri = fields.Str(allow_none=True) - product = fields.Nested(ProductSchema, allow_none=True) - contract = fields.Nested(ContractSchema, allow_none=True) - marketplace = fields.Nested(MarketplaceSchema, allow_none=True) - vendor = fields.Nested(CompanySchema, allow_none=True) - provider = fields.Nested(CompanySchema, allow_none=True) - acceptance_note = fields.Str(allow_none=True) - rejection_note = fields.Str(allow_none=True) - error_details = fields.Str(allow_none=True) - records = fields.Nested(UsageRecordsSchema, allow_none=True) - events = fields.Nested(EventsSchema, allow_none=True) + name = fields.Str() + description = fields.Str() + note = fields.Str() + status = fields.Str() + created_by = fields.Str() + created_at = fields.Str() + upload_file_uri = fields.Str() + processed_file_uri = fields.Str() + product = fields.Nested(ProductSchema) + contract = fields.Nested(ContractSchema) + marketplace = fields.Nested(MarketplaceSchema) + vendor = fields.Nested(CompanySchema) + provider = fields.Nested(CompanySchema) + acceptance_note = fields.Str() + rejection_note = fields.Str() + error_details = fields.Str() + records = fields.Nested(UsageRecordsSchema) + events = fields.Nested(EventsSchema) @post_load def make_object(self, data): @@ -669,14 +674,14 @@ def make_object(self, data): class UsageListingSchema(BaseSchema): - status = fields.Str(allow_none=True) - contract = fields.Nested(ContractSchema, allow_none=True) - product = fields.Nested(ProductSchema, allow_none=True) - created = fields.Str(allow_none=True) + status = fields.Str() + contract = fields.Nested(ContractSchema) + product = fields.Nested(ProductSchema) + created = fields.Str() # Undocumented fields (they appear in PHP SDK) - vendor = fields.Nested(CompanySchema, allow_none=True) - provider = fields.Nested(CompanySchema, allow_none=True) + vendor = fields.Nested(CompanySchema) + provider = fields.Nested(CompanySchema) @post_load def make_object(self, data): @@ -685,14 +690,14 @@ def make_object(self, data): class UsageRecordSchema(BaseSchema): - usage_record_id = fields.Str(allow_none=True) - item_search_criteria = fields.Str(allow_none=True) - item_search_value = fields.Str(allow_none=True) - quantity = fields.Int(allow_none=True) - start_time_utc = fields.Str(allow_none=True) - end_time_utc = fields.Str(allow_none=True) - asset_search_criteria = fields.Str(allow_none=True) - asset_search_value = fields.Str(allow_none=True) + usage_record_id = fields.Str() + item_search_criteria = fields.Str() + item_search_value = fields.Str() + quantity = fields.Int() + start_time_utc = fields.Str() + end_time_utc = fields.Str() + asset_search_criteria = fields.Str() + asset_search_value = fields.Str() @post_load def make_object(self, data): @@ -701,10 +706,10 @@ def make_object(self, data): class ConversationMessageSchema(BaseSchema): - conversation = fields.Str(allow_none=True) - created = fields.DateTime(allow_none=True) - creator = fields.Nested(UserSchema, allow_none=True) - text = fields.Str(allow_none=True) + conversation = fields.Str() + created = fields.DateTime() + creator = fields.Nested(UserSchema) + text = fields.Str() @post_load def make_object(self, data): @@ -713,11 +718,11 @@ def make_object(self, data): class ConversationSchema(BaseSchema): - instance_id = fields.Str(allow_none=True) - created = fields.DateTime(allow_none=True) - topic = fields.Str(allow_none=True) - messages = fields.Nested(ConversationMessageSchema, many=True, allow_none=True) - creator = fields.Nested(UserSchema, allow_none=True) + instance_id = fields.Str() + created = fields.DateTime() + topic = fields.Str() + messages = fields.Nested(ConversationMessageSchema, many=True) + creator = fields.Nested(UserSchema) @post_load def make_object(self, data):