Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _mock_item(self, sha1_hash=None):
prop_dict = dict()
if sha1_hash:
prop_dict['sha1Hash'] = sha1_hash
item = Item(prop_dict={'file': {'hashes': prop_dict}})
self.assertEqual(sha1_hash, item.file.hashes.sha1_hash)
return item
def test_serialization(self):
"""
Test the serialization of the dict-backed models, seeing that
the correct objects are returned when called
"""
ref = ItemReference();
ref._prop_dict = {"id": self.id}
response = {"name":self.name, "folder":{}, "parentReference":ref._prop_dict, "lastModifiedDateTime": "2015-07-09T22:22:53.993000Z"}
item = Item();
item._prop_dict = response
assert isinstance(item.folder, Folder)
assert item.name == self.name
assert isinstance(item.parent_reference, ItemReference)
assert item.parent_reference.id == self.id
assert isinstance(item.last_modified_date_time, datetime)
assert item.last_modified_date_time.isoformat()+"Z" == response["lastModifiedDateTime"]
def test_serialization_different_datetime(self):
"""
Test the serialization of the dict-backed models, seeing that
the correct objects are returned when called. Specifically,
ensure that the datetime can be parsed correctly when the format
does not fit exactly what we always return
"""
ref = ItemReference();
ref._prop_dict = {"id": self.id}
response = {"name":self.name, "folder":{}, "parentReference":ref._prop_dict, "lastModifiedDateTime": "2015-07-09T22:22:53.99Z"}
item = Item();
item._prop_dict = response
assert isinstance(item.folder, Folder)
assert item.name == self.name
assert isinstance(item.parent_reference, ItemReference)
assert item.parent_reference.id == self.id
assert isinstance(item.last_modified_date_time, datetime)
assert item.last_modified_date_time.isoformat()+"Z" == "2015-07-09T22:22:53.990000Z"
response = {"name":self.name, "folder":{}, "parentReference":ref._prop_dict, "lastModifiedDateTime": "2015-07-09T22:22:53Z"}
item._prop_dict = response
assert isinstance(item.folder, Folder)
assert item.name == self.name
assert isinstance(item.parent_reference, ItemReference)
assert item.parent_reference.id == self.id