|
5 | 5 | import unittest
|
6 | 6 |
|
7 | 7 | from influxdb_client import InfluxDBClient, Point
|
8 |
| -from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS, WriteOptions, WriteType |
| 8 | +from influxdb_client.client.write_api import WriteOptions, WriteType |
| 9 | + |
| 10 | +from tests.base_test import BaseTest |
9 | 11 |
|
10 | 12 |
|
11 | 13 | class InfluxDBClientTest(unittest.TestCase):
|
@@ -167,6 +169,49 @@ def test_write_context_manager(self):
|
167 | 169 | self.assertIsNone(api_client._pool)
|
168 | 170 | self.assertIsNone(self.client.api_client)
|
169 | 171 |
|
| 172 | + |
| 173 | +class InfluxDBClientTestIT(BaseTest): |
| 174 | + httpRequest = [] |
| 175 | + |
| 176 | + def tearDown(self) -> None: |
| 177 | + super(InfluxDBClientTestIT, self).tearDown() |
| 178 | + if hasattr(self, 'httpd'): |
| 179 | + self.httpd.shutdown() |
| 180 | + if hasattr(self, 'httpd_thread'): |
| 181 | + self.httpd_thread.join() |
| 182 | + InfluxDBClientTestIT.httpRequest = [] |
| 183 | + |
| 184 | + def test_proxy(self): |
| 185 | + self._start_proxy_server() |
| 186 | + |
| 187 | + self.client.close() |
| 188 | + self.client = InfluxDBClient(url=self.host, |
| 189 | + token=self.auth_token, |
| 190 | + proxy=f"http://localhost:{self.httpd.server_address[1]}", |
| 191 | + proxy_headers={'ProxyHeader': 'Val'}) |
| 192 | + ready = self.client.ready() |
| 193 | + self.assertEqual(ready.status, "ready") |
| 194 | + self.assertEqual(1, len(InfluxDBClientTestIT.httpRequest)) |
| 195 | + self.assertEqual('Val', InfluxDBClientTestIT.httpRequest[0].headers.get('ProxyHeader')) |
| 196 | + |
| 197 | + def _start_proxy_server(self): |
| 198 | + import http.server |
| 199 | + import urllib.request |
| 200 | + |
| 201 | + class ProxyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): |
| 202 | + |
| 203 | + def do_GET(self): |
| 204 | + InfluxDBClientTestIT.httpRequest.append(self) |
| 205 | + self.send_response(200) |
| 206 | + self.send_header('Content-type', 'application/json') |
| 207 | + self.end_headers() |
| 208 | + self.copyfile(urllib.request.urlopen(self.path), self.wfile) |
| 209 | + |
| 210 | + self.httpd = http.server.HTTPServer(('localhost', 0), ProxyHTTPRequestHandler) |
| 211 | + self.httpd_thread = threading.Thread(target=self.httpd.serve_forever) |
| 212 | + self.httpd_thread.start() |
| 213 | + |
| 214 | + |
170 | 215 | class ServerWithSelfSingedSSL(http.server.SimpleHTTPRequestHandler):
|
171 | 216 | def _set_headers(self):
|
172 | 217 | self.send_response(200)
|
|
0 commit comments