Skip to content

Commit d4a822e

Browse files
author
Fabien Coelho
committed
improve coverage tests on the request client
1 parent bedfa5a commit d4a822e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Diff for: FlaskTester.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def check(self, method: str, path: str, status: int, content: str|None = None, *
299299
return res
300300

301301

302-
class RequestClient(Client): # pragma: no cover
302+
class RequestClient(Client):
303303
"""Request-based test provider."""
304304

305305
def __init__(self, auth: Authenticator, base_url: str, default_login=None):
@@ -316,7 +316,7 @@ def _request(self, method: str, path: str, **kwargs):
316316
files: dict[str, Any] = {}
317317
for name, whatever in data.items():
318318
# FIXME what types should be accepted?
319-
if isinstance(whatever, io.BufferedReader):
319+
if isinstance(whatever, io.IOBase):
320320
files[name] = whatever
321321
elif isinstance(whatever, tuple):
322322
# reorder tuple to match requests expectations:

Diff for: README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Only one set of tests is needed, switching from internal to external is
88
achieved through environment variables.
99

1010
![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
11-
![Tests](https://img.shields.io/badge/tests-7%20✓-success)
11+
![Tests](https://img.shields.io/badge/tests-8%20✓-success)
1212
![Coverage](https://img.shields.io/badge/coverage-100%25-success)
1313
![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
1414
![Python](https://img.shields.io/badge/python-3-informational)
@@ -131,7 +131,6 @@ please report any [issues](https://github.com/zx80/flask-tester/issues).
131131

132132
- API documentation generation
133133
- control logging level
134-
- improve actual coverage
135134

136135
## Versions
137136

Diff for: tests/test.py

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import FlaskTester as ft
55
from FlaskTester import ft_client, ft_authenticator
66
import app
7+
import http.server as htsv
8+
import threading
9+
import io
710
import logging
811

912
logging.basicConfig(level=logging.INFO)
@@ -180,3 +183,18 @@ def test_client():
180183
assert False, "must raise an error" # pragma: no cover
181184
except NotImplementedError:
182185
assert True, "error raised"
186+
187+
def test_request_client():
188+
httpd = htsv.HTTPServer(("", 8888), htsv.SimpleHTTPRequestHandler)
189+
thread = threading.Thread(target = lambda: httpd.serve_forever())
190+
thread.start()
191+
try:
192+
client = ft.RequestClient(ft.Authenticator(), "http://localhost:8888")
193+
client.get("/", status=200)
194+
hello = io.BytesIO(b"hello world")
195+
client.post("/", status=501, data={"hello": hello})
196+
hello = io.BytesIO(b"hello world")
197+
client.post("/", status=501, data={"hello": (hello, "hello.txt", "text/plain")})
198+
client.post("/", status=501, data={"hello": "world!"})
199+
finally:
200+
httpd.shutdown()

0 commit comments

Comments
 (0)