How to use the onedrivesdk.HttpProvider 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_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_collections(self, MockHttpProvider, MockAuthProvider):
        """
        Test that collections are returned properly from method calls that return collections
        """
        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["testitem!id"].delta().request().get()
        request = onedrivesdk.ItemDeltaRequest.get_next_page_request(items, client, None)
        assert type(request) is ItemDeltaRequest
        assert type(request.get()) is ItemDeltaCollectionPage
github OneDrive / onedrive-sdk-python / testonedrivesdk / test_requests.py View on Github external
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())
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_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 xybu / onedrived-dev / onedrived / od_auth.py View on Github external
def __init__(self):
        proxies = getproxies()
        if len(proxies) == 0:
            http_provider = onedrivesdk.HttpProvider()
        else:
            from onedrivesdk.helpers.http_provider_with_proxy import HttpProviderWithProxy
            http_provider = HttpProviderWithProxy(proxies, verify_ssl=True)
        auth_provider = onedrivesdk.AuthProvider(http_provider=http_provider,
                                                 client_id=self.APP_CLIENT_ID,
                                                 session_type=od_api_session.OneDriveAPISession,
                                                 scopes=self.APP_SCOPES)
        self.client = onedrivesdk.OneDriveClient(self.APP_BASE_URL, auth_provider, http_provider)
github epam / OneDrive-L / onedrive_service / src / onedrive_service / authentication / one_drive_client.py View on Github external
def __init__(self, config: dict) -> None:
        """ Basic initialization.
        """

        self._config = config
        client_id = config['auth']['client_id']
        scopes = config['auth']['scopes']

        http_provider = onedrivesdk.HttpProvider()
        auth_provider = onedrivesdk.AuthProvider(http_provider, client_id,
                                                 scopes, session_type=Session)

        super().__init__(API_BASE_URL, auth_provider, http_provider)
github niqdev / packtpub-crawler / script / onedrive.py View on Github external
def __init_service(self):
        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)