Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify making a post in Python configuring the headers #3962

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
}
]
},
"./tests/Kiota.Builder.IntegrationTests/ToDoApi.yaml": {
"MockServerITFolder": "todo"
},
"./tests/Kiota.Builder.IntegrationTests/InheritingErrors.yaml": {
"MockServerITFolder": "basic",
"Suppressions": [
Expand Down
17 changes: 8 additions & 9 deletions it/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ build-backend = "flit_core.buildapi"

[project]
name = "integration-test"
authors = [{name = "Microsoft", email = "[email protected]"}]
authors = [{ name = "Microsoft", email = "[email protected]" }]
dependencies = [
"uritemplate >=4.1.1",
"microsoft-kiota-abstractions >= 0.6.0",
"microsoft-kiota-http >= 0.4.4",
"microsoft-kiota-authentication-azure >= 0.2.0",
"microsoft-kiota-serialization-json >= 0.3.7",
"microsoft-kiota-serialization-text >= 0.2.1"
"microsoft-kiota-abstractions >= 1.0.0",
"microsoft-kiota-http >= 1.2.0",
"microsoft-kiota-authentication-azure >= 1.0.0",
"microsoft-kiota-serialization-json >= 1.0.0",
"microsoft-kiota-serialization-text >= 1.0.0",
]
license = {file = "LICENSE"}
license = { file = "LICENSE" }
readme = "README.md"
keywords = ["kiota"]
classifiers = [
Expand Down Expand Up @@ -44,4 +43,4 @@ each_dict_entry_on_separate_line = true
column_limit = 100

[tool.isort]
profile = "hug"
profile = "hug"
25 changes: 25 additions & 0 deletions it/python/todo/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from kiota_abstractions.headers_collection import HeadersCollection
from kiota_abstractions.authentication.anonymous_authentication_provider import (
AnonymousAuthenticationProvider,
)
from kiota_http.httpx_request_adapter import HttpxRequestAdapter

from client.api_client import ApiClient
from client.models.new_todo import NewTodo
from client.todos.todos_request_builder import TodosRequestBuilder

@pytest.mark.asyncio
async def test_basic_upload_download():
auth_provider = AnonymousAuthenticationProvider()
request_adapter = HttpxRequestAdapter(auth_provider)
request_adapter.base_url = 'http://127.0.0.1:1080'
client = ApiClient(request_adapter)

myHeaders = HeadersCollection()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the nasty detail, it looks like a lot of boilerplate for something that we used to write as:

config = TodosRequestBuilder.TodosRequestBuilderPostRequestConfiguration(
        headers = { "My-Extra-Header", "hello" }
 )

Either we add more helper methods to make the conversion automatic for the user or, at the very least, we should add a constructor from Dict[str, str | List[str]] to HeadersCollection.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for context to others reading this. It's being discussed here microsoft/kiota-python#208

myHeaders.add("My-Extra-Header", "hello")
config = TodosRequestBuilder.TodosRequestBuilderPostRequestConfiguration(
headers = myHeaders
)

await client.todos.post(NewTodo(), config)