コード例 #1
0
    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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl", http_provider, auth_provider)

        items = client.drives["me"].items["testitem!id"].delta().request().get(
        )
        assert type(items.next_page_request) is ItemDeltaRequest
        assert type(items.next_page_request.get()) is ItemDeltaCollectionPage
コード例 #2
0
    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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("/", 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] == "/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())
コード例 #3
0
    def test_path_creation(self, MockHttpProvider, MockAuthProvider):
        """
        Tests that the path of a request is resolved correctly
        """
        http_provider = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", http_provider, auth_provider)

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

        request = client.drives["me"].items["root"].children[
            "testfile.txt"].request()
        assert request.request_url == "graphurl/drives/me/items/root/children/testfile.txt"
コード例 #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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", 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
コード例 #5
0
    def test_path_creation_with_query(self, MockHttpProvider,
                                      MockAuthProvider):
        """
        Tests that a path is created with the correct query parameters
        """
        http_provider = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", 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())
コード例 #6
0
    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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", http_provider, auth_provider)

        changes_request = client.drives["me"].items["testitem!id"].delta(
            token="token").request()
        assert urlparse(
            changes_request.request_url
        ).path == "graphurl/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())
コード例 #7
0
    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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", http_provider, auth_provider)

        items = client.drives["me"].items["root"].children.request().get()
        
        assert type(items.next_page_request) is ChildrenCollectionRequest
        assert type(items.next_page_request.get()) is ChildrenCollectionPage
コード例 #8
0
    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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("/", 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] == "/drives/me/items/root/children/newFile.txt/content"
コード例 #9
0
    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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", http_provider, auth_provider)

        items = client.drives["me"].items["root"].children.request().get()
        
        assert len(items) == 2
        assert type(items) is ChildrenCollectionPage
        assert items[0].name == "test1"
        assert type(items[0].folder) is Folder
        assert items[1].folder is None
コード例 #10
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 = msgraph.HttpProvider()
        auth_provider = msgraph.AuthProvider()
        client = msgraph.GraphClient("graphurl/", 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 == "graphurl/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())