How to use the onedrivesdk.OneDriveClient function in onedrivesdk

To help you get started, we’ve selected a few onedrivesdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OneDrive / onedrive-sdk-python / testonedrivesdk / test_requests.py View on Github external
def test_path_creation(self, MockHttpProvider, MockAuthProvider):
        """
        Tests that the path of a request is resolved correctly
        """
        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider, auth_provider)

        request = client.drives["me"].items["root"].children.request()
        assert request.request_url == "onedriveurl/drives/me/items/root/children"

        request = client.drives["me"].items["root"].children["testfile.txt"].request()
        assert request.request_url == "onedriveurl/drives/me/items/root/children/testfile.txt"
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_collections.py View on Github external
def test_paging(self, MockHttpProvider, MockAuthProvider):
        """
        Test paging of a file in situations where more than one page is available
        """
        response = HttpResponse(200, None, json.dumps({"@odata.nextLink":"testing", "value":[{"name":"test1", "folder":{}}, {"name":"test2"}]}))

        instance = MockHttpProvider.return_value
        instance.send.return_value = response

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

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

        items = client.drives["me"].items["root"].children.request().get()
        
        assert items._next_page_link is not None

        request = onedrivesdk.ChildrenCollectionRequest.get_next_page_request(items, client)
        assert isinstance(request, ChildrenCollectionRequest)
        assert isinstance(request.get(), ChildrenCollectionPage)
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_requests.py View on Github external
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
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_requests.py View on Github external
def test_path_creation_with_query(self, MockHttpProvider, MockAuthProvider):
        """
        Tests that a path is created with the correct query parameters
        """
        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider, auth_provider)

        request = client.drives["me"].items["root"].children.request(top=3, select="test")

        query_dict = dict(parse_qsl(urlparse(request.request_url).query))
        expected_dict = {"select":"test", "top":"3"}
        assert all(item in query_dict.items() for item in expected_dict.items())
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_collections.py View on Github external
def test_page_creation(self, MockHttpProvider, MockAuthProvider):
        """
        Test page creation when there is no nextLink attached to the collection
        """
        response = HttpResponse(200, None, json.dumps({"value":[{"name":"test1", "folder":{}}, {"name":"test2"}]}))

        instance = MockHttpProvider.return_value
        instance.send.return_value = response

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

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

        items = client.drives["me"].items["root"].children.request().get()
        
        assert len(items) == 2
        assert isinstance(items, ChildrenCollectionPage)
        assert items[0].name == "test1"
        assert isinstance(items[0].folder, Folder)
        assert items[1].folder is None
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_streams.py View on Github external
def test_put(self, MockHttpProvider, MockAuthProvider):

        response = HttpResponse(200, None, json.dumps({"name":"test1", "folder":{}, "id":"test!id"}))

        instance = MockHttpProvider.return_value
        instance.send.return_value = response

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

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

        response_item = client.drives["me"].items["root"].children["newFile.txt"].content.request().upload("./myPath/myFile.txt")

        assert client.http_provider.send.call_args[1]["path"] == "./myPath/myFile.txt"
        assert client.http_provider.send.call_args[0][2] == "onedriveurl/drives/me/items/root/children/newFile.txt/content"
        assert all(item in response_item._prop_dict.items() for item in json.loads(response.content).items())
github epam / OneDrive-L / onedrive_service / src / onedrive_service / authentication / base_client.py View on Github external
""" Base class for OneDrive clients.
"""

import os

import onedrivesdk


class BaseOneDriveClient(onedrivesdk.OneDriveClient):
    """ Base class for OneDrive API clients.
    """

    @staticmethod
    def check_saved_session_exists() -> bool:
        """ Returns 'True' if saved sessions exists.
        """

        current_path = os.getcwd()
        session_path = os.path.join(current_path, 'session.pickle')
        return os.path.exists(session_path)
github niqdev / packtpub-crawler / script / onedrive.py View on Github external
api_base_url = self.__config.get('onedrive', 'onedrive.api_base_url')
        client_id = self.__config.get('onedrive', 'onedrive.client_id')
        session_file = self.__config.get('onedrive', 'onedrive.session_file')

        if not exists(session_file):
            self.__save_credentials(session_file)

        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider(http_provider,
                                                client_id,
                                                self.__scopes)

        # Load the session
        auth_provider.load_session(path=session_file)
        auth_provider.refresh_token()
        self.__onedrive_service = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider)