Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd16e41b

Browse files
test: convert usage ofmatch_querystring tomatch
In the `responses` library the usage of `match_querystring` isdeprecated. Convert to using `match`
1 parent5254f19 commitd16e41b

File tree

4 files changed

+104
-101
lines changed

4 files changed

+104
-101
lines changed

‎tests/unit/helpers.py‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
importdatetime
2+
importio
3+
importjson
4+
fromtypingimportOptional
5+
6+
importrequests
7+
8+
9+
# NOTE: The function `httmock_response` and the class `Headers` is taken from
10+
# https://github.com/patrys/httmock/ which is licensed under the Apache License, Version
11+
# 2.0. Thus it is allowed to be used in this project.
12+
# https://www.apache.org/licenses/GPL-compatibility.html
13+
classHeaders(object):
14+
def__init__(self,res):
15+
self.headers=res.headers
16+
17+
defget_all(self,name,failobj=None):
18+
returnself.getheaders(name)
19+
20+
defgetheaders(self,name):
21+
return [self.headers.get(name)]
22+
23+
24+
defhttmock_response(
25+
status_code:int=200,
26+
content:str="",
27+
headers=None,
28+
reason=None,
29+
elapsed=0,
30+
request:Optional[requests.models.PreparedRequest]=None,
31+
stream:bool=False,
32+
http_vsn=11,
33+
)->requests.models.Response:
34+
res=requests.Response()
35+
res.status_code=status_code
36+
ifisinstance(content, (dict,list)):
37+
content=json.dumps(content).encode("utf-8")
38+
ifisinstance(content,str):
39+
content=content.encode("utf-8")
40+
res._content=content
41+
res._content_consumed=content
42+
res.headers=requests.structures.CaseInsensitiveDict(headersor {})
43+
res.encoding=requests.utils.get_encoding_from_headers(res.headers)
44+
res.reason=reason
45+
res.elapsed=datetime.timedelta(elapsed)
46+
res.request=request
47+
ifhasattr(request,"url"):
48+
res.url=request.url
49+
ifisinstance(request.url,bytes):
50+
res.url=request.url.decode("utf-8")
51+
if"set-cookie"inres.headers:
52+
res.cookies.extract_cookies(
53+
requests.cookies.MockResponse(Headers(res)),
54+
requests.cookies.MockRequest(request),
55+
)
56+
ifstream:
57+
res.raw=io.BytesIO(content)
58+
else:
59+
res.raw=io.BytesIO(b"")
60+
res.raw.version=http_vsn
61+
62+
# normally this closes the underlying connection,
63+
# but we have nothing to free.
64+
res.close=lambda*args,**kwargs:None
65+
66+
returnres

‎tests/unit/mixins/test_mixin_methods.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class M(GetMixin, FakeManager):
3535
url=url,
3636
json={"id":42,"foo":"bar"},
3737
status=200,
38-
match_querystring=True,
38+
match=[responses.matchers.query_param_matcher({})],
3939
)
4040

4141
mgr=M(gl)
@@ -57,7 +57,7 @@ class TestClass(RefreshMixin, FakeObject):
5757
url=url,
5858
json={"id":42,"foo":"bar"},
5959
status=200,
60-
match_querystring=True,
60+
match=[responses.matchers.query_param_matcher({})],
6161
)
6262

6363
mgr=FakeManager(gl)
@@ -80,7 +80,7 @@ class M(GetWithoutIdMixin, FakeManager):
8080
url=url,
8181
json={"foo":"bar"},
8282
status=200,
83-
match_querystring=True,
83+
match=[responses.matchers.query_param_matcher({})],
8484
)
8585

8686
mgr=M(gl)
@@ -102,7 +102,7 @@ class M(ListMixin, FakeManager):
102102
url=url,
103103
json=[{"id":42,"foo":"bar"}, {"id":43,"foo":"baz"}],
104104
status=200,
105-
match_querystring=True,
105+
match=[responses.matchers.query_param_matcher({})],
106106
)
107107

108108
# test RESTObjectList
@@ -134,7 +134,7 @@ class M(ListMixin, FakeManager):
134134
url=url,
135135
json=[{"id":42,"foo":"bar"}],
136136
status=200,
137-
match_querystring=True,
137+
match=[responses.matchers.query_param_matcher({})],
138138
)
139139

140140
mgr=M(gl)
@@ -177,7 +177,7 @@ class M(CreateMixin, FakeManager):
177177
url=url,
178178
json={"id":42,"foo":"bar"},
179179
status=200,
180-
match_querystring=True,
180+
match=[responses.matchers.query_param_matcher({})],
181181
)
182182

183183
mgr=M(gl)
@@ -202,7 +202,7 @@ class M(CreateMixin, FakeManager):
202202
url=url,
203203
json={"id":42,"foo":"bar"},
204204
status=200,
205-
match_querystring=True,
205+
match=[responses.matchers.query_param_matcher({})],
206206
)
207207

208208
mgr=M(gl)
@@ -243,7 +243,7 @@ class M(UpdateMixin, FakeManager):
243243
url=url,
244244
json={"id":42,"foo":"baz"},
245245
status=200,
246-
match_querystring=True,
246+
match=[responses.matchers.query_param_matcher({})],
247247
)
248248

249249
mgr=M(gl)
@@ -268,7 +268,7 @@ class M(UpdateMixin, FakeManager):
268268
url=url,
269269
json={"foo":"baz"},
270270
status=200,
271-
match_querystring=True,
271+
match=[responses.matchers.query_param_matcher({})],
272272
)
273273

274274
mgr=M(gl)
@@ -289,7 +289,7 @@ class M(DeleteMixin, FakeManager):
289289
url=url,
290290
json="",
291291
status=200,
292-
match_querystring=True,
292+
match=[responses.matchers.query_param_matcher({})],
293293
)
294294

295295
mgr=M(gl)
@@ -311,7 +311,7 @@ class TestClass(SaveMixin, base.RESTObject):
311311
url=url,
312312
json={"id":42,"foo":"baz"},
313313
status=200,
314-
match_querystring=True,
314+
match=[responses.matchers.query_param_matcher({})],
315315
)
316316

317317
mgr=M(gl)
@@ -334,7 +334,7 @@ class M(SetMixin, FakeManager):
334334
url=url,
335335
json={"key":"foo","value":"bar"},
336336
status=200,
337-
match_querystring=True,
337+
match=[responses.matchers.query_param_matcher({})],
338338
)
339339

340340
mgr=M(gl)

‎tests/unit/test_gitlab.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def resp_page_1():
5858
"headers":headers,
5959
"content_type":"application/json",
6060
"status":200,
61-
"match_querystring":True,
61+
"match":[responses.matchers.query_param_matcher({})],
6262
}
6363

6464

@@ -81,7 +81,6 @@ def resp_page_2():
8181
"content_type":"application/json",
8282
"status":200,
8383
"match": [responses.matchers.query_param_matcher(params)],
84-
"match_querystring":False,
8584
}
8685

8786

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp