Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ def __init__(
self,
method: Optional[Method] = None,
url_template: Optional[str] = None,
path_parameters: dict[str, Any] = {}
path_parameters: Optional[dict[str, Any]] = None
) -> None:
"""Creates a new instance of the RequestInformation class.

Args:
method (Method): The request method.
url_template (str): The given url template.
path_parameters (dict[str, Any], optional): Path parameters
for the request. Defaults to {}.
for the request. Defaults to a new empty dict.
"""
# The uri of the request
self.__uri: Optional[Url] = None

self.__request_options: dict[str, RequestOption] = {}

# The path parameters for the current request
self.path_parameters: dict[str, Any] = path_parameters
# The path parameters for the current request, a new dict unless the caller passes one
self.path_parameters: dict[str, Any] = {} if path_parameters is None else path_parameters

# The URL template for the request
self.url_template: Optional[str] = url_template
Expand Down
39 changes: 38 additions & 1 deletion packages/abstractions/tests/test_request_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,41 @@ def test_sets_time_only_values_in_path_parameters():
assert request_info.url == "https://example.com/daysFrom/00%3A20%3A00"





def test_each_request_information_gets_its_own_path_parameters():
first = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/messages")
second = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/calendar")

first.path_parameters["user%2Did"] = "alice"

assert first.path_parameters is not second.path_parameters
assert "user%2Did" not in second.path_parameters


def test_a_path_parameter_set_on_one_request_does_not_reach_another_url():
first = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/messages")
first.path_parameters.update({"baseurl": "https://graph.microsoft.com/v1.0", "user%2Did": "alice"})
second = RequestInformation(Method.GET, "{+baseurl}/me/calendar")
second.path_parameters["baseurl"] = "https://graph.microsoft.com/v1.0"

assert first.url == "https://graph.microsoft.com/v1.0/users/alice/messages"
assert second.path_parameters == {"baseurl": "https://graph.microsoft.com/v1.0"}


def test_passed_path_parameters_are_used_as_given():
path_parameters = {"baseurl": "https://graph.microsoft.com/v1.0"}

request_info = RequestInformation(Method.GET, "{+baseurl}/me", path_parameters)

assert request_info.path_parameters is path_parameters


def test_setting_a_raw_url_does_not_clear_another_requests_path_parameters():
templated = RequestInformation(Method.GET, "{+baseurl}/users/{user%2Did}/messages")
templated.path_parameters.update({"baseurl": "https://graph.microsoft.com/v1.0", "user%2Did": "bob"})
raw = RequestInformation(Method.GET)

raw.url = "https://graph.microsoft.com/v1.0/me/messages?$skiptoken=abc"

assert templated.url == "https://graph.microsoft.com/v1.0/users/bob/messages"
Loading