Skip to content

Commit 7d7d679

Browse files
author
Joel Collins
committed
Tidied up client fixtures
1 parent 65d3b0e commit 7d7d679

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tests/test_server_decorators.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def put(self, args):
179179

180180
app.add_url_rule("/", view_func=WrappedCls.as_view("index"))
181181

182-
with app.test_client() as c:
182+
with client as c:
183183
assert c.get("/").data == b'{"integer":1}\n'
184184
assert c.post("/", json={"integer": 5}).data == b'{"integer":5}\n'
185185
assert c.put("/", json={"integer": 5}).data == b'{"integer":5}\n'
@@ -204,7 +204,7 @@ def post(self, data):
204204

205205
app.add_url_rule("/", view_func=Index.as_view("index"))
206206

207-
with app.test_client() as c:
207+
with client as c:
208208
assert c.post("/", data=b"5\n").data == b"5"
209209

210210

@@ -220,7 +220,7 @@ def post(self, data):
220220

221221
app.add_url_rule("/", view_func=Index.as_view("index"))
222222

223-
with app.test_client() as c:
223+
with client as c:
224224
assert c.post("/").status_code == 400
225225

226226

@@ -237,7 +237,7 @@ def post(self, data):
237237

238238
app.add_url_rule("/", view_func=Index.as_view("index"))
239239

240-
with app.test_client() as c:
240+
with client as c:
241241
assert c.post("/").status_code == 200
242242

243243

@@ -253,7 +253,7 @@ def post(self, data):
253253

254254
app.add_url_rule("/", view_func=Index.as_view("index"))
255255

256-
with app.test_client() as c:
256+
with client as c:
257257
assert c.post("/").data == b"5"
258258

259259

@@ -269,7 +269,7 @@ def post(self, data):
269269

270270
app.add_url_rule("/", view_func=Index.as_view("index"))
271271

272-
with app.test_client() as c:
272+
with client as c:
273273
assert c.post("/", data=b"{}").status_code == 400
274274

275275

@@ -285,7 +285,7 @@ def post(self, data):
285285

286286
app.add_url_rule("/", view_func=Index.as_view("index"))
287287

288-
with app.test_client() as c:
288+
with client as c:
289289
assert c.post("/", json={"integer": 5}).data == b"{'integer': 5}"
290290

291291

@@ -301,7 +301,7 @@ def post(self, data):
301301

302302
app.add_url_rule("/", view_func=Index.as_view("index"))
303303

304-
with app.test_client() as c:
304+
with client as c:
305305
assert c.post("/").data == b"5"
306306

307307

tests/test_server_view_builder.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
from labthings.server.view import builder
44

55

6-
def test_property_of(app):
6+
def test_property_of(app, client):
77
obj = type("obj", (object,), {"property_name": "propertyValue"})
88

99
GeneratedClass = builder.property_of(obj, "property_name")
1010
app.add_url_rule("/", view_func=GeneratedClass.as_view("index"))
1111

12-
with app.test_client() as c:
12+
with client as c:
1313
assert c.get("/").data == b"propertyValue"
1414
assert c.post("/", data=b"newPropertyValue").data == b"newPropertyValue"
1515
assert c.get("/").data == b"newPropertyValue"
1616

1717

18-
def test_property_of_dict(app):
18+
def test_property_of_dict(app, client):
1919
obj = type(
2020
"obj",
2121
(object,),
@@ -30,7 +30,7 @@ def test_property_of_dict(app):
3030
GeneratedClass = builder.property_of(obj, "properties")
3131
app.add_url_rule("/", view_func=GeneratedClass.as_view("index"))
3232

33-
with app.test_client() as c:
33+
with client as c:
3434
assert (
3535
c.get("/").data
3636
== b'{"property_name":"propertyValue","property_name_2":"propertyValue2"}\n'
@@ -64,25 +64,25 @@ def test_property_of_name_description():
6464
assert GeneratedClass.__apispec__.get("summary") == "property description"
6565

6666

67-
def test_action_from(app):
67+
def test_action_from(app, client):
6868
def f(arg: int, kwarg: str = "default"):
6969
return {"arg": arg, "kwarg": kwarg}
7070

7171
GeneratedClass = builder.action_from(f)
7272
app.add_url_rule("/", view_func=GeneratedClass.as_view("index"))
7373

74-
with app.test_client() as c:
74+
with client as c:
7575
assert c.post("/", json={"arg": 5}).data == b'{"arg":5,"kwarg":"default"}\n'
7676

7777

78-
def test_action_from_task(app):
78+
def test_action_from_task(app, client):
7979
def f(arg: int, kwarg: str = "default"):
8080
return {"arg": arg, "kwarg": kwarg}
8181

8282
GeneratedClass = builder.action_from(f, task=True,)
8383
app.add_url_rule("/", view_func=GeneratedClass.as_view("index"))
8484

85-
with app.test_client() as c:
85+
with client as c:
8686
response = c.post("/", json={"arg": 5}).json
8787
# Check we get back a Task representation
8888
assert isinstance(response, dict)
@@ -103,15 +103,15 @@ def f(arg: int, kwarg: str = "default"):
103103
)
104104

105105

106-
def test_static_from(app, app_ctx, static_path):
106+
def test_static_from(app, client, app_ctx, static_path):
107107

108108
GeneratedClass = builder.static_from(static_path,)
109109
app.add_url_rule("/static", view_func=GeneratedClass.as_view("index"))
110110

111111
with app_ctx.test_request_context():
112112
assert GeneratedClass().get("text").status_code == 200
113113

114-
with app.test_client() as c:
114+
with client as c:
115115
assert c.get("/static/text").data == b"text"
116116

117117

0 commit comments

Comments
 (0)