Skip to content

Commit 0d24648

Browse files
Fix error parsing Fulfillment.assignee.
1 parent efc1eea commit 0d24648

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

connect/models/country.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99

1010
class Country(BaseModel):
11-
""" An instance of a hub. """
11+
""" Country data. """
1212

1313
_schema = CountrySchema()
1414

1515
name = None # type: str
16-
""" (str) Country name """
16+
""" (str) Country name. """
1717

1818
icon = None # type: str
1919
""" (str) Icon path. """

connect/models/fulfillment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.
55

66
import datetime
7+
from typing import Union
78

89
from .asset import Asset
910
from .base import BaseModel
@@ -73,8 +74,8 @@ class Fulfillment(BaseModel):
7374
marketplace = None # type: Marketplace
7475
""" (:py:class:`.Marketplace`) Marketplace object. """
7576

76-
assignee = None # type: User
77-
""" (:py:class:`.User`) Details of the user assigned to the request. """
77+
assignee = None # type: Union[User, str, None]
78+
""" (:py:class:`.User` | None) Details of the user assigned to the request. """
7879

7980
@property
8081
def new_items(self):

connect/models/product_stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class ProductStats(BaseModel):
2020
""" (:py:class:`.ProductStatsInfo`) Agreements related to the product. """
2121

2222
contracts = None # type: ProductStatsInfo
23-
""" (:py:class:`.ProductStatsInfo`) Contracts related to the product """
23+
""" (:py:class:`.ProductStatsInfo`) Contracts related to the product. """

connect/models/schemas.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,15 @@ def make_object(self, data):
545545
return Asset(**data)
546546

547547

548+
class AssigneeField(fields.Field):
549+
def _deserialize(self, value, attr, obj, **kwargs):
550+
from connect.models.user import User
551+
if isinstance(value, six.string_types):
552+
return value
553+
else:
554+
return User.deserialize_json(value)
555+
556+
548557
class FulfillmentSchema(BaseSchema):
549558
type = fields.Str()
550559
created = fields.DateTime()
@@ -557,7 +566,7 @@ class FulfillmentSchema(BaseSchema):
557566
asset = fields.Nested(AssetSchema)
558567
contract = fields.Nested(ContractSchema, only=('id', 'name'))
559568
marketplace = fields.Nested(MarketplaceSchema, only=('id', 'name'))
560-
assignee = fields.Nested(UserSchema, allow_none=True)
569+
assignee = AssigneeField(allow_none=True)
561570

562571
@post_load
563572
def make_object(self, data):

tests/data/response.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"reason": "",
106106
"status": "approved",
107107
"type": "purchase",
108-
"updated": "2019-02-19T19:28:11.053922+00:00"
108+
"updated": "2019-02-19T19:28:11.053922+00:00",
109+
"assignee": ""
109110
}
110111
]

tests/data/response2.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@
255255
"id": "PR-5620-6510-8214",
256256
"status": "approved",
257257
"type": "purchase",
258-
"updated": "2018-09-04T10:38:58.045330+00:00"
258+
"updated": "2018-09-04T10:38:58.045330+00:00",
259+
"assignee": {
260+
"id": "Assignee"
261+
}
259262
}
260263
]

tests/test_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import six
1010
from mock import MagicMock, patch
1111

12-
from connect.models import Asset, Param, Fulfillment, Item, TierConfig, Configuration
12+
from connect.models import Asset, Param, Fulfillment, Item, TierConfig, Configuration, User
1313
from connect.resources import FulfillmentAutomation
1414
from .common import Response, load_str
1515

@@ -102,6 +102,7 @@ def test_create_model_from_response():
102102
assert request_obj.asset.id == content['asset']['id']
103103
assert request_obj.asset.product.id == content['asset']['product']['id']
104104
assert isinstance(request_obj.asset.external_id, six.string_types)
105+
assert request_obj.assignee == ''
105106

106107

107108
@patch('requests.get', MagicMock(return_value=_get_response_ok2()))
@@ -112,6 +113,8 @@ def test_fulfillment_items():
112113
assert len(requests) == 1
113114
request = requests[0]
114115
assert isinstance(request, Fulfillment)
116+
assert isinstance(request.assignee, User)
117+
assert request.assignee.id == 'Assignee'
115118

116119
# Test new items
117120
new_items = request.new_items

0 commit comments

Comments
 (0)