Skip to content

Commit

Permalink
Merge pull request #694 from microsoftgraph/shem/replace_me_token_to_…
Browse files Browse the repository at this point in the history
…replace

replace users/me-token-to-replace with /me
  • Loading branch information
shemogumbe authored Oct 2, 2024
2 parents 504bfac + e8aeff7 commit 39a618f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
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

0 comments on commit 39a618f

Please sign in to comment.