On 304s we still make a request using our connection pool, yet we do not call the parent adapter, which releases the connection back to the pool. This test ensures that when the parent `get` method is not called we consume the response (which should be empty according to the HTT
| 143 | |
| 144 | |
| 145 | class TestReleaseConnection: |
| 146 | """ |
| 147 | On 304s we still make a request using our connection pool, yet |
| 148 | we do not call the parent adapter, which releases the connection |
| 149 | back to the pool. This test ensures that when the parent `get` |
| 150 | method is not called we consume the response (which should be |
| 151 | empty according to the HTTP spec) and release the connection. |
| 152 | """ |
| 153 | |
| 154 | def test_not_modified_releases_connection(self, server, url): |
| 155 | sess = CacheControl(requests.Session()) |
| 156 | etag_url = urljoin(url, "/etag") |
| 157 | sess.get(etag_url) |
| 158 | |
| 159 | resp = Mock(status=304, headers={}) |
| 160 | |
| 161 | # These are various ways the the urllib3 response can created |
| 162 | # in requests.adapters. Which one is actually used depends |
| 163 | # on which version if `requests` is in use, as well as perhaps |
| 164 | # other parameters. |
| 165 | response_mods = [ |
| 166 | "requests.adapters.HTTPResponse.from_httplib", |
| 167 | "urllib3.HTTPConnectionPool.urlopen", |
| 168 | ] |
| 169 | |
| 170 | with ExitStack() as stack: |
| 171 | for mod in response_mods: |
| 172 | with suppress(ImportError, AttributeError): |
| 173 | stack.enter_context(patch(mod, Mock(return_value=resp))) |
| 174 | |
| 175 | sess.get(etag_url) |
| 176 | assert resp.read.called |
| 177 | assert resp.release_conn.called |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…