|
4 | 4 | import coverage |
5 | 5 |
|
6 | 6 |
|
7 | | -from pytest_httpserver.httpserver import Server |
| 7 | +from pytest_httpserver.httpserver import HTTPServer |
8 | 8 | from werkzeug.wrappers import Response |
9 | 9 |
|
10 | 10 | JSON_STRING = '{"foo": "bar"}' |
11 | 11 |
|
12 | 12 |
|
13 | | -def test_expected_request_json(server: Server): |
14 | | - server.expect_request("/foobar").respond_with_json({"foo": "bar"}) |
15 | | - assert requests.get(server.url_for("/foobar")).json() == {'foo': 'bar'} |
| 13 | +def test_expected_request_json(httpserver: HTTPServer): |
| 14 | + httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"}) |
| 15 | + assert requests.get(httpserver.url_for("/foobar")).json() == {'foo': 'bar'} |
16 | 16 |
|
17 | 17 |
|
18 | | -def test_expected_request_data(server: Server): |
19 | | - server.expect_request("/foobar").respond_with_data(JSON_STRING) |
20 | | - assert requests.get(server.url_for("/foobar")).json() == {'foo': 'bar'} |
| 18 | +def test_expected_request_data(httpserver: HTTPServer): |
| 19 | + httpserver.expect_request("/foobar").respond_with_data(JSON_STRING) |
| 20 | + assert requests.get(httpserver.url_for("/foobar")).json() == {'foo': 'bar'} |
21 | 21 |
|
22 | 22 |
|
23 | | -def test_expected_request_handler(server: Server): |
24 | | - server.expect_request("/foobar").respond_with_handler(lambda request: JSON_STRING) |
25 | | - assert requests.get(server.url_for("/foobar")).json() == {'foo': 'bar'} |
| 23 | +def test_expected_request_handler(httpserver: HTTPServer): |
| 24 | + httpserver.expect_request("/foobar").respond_with_handler(lambda request: JSON_STRING) |
| 25 | + assert requests.get(httpserver.url_for("/foobar")).json() == {'foo': 'bar'} |
26 | 26 |
|
27 | 27 |
|
28 | | -def test_expected_request_response(server: Server): |
29 | | - server.expect_request("/foobar").respond_with_response(Response(JSON_STRING)) |
30 | | - assert requests.get(server.url_for("/foobar")).json() == {'foo': 'bar'} |
| 28 | +def test_expected_request_response(httpserver: HTTPServer): |
| 29 | + httpserver.expect_request("/foobar").respond_with_response(Response(JSON_STRING)) |
| 30 | + assert requests.get(httpserver.url_for("/foobar")).json() == {'foo': 'bar'} |
31 | 31 |
|
32 | 32 |
|
33 | | -def test_expected_request_response_as_string(server: Server): |
34 | | - server.expect_request("/foobar").respond_with_response(JSON_STRING) |
35 | | - assert requests.get(server.url_for("/foobar")).json() == {'foo': 'bar'} |
| 33 | +def test_expected_request_response_as_string(httpserver: HTTPServer): |
| 34 | + httpserver.expect_request("/foobar").respond_with_response(JSON_STRING) |
| 35 | + assert requests.get(httpserver.url_for("/foobar")).json() == {'foo': 'bar'} |
36 | 36 |
|
37 | 37 |
|
38 | | -def test_request_post(server: Server): |
39 | | - server.expect_request("/foobar", data='{"request": "example"}', method="POST").respond_with_data("example_response") |
40 | | - response = requests.post(server.url_for("/foobar"), json={"request": "example"}) |
41 | | - print(server.log[0]) |
42 | | - server.check_assertions() |
| 38 | +def test_request_post(httpserver: HTTPServer): |
| 39 | + httpserver.expect_request("/foobar", data='{"request": "example"}', method="POST").respond_with_data("example_response") |
| 40 | + response = requests.post(httpserver.url_for("/foobar"), json={"request": "example"}) |
| 41 | + print(httpserver.log[0]) |
| 42 | + httpserver.check_assertions() |
43 | 43 | assert response.text == "example_response" |
44 | 44 | assert response.status_code == 200 |
45 | 45 |
|
46 | 46 |
|
47 | | -def test_unexpected_request(server: Server): |
48 | | - server.expect_request("/foobar").respond_with_json({"foo": "bar"}) |
49 | | - requests.get(server.url_for("/nonexists")) |
| 47 | +def test_unexpected_request(httpserver: HTTPServer): |
| 48 | + httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"}) |
| 49 | + requests.get(httpserver.url_for("/nonexists")) |
50 | 50 | with pytest.raises(AssertionError): |
51 | | - server.check_assertions() |
| 51 | + httpserver.check_assertions() |
0 commit comments