How to use onedrivesdk - 10 common examples

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 xybu / onedrived-dev / tests / test_repo.py View on Github external
def setUp(self):
        self.temp_config_dir, self.temp_repo_dir, self.drive_config, self.repo = get_sample_repo()
        self.root_folder_item = onedrivesdk.Item(json.loads(get_resource('data/folder_item.json', pkg_name='tests')))
        self.root_subfolder_item = onedrivesdk.Item(json.loads(
            get_resource('data/subfolder_item.json', pkg_name='tests')))
        self.root_child_item = onedrivesdk.Item(json.loads(
            get_resource('data/folder_child_item.json', pkg_name='tests')))
        self.image_item = onedrivesdk.Item(json.loads(get_resource('data/image_item.json', pkg_name='tests')))
        self._add_all_items()
github xybu / onedrived-dev / tests / test_tasks.py View on Github external
def test_remote_dir_matches_record(self):
        item = onedrivesdk.Item(json.loads(get_resource('data/folder_item.json', pkg_name='tests')))
        self.repo.update_item(item, '', size_local=0)
        record = self.repo.get_item_by_path(item.name, '')
        merge_dir.MergeDirectoryTask._remote_dir_matches_record(item, record)
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 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"}))
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_requests.py View on Github external
def test_method_query_format(self, MockHttpProvider, MockAuthProvider):
        """
        Test that the parameters are correctly entered into the query string
        of the request for methods that require this
        """
        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider()
        client = onedrivesdk.OneDriveClient("onedriveurl/", http_provider, auth_provider)

        changes_request = client.drives["me"].items["testitem!id"].delta(token="token").request()
        assert urlparse(changes_request.request_url).path == "onedriveurl/drives/me/items/testitem!id/view.delta"

        query_dict = dict(parse_qsl(urlparse(changes_request.request_url).query))
        expected_dict = {"token":"token"}
        assert all(item in query_dict.items() for item in expected_dict.items())
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_streams.py View on Github external
def test_download(self, MockHttpProvider, MockAuthProvider):

        path = "./myPath/myFile.txt"
        response = HttpResponse(200, None, None)

        instance = MockHttpProvider.return_value
        instance.download.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)
        client.drives["me"].items["root"].children["newFile.txt"].content.request().download(path)

        assert client.http_provider.download.call_args[0][2] == path
        assert client.http_provider.download.call_args[0][1] == "onedriveurl/drives/me/items/root/children/newFile.txt/content"
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_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