diff --git a/connect/models/country.py b/connect/models/country.py index 90792b9..f26e649 100644 --- a/connect/models/country.py +++ b/connect/models/country.py @@ -8,12 +8,12 @@ class Country(BaseModel): - """ An instance of a hub. """ + """ Country data. """ _schema = CountrySchema() name = None # type: str - """ (str) Country name """ + """ (str) Country name. """ icon = None # type: str """ (str) Icon path. """ diff --git a/connect/models/fulfillment.py b/connect/models/fulfillment.py index 2677e3e..d35aa47 100644 --- a/connect/models/fulfillment.py +++ b/connect/models/fulfillment.py @@ -4,6 +4,7 @@ # Copyright (c) 2019 Ingram Micro. All Rights Reserved. import datetime +from typing import Union from .asset import Asset from .base import BaseModel @@ -73,8 +74,8 @@ class Fulfillment(BaseModel): marketplace = None # type: Marketplace """ (:py:class:`.Marketplace`) Marketplace object. """ - assignee = None # type: User - """ (:py:class:`.User`) Details of the user assigned to the request. """ + assignee = None # type: Union[User, str, None] + """ (:py:class:`.User` | None) Details of the user assigned to the request. """ @property def new_items(self): diff --git a/connect/models/product_stats.py b/connect/models/product_stats.py index 2da7e8d..4b6d65e 100644 --- a/connect/models/product_stats.py +++ b/connect/models/product_stats.py @@ -20,4 +20,4 @@ class ProductStats(BaseModel): """ (:py:class:`.ProductStatsInfo`) Agreements related to the product. """ contracts = None # type: ProductStatsInfo - """ (:py:class:`.ProductStatsInfo`) Contracts related to the product """ + """ (:py:class:`.ProductStatsInfo`) Contracts related to the product. """ diff --git a/connect/models/schemas.py b/connect/models/schemas.py index 3d20f55..78ff6c8 100644 --- a/connect/models/schemas.py +++ b/connect/models/schemas.py @@ -545,6 +545,15 @@ def make_object(self, data): return Asset(**data) +class AssigneeField(fields.Field): + def _deserialize(self, value, attr, obj, **kwargs): + from connect.models.user import User + if isinstance(value, six.string_types): + return value + else: + return User.deserialize_json(value) + + class FulfillmentSchema(BaseSchema): type = fields.Str() created = fields.DateTime() @@ -557,7 +566,7 @@ class FulfillmentSchema(BaseSchema): asset = fields.Nested(AssetSchema) contract = fields.Nested(ContractSchema, only=('id', 'name')) marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name')) - assignee = fields.Nested(UserSchema, allow_none=True) + assignee = AssigneeField(allow_none=True) @post_load def make_object(self, data): diff --git a/tests/data/response.json b/tests/data/response.json index fabe6f6..53029e2 100644 --- a/tests/data/response.json +++ b/tests/data/response.json @@ -105,6 +105,7 @@ "reason": "", "status": "approved", "type": "purchase", - "updated": "2019-02-19T19:28:11.053922+00:00" + "updated": "2019-02-19T19:28:11.053922+00:00", + "assignee": "" } ] diff --git a/tests/data/response2.json b/tests/data/response2.json index 3740ef1..a32a23a 100644 --- a/tests/data/response2.json +++ b/tests/data/response2.json @@ -255,6 +255,9 @@ "id": "PR-5620-6510-8214", "status": "approved", "type": "purchase", - "updated": "2018-09-04T10:38:58.045330+00:00" + "updated": "2018-09-04T10:38:58.045330+00:00", + "assignee": { + "id": "Assignee" + } } ] \ No newline at end of file diff --git a/tests/test_models.py b/tests/test_models.py index 5a21ad4..c1732fa 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -9,7 +9,7 @@ import six from mock import MagicMock, patch -from connect.models import Asset, Param, Fulfillment, Item, TierConfig, Configuration +from connect.models import Asset, Param, Fulfillment, Item, TierConfig, Configuration, User from connect.resources import FulfillmentAutomation from .common import Response, load_str @@ -102,6 +102,7 @@ def test_create_model_from_response(): assert request_obj.asset.id == content['asset']['id'] assert request_obj.asset.product.id == content['asset']['product']['id'] assert isinstance(request_obj.asset.external_id, six.string_types) + assert request_obj.assignee == '' @patch('requests.get', MagicMock(return_value=_get_response_ok2())) @@ -112,6 +113,8 @@ def test_fulfillment_items(): assert len(requests) == 1 request = requests[0] assert isinstance(request, Fulfillment) + assert isinstance(request.assignee, User) + assert request.assignee.id == 'Assignee' # Test new items new_items = request.new_items