Skip to content

replace users/me-token-to-replace with /me #694

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

Merged
merged 3 commits into from
Oct 2, 2024
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
4 changes: 2 additions & 2 deletions src/msgraph_core/requests/batch_request_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
self.method = request_information.http_method
self._headers = request_information.request_headers
self._body = request_information.content
self.url = request_information.url
self.url = request_information.url.replace('/users/me-token-to-replace', '/me', 1)
self._depends_on: Optional[List[str]] = []
if depends_on is not None:
self.set_depends_on(depends_on)
Expand Down Expand Up @@ -101,7 +101,7 @@ def set_url(self, url: str) -> None:
f"Error occurred during regex replacement of API version in URL string: {url}"
)

relative_url = re.sub(self.ME_TOKEN_REGEX, '/me', relative_url, 1)
relative_url = relative_url.replace('/users/me-token-to-replace', '/me', 1)
if not relative_url:
raise ValueError(
f"""Error occurred during regex replacement
Expand Down
37 changes: 37 additions & 0 deletions tests/requests/test_batch_request_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@ def test_set_url(batch_request_item):
assert batch_request_item.url == "/v1.0/me"


def test_constructor_url_replacement():
request_info = RequestInformation()
request_info.http_method = "GET"
request_info.url = "https://graph.microsoft.com/v1.0/users/me-token-to-replace"
request_info.headers = RequestHeaders()
request_info.content = None

batch_request_item = BatchRequestItem(request_info)

assert batch_request_item.url == "https://graph.microsoft.com/v1.0/me"


def test_set_url_replacement():
request_info = RequestInformation()
request_info.http_method = "GET"
request_info.url = "https://graph.microsoft.com/v1.0/users/me-token-to-replace"
request_info.headers = RequestHeaders()
request_info.content = None

batch_request_item = BatchRequestItem(request_info)
batch_request_item.set_url("https://graph.microsoft.com/v1.0/users/me-token-to-replace")

assert batch_request_item.url == "/v1.0/me"


def test_constructor_url_replacement_with_query():
request_info = RequestInformation()
request_info.http_method = "GET"
request_info.url = "https://graph.microsoft.com/v1.0/users/me-token-to-replace?param=value"
request_info.headers = RequestHeaders()
request_info.content = None

batch_request_item = BatchRequestItem(request_info)

assert batch_request_item.url == "https://graph.microsoft.com/v1.0/me?param=value"


def test_id_property(batch_request_item):
batch_request_item.id = "new_id"
assert batch_request_item.id == "new_id"
Expand Down
Loading