|
| 1 | +import contextlib |
| 2 | + |
1 | 3 | import pytest
|
| 4 | +asyncio = pytest.importorskip("asyncio") |
2 | 5 | aiohttp = pytest.importorskip("aiohttp")
|
3 | 6 |
|
4 |
| -import asyncio # noqa: E402 |
5 |
| -import contextlib # noqa: E402 |
6 |
| - |
7 |
| -import pytest # noqa: E402 |
8 | 7 | import vcr # noqa: E402
|
9 |
| - |
10 | 8 | from .aiohttp_utils import aiohttp_request # noqa: E402
|
11 | 9 |
|
12 |
| -try: |
13 |
| - from .async_def import test_http # noqa: F401 |
14 |
| -except SyntaxError: |
15 |
| - pass |
16 |
| - |
17 | 10 |
|
18 | 11 | def run_in_loop(fn):
|
19 | 12 | with contextlib.closing(asyncio.new_event_loop()) as loop:
|
@@ -78,11 +71,13 @@ def test_text(tmpdir, scheme):
|
78 | 71 |
|
79 | 72 | def test_json(tmpdir, scheme):
|
80 | 73 | url = scheme + '://httpbin.org/get'
|
| 74 | + headers = {'Content-Type': 'application/json'} |
| 75 | + |
81 | 76 | with vcr.use_cassette(str(tmpdir.join('json.yaml'))):
|
82 |
| - _, response_json = get(url, output='json') |
| 77 | + _, response_json = get(url, output='json', headers=headers) |
83 | 78 |
|
84 | 79 | with vcr.use_cassette(str(tmpdir.join('json.yaml'))) as cassette:
|
85 |
| - _, cassette_response_json = get(url, output='json') |
| 80 | + _, cassette_response_json = get(url, output='json', headers=headers) |
86 | 81 | assert cassette_response_json == response_json
|
87 | 82 | assert cassette.play_count == 1
|
88 | 83 |
|
@@ -112,24 +107,28 @@ def test_post(tmpdir, scheme):
|
112 | 107 |
|
113 | 108 | def test_params(tmpdir, scheme):
|
114 | 109 | url = scheme + '://httpbin.org/get'
|
| 110 | + headers = {'Content-Type': 'application/json'} |
115 | 111 | params = {'a': 1, 'b': False, 'c': 'c'}
|
| 112 | + |
116 | 113 | with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
117 |
| - _, response_json = get(url, output='json', params=params) |
| 114 | + _, response_json = get(url, output='json', params=params, headers=headers) |
118 | 115 |
|
119 | 116 | with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
120 |
| - _, cassette_response_json = get(url, output='json', params=params) |
| 117 | + _, cassette_response_json = get(url, output='json', params=params, headers=headers) |
121 | 118 | assert cassette_response_json == response_json
|
122 | 119 | assert cassette.play_count == 1
|
123 | 120 |
|
124 | 121 |
|
125 | 122 | def test_params_same_url_distinct_params(tmpdir, scheme):
|
126 | 123 | url = scheme + '://httpbin.org/get'
|
| 124 | + headers = {'Content-Type': 'application/json'} |
127 | 125 | params = {'a': 1, 'b': False, 'c': 'c'}
|
| 126 | + |
128 | 127 | with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
129 |
| - _, response_json = get(url, output='json', params=params) |
| 128 | + _, response_json = get(url, output='json', params=params, headers=headers) |
130 | 129 |
|
131 | 130 | with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
132 |
| - _, cassette_response_json = get(url, output='json', params=params) |
| 131 | + _, cassette_response_json = get(url, output='json', params=params, headers=headers) |
133 | 132 | assert cassette_response_json == response_json
|
134 | 133 | assert cassette.play_count == 1
|
135 | 134 |
|
|
0 commit comments