Example #1
0
    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"]
Example #2
0
 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": "thisisa!test"}

        response = {"name":"test1", "folder":{}, "parentReference":ref._prop_dict, "lastModifiedDateTime": "2015-07-09T22:22:53.993000Z"}

        item = Item();
        item._prop_dict = response

        assert type(item.folder) is Folder
        assert item.name == "test1"
        assert type(item.parent_reference) is ItemReference
        assert item.parent_reference.id == "thisisa!test"
        assert type(item.last_modified_date_time) == datetime
        assert item.last_modified_date_time.isoformat()+"Z" == response["lastModifiedDateTime"]
Example #4
0
 def add(self, entity):
     """Add a Item to the collection
     
     Args:
         entity (:class:`Item<onedrivesdk.model.item.Item>`):
             The Item that you would like to add to the collection
     
     Returns: 
         :class:`Item<onedrivesdk.model.item.Item>`:
             The Item that you added, with additional data from OneDrive
     """
     self.content_type = "application/json"
     self.method = "POST"
     entity = Item(json.loads(self.send(entity).content))
     return entity
    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
        assert isinstance(item.last_modified_date_time, datetime)
        assert item.last_modified_date_time.isoformat() + "Z" == "2015-07-09T22:22:53Z"

        timenow = datetime.now()
        item.last_modified_date_time = timenow
        assert item.last_modified_date_time.isoformat() == timenow.isoformat()
        assert item._prop_dict["lastModifiedDateTime"] == timenow.isoformat() + "Z"

        timenow = timenow.replace(microsecond=235)
        item.last_modified_date_time = timenow
        assert item.last_modified_date_time.isoformat() == timenow.isoformat()
        assert item._prop_dict["lastModifiedDateTime"] == timenow.isoformat() + "Z"

        timenow = timenow.replace(microsecond=0)
        item.last_modified_date_time = timenow
        assert item.last_modified_date_time.isoformat() == timenow.isoformat()
        assert item._prop_dict["lastModifiedDateTime"] == timenow.isoformat() + ".0Z"
    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"]
Example #7
0
    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"

        timenow = datetime.now()
        item.last_modified_date_time = timenow
        assert item.last_modified_date_time.isoformat() == timenow.isoformat()
        assert item._prop_dict['lastModifiedDateTime'] == timenow.isoformat(
        ) + "Z"

        timenow = timenow.replace(microsecond=235)
        item.last_modified_date_time = timenow
        assert item.last_modified_date_time.isoformat() == timenow.isoformat()
        assert item._prop_dict['lastModifiedDateTime'] == timenow.isoformat(
        ) + "Z"

        timenow = timenow.replace(microsecond=0)
        item.last_modified_date_time = timenow
        assert item.last_modified_date_time.isoformat() == timenow.isoformat()
        assert item._prop_dict['lastModifiedDateTime'] == timenow.isoformat(
        ) + ".0Z"