Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions connect/models/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down
5 changes: 3 additions & 2 deletions connect/models/fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion connect/models/product_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
11 changes: 10 additions & 1 deletion connect/models/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/data/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
]
5 changes: 4 additions & 1 deletion tests/data/response2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
5 changes: 4 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()))
Expand All @@ -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
Expand Down