|
4 | 4 | import string |
5 | 5 | import time |
6 | 6 | import unittest |
| 7 | +from unittest.mock import patch |
7 | 8 |
|
8 | 9 | import pyarrow |
9 | 10 | import pytest |
@@ -276,15 +277,21 @@ async def test_verify_query_async(self): |
276 | 277 | assert lp_to_py_object(item) in result_list, f"original lp data \"{item}\" should be in result list" |
277 | 278 |
|
278 | 279 | def test_from_env(self): |
279 | | - c = from_env() |
280 | | - with c: |
| 280 | + with from_env() as client: |
281 | 281 | id_test = time.time_ns() |
282 | | - c.write(f"integration_test_python,type=used value=123.0,id_test={id_test}i") |
| 282 | + client.write(f"integration_test_python,type=used value=123.0,id_test={id_test}i") |
283 | 283 |
|
284 | 284 | sql = 'SELECT * FROM integration_test_python where type=$type and id_test=$id_test' |
285 | | - data = c.query(sql, mode="pandas", query_parameters={'type': 'used', 'id_test': id_test}) |
| 285 | + data = client.query(sql, mode="pandas", query_parameters={'type': 'used', 'id_test': id_test}) |
286 | 286 |
|
287 | 287 | self.assertIsNotNone(data) |
288 | 288 | self.assertEqual(1, len(data)) |
289 | 289 | self.assertEqual(id_test, data['id_test'][0]) |
290 | 290 | self.assertEqual(123.0, data['value'][0]) |
| 291 | + |
| 292 | + @patch.dict('os.environ', {'INFLUX_AUTH_SCHEME': 'invalid_schema'}) |
| 293 | + def test_from_env_invalid_auth_schema(self): |
| 294 | + with from_env() as client: |
| 295 | + with self.assertRaises(InfluxDBError) as err: |
| 296 | + client.write("integration_test_python,type=used value=123.0") |
| 297 | + self.assertEqual('unauthorized access', err.exception.message) |
0 commit comments