Skip to content

Commit

Permalink
Merge pull request #45 from mweber-qvantel/master
Browse files Browse the repository at this point in the history
Adapt to aiohttp > 3, fix deprecation warnings, fix weird bug
  • Loading branch information
mweber-qvantel authored Feb 26, 2020
2 parents 6762112 + ca85f49 commit 0e44a49
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pytest-mock
pytest
asynctest
jsonschema
aiohttp
aiohttp>=3.0
aiodns
sphinx
sphinx-autodoc-annotation
pytest-cov
coveralls
coveralls
4 changes: 2 additions & 2 deletions src/jsonapi_client/relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def add(self, new_value: Union[R_IDENT_TYPES, Iterable[R_IDENT_TYPES]], type_=No
"""
if type_ is None:
type_ = self.type
if isinstance(new_value, collections.Iterable):
if isinstance(new_value, collections.abc.Iterable):
self._resource_identifiers.extend(
[self._value_to_identifier(val, type_) for val in new_value])
else:
Expand Down Expand Up @@ -424,7 +424,7 @@ def url(self) -> str:

def set(self, new_value: Union[Iterable[R_IDENT_TYPES], R_IDENT_TYPES],
type_: str='') -> None:
if isinstance(new_value, collections.Iterable):
if isinstance(new_value, collections.abc.Iterable):
if self.is_single:
logger.warning('This should contain list of resources, '
'but only one is given')
Expand Down
13 changes: 9 additions & 4 deletions src/jsonapi_client/resourceobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def __init__(self, data: dict,
for field_name, field_spec in specification['properties'].items():
if field_spec.get('type') == 'object':
_data = data.pop(field_name, {})
# Workaround a strange bug where _data is None instead of
# default value {}
if _data is None:
_data = {}
self[field_name] = AttributeDict(data=_data,
name=field_name,
parent=self,
Expand All @@ -102,10 +106,11 @@ def __init__(self, data: dict,
logger.warning('There was extra data (not specified in schema): %s',
data)
# If not, we will use the source data as it is.
self.update(data)
for key, value in data.items():
if isinstance(value, dict):
self[key] = AttributeDict(data=value, name=key, parent=self, resource=resource)
if data:
self.update(data)
for key, value in data.items():
if isinstance(value, dict):
self[key] = AttributeDict(data=value, name=key, parent=self, resource=resource)
self._dirty_attributes.clear()

def create_map(self, attr_name):
Expand Down
2 changes: 1 addition & 1 deletion src/jsonapi_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def create(self, _type: str, fields: dict=None, **more_fields) -> 'ResourceObjec
res_types = props['resource']
if isinstance(value, RESOURCE_TYPES + (str,)):
value = self._value_to_dict(value, res_types)
elif isinstance(value, collections.Iterable):
elif isinstance(value, collections.abc.Iterable):
value = [self._value_to_dict(id_, res_types) for id_ in value]
rels[key] = {'data': value}
else:
Expand Down
5 changes: 3 additions & 2 deletions tests/json/api/leases/qvantel-lease1/external-references.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"meta": {
"type": "valid-for-datetime"
}
}
},
"null-field": null
},
"relationships": {
"target": {
Expand All @@ -31,4 +32,4 @@
"links": {
"self": "/api/leases/qvantel-lease1/external-references"
}
}
}
3 changes: 3 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
'format': 'date-time',
'type': ['string', 'null']}},
'required': ['start-datetime'],
'type': 'object'},
'null-field': {'properties': {'useless-field': {'type': ['string',
'null']}},
'type': 'object'}},
'type': 'object'}

Expand Down

0 comments on commit 0e44a49

Please sign in to comment.