Skip to content

Commit 39a618f

Browse files
authored
Merge pull request #694 from microsoftgraph/shem/replace_me_token_to_replace
replace users/me-token-to-replace with /me
2 parents 504bfac + e8aeff7 commit 39a618f

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/msgraph_core/requests/batch_request_item.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
self.method = request_information.http_method
4343
self._headers = request_information.request_headers
4444
self._body = request_information.content
45-
self.url = request_information.url
45+
self.url = request_information.url.replace('/users/me-token-to-replace', '/me', 1)
4646
self._depends_on: Optional[List[str]] = []
4747
if depends_on is not None:
4848
self.set_depends_on(depends_on)
@@ -101,7 +101,7 @@ def set_url(self, url: str) -> None:
101101
f"Error occurred during regex replacement of API version in URL string: {url}"
102102
)
103103

104-
relative_url = re.sub(self.ME_TOKEN_REGEX, '/me', relative_url, 1)
104+
relative_url = relative_url.replace('/users/me-token-to-replace', '/me', 1)
105105
if not relative_url:
106106
raise ValueError(
107107
f"""Error occurred during regex replacement

tests/requests/test_batch_request_item.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,43 @@ def test_set_url(batch_request_item):
5050
assert batch_request_item.url == "/v1.0/me"
5151

5252

53+
def test_constructor_url_replacement():
54+
request_info = RequestInformation()
55+
request_info.http_method = "GET"
56+
request_info.url = "https://graph.microsoft.com/v1.0/users/me-token-to-replace"
57+
request_info.headers = RequestHeaders()
58+
request_info.content = None
59+
60+
batch_request_item = BatchRequestItem(request_info)
61+
62+
assert batch_request_item.url == "https://graph.microsoft.com/v1.0/me"
63+
64+
65+
def test_set_url_replacement():
66+
request_info = RequestInformation()
67+
request_info.http_method = "GET"
68+
request_info.url = "https://graph.microsoft.com/v1.0/users/me-token-to-replace"
69+
request_info.headers = RequestHeaders()
70+
request_info.content = None
71+
72+
batch_request_item = BatchRequestItem(request_info)
73+
batch_request_item.set_url("https://graph.microsoft.com/v1.0/users/me-token-to-replace")
74+
75+
assert batch_request_item.url == "/v1.0/me"
76+
77+
78+
def test_constructor_url_replacement_with_query():
79+
request_info = RequestInformation()
80+
request_info.http_method = "GET"
81+
request_info.url = "https://graph.microsoft.com/v1.0/users/me-token-to-replace?param=value"
82+
request_info.headers = RequestHeaders()
83+
request_info.content = None
84+
85+
batch_request_item = BatchRequestItem(request_info)
86+
87+
assert batch_request_item.url == "https://graph.microsoft.com/v1.0/me?param=value"
88+
89+
5390
def test_id_property(batch_request_item):
5491
batch_request_item.id = "new_id"
5592
assert batch_request_item.id == "new_id"

0 commit comments

Comments
 (0)