Пример #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"]
Пример #2
0
    def test_method_body_format(self, MockHttpProvider, MockAuthProvider):
        """
        Test that the parameters are correctly entered into the body of the message
        of methods that require this
        """
        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider,
                                            auth_provider)

        ref = ItemReference()
        ref.id = "testing!id"

        copy_request = client.drives["me"].items["testitem!id"].copy(
            parent_reference=ref, name="newName").request()
        assert copy_request.request_url == "onedriveurl/drives/me/items/testitem!id/action.copy"

        expected_dict = {
            "parentReference": {
                "id": "testing!id"
            },
            "name": "newName"
        }
        assert all(item in copy_request.body_options.items()
                   for item in expected_dict.items())
Пример #3
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"

        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"
Пример #4
0
    def test_polling_background_method(self, MockHttpProvider,
                                       MockAuthProvider):
        """
        Test that polling in the background actually functions as it should and polls
        on a seperate thread.
        """
        response = HttpResponse(301, {"Location": "statusLocation"}, "")
        instance_http = MockHttpProvider.return_value
        instance_http.send.return_value = response

        instance_auth = MockAuthProvider.return_value
        instance_auth.authenticate.return_value = "blah"
        instance_auth.authenticate_request.return_value = None

        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider,
                                            auth_provider)

        ref = ItemReference()
        ref.id = "testing!id"
        mock = Mock()

        copy_operation = client.drives["me"].items["testitem!id"].copy(
            parent_reference=ref, name="newName").request().post()

        response = HttpResponse(
            200, None,
            json.dumps({
                "operation": "copy",
                "percentageComplete": 0,
                "status": "In progress"
            }))
        instance_http.send.return_value = response

        time.sleep(0.2)

        assert copy_operation.item is None

        response = HttpResponse(
            200, None, json.dumps({
                "id": "testitem!id",
                "name": "newName"
            }))
        instance_http.send.return_value = response

        time.sleep(0.1)

        assert copy_operation.item is not None
    def test_method_body_format(self, MockHttpProvider, MockAuthProvider):
        """
        Test that the parameters are correctly entered into the body of the message
        of methods that require this
        """
        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider, auth_provider)

        ref = ItemReference()
        ref.id = "testing!id"

        copy_request = client.drives["me"].items["testitem!id"].copy(parent_reference=ref, name="newName").request()
        assert copy_request.request_url == "onedriveurl/drives/me/items/testitem!id/action.copy"

        expected_dict = {"parentReference": {"id":"testing!id"}, "name":"newName"}
        assert all(item in copy_request.body_options.items() for item in expected_dict.items())
Пример #6
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"
Пример #7
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": "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"]
Пример #8
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"]
    def test_polling_background_method(self, MockHttpProvider, MockAuthProvider):
        """
        Test that polling in the background actually functions as it should and polls
        on a seperate thread.
        """
        response = HttpResponse(301, {"Location": "statusLocation"}, "")
        instance_http = MockHttpProvider.return_value
        instance_http.send.return_value = response

        instance_auth = MockAuthProvider.return_value
        instance_auth.authenticate.return_value = "blah"
        instance_auth.authenticate_request.return_value = None

        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider, auth_provider)

        ref = ItemReference()
        ref.id = "testing!id"
        mock = Mock()

        copy_operation = client.drives["me"].items["testitem!id"].copy(parent_reference=ref, name="newName").request().post()
        
        response = HttpResponse(200, None, json.dumps({"operation":"copy", "percentageComplete":0, "status": "In progress"}))
        instance_http.send.return_value = response
        
        time.sleep(0.2)

        assert copy_operation.item is None

        response = HttpResponse(200, None, json.dumps({"id" : "testitem!id", "name": "newName"}))
        instance_http.send.return_value = response

        time.sleep(0.1)

        assert copy_operation.item is not None