Skip to content

Commit b398915

Browse files
alespourNguyenHoangSon96
authored andcommitted
test: adjust partial writes test to v3.10 behaviour
1 parent 588e4da commit b398915

1 file changed

Lines changed: 52 additions & 38 deletions

File tree

tests/test_influxdb_client_3_integration.py

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import os
34
import random
@@ -13,6 +14,7 @@
1314
from influxdb_client_3 import InfluxDBClient3, write_client_options, WriteOptions, \
1415
WriteType, InfluxDB3ClientQueryError
1516
from influxdb_client_3.exceptions import InfluxDBError, InfluxDBPartialWriteError
17+
from influxdb_client_3.write_client.rest import ApiException
1618
from tests.util import asyncio_run, lp_to_py_object
1719

1820

@@ -133,52 +135,64 @@ def test_v3_error(self):
133135
for accept_partial in [True, False]:
134136
with self.subTest(accept_partial=accept_partial):
135137
with InfluxDBClient3(
136-
host=self.host,
137-
database=self.database,
138-
token=self.token,
139-
write_client_options=write_client_options(write_options=WriteOptions(
140-
write_type=WriteType.synchronous,
141-
use_v2_api=False,
142-
accept_partial=accept_partial
143-
))
138+
host=self.host,
139+
database=self.database,
140+
token=self.token,
141+
write_client_options=write_client_options(write_options=WriteOptions(
142+
write_type=WriteType.synchronous,
143+
use_v2_api=False,
144+
accept_partial=accept_partial
145+
))
144146
) as client:
145-
with self.assertRaises(InfluxDBPartialWriteError) as err:
146-
client.write(lp)
147-
148-
msg = err.exception.message
149-
self.assertTrue(
150-
"partial write of line protocol occurred" in msg or "parsing failed for write_lp endpoint" in msg
151-
)
152-
self.assertIn((
153-
"invalid column type for column 'temp', expected iox::column_type::field::float, "
154-
"got iox::column_type::field::string"
155-
), msg)
156-
self.assertIn("line 2", msg)
157-
self.assertIn("home,room=Sunroom", msg)
147+
if accept_partial:
148+
with self.assertRaises(InfluxDBPartialWriteError) as err:
149+
client.write(lp)
150+
151+
self.assertEqual(1, len(err.exception.line_errors))
152+
line_error = err.exception.line_errors[0]
153+
self.assertEqual(2, line_error.line_number)
154+
self.assertIn("invalid column type for column 'temp'", line_error.error_message)
155+
self.assertIn("home,room=Sunroom", line_error.original_line)
156+
else:
157+
with self.assertRaises(ApiException) as err:
158+
client.write(lp)
159+
160+
self.assertEqual(400, err.exception.status)
161+
self.assertEqual("line protocol parsing error", err.exception.message)
162+
body = json.loads(err.exception.body)
163+
self.assertEqual("line protocol parsing error", body["error"])
164+
self.assertEqual(2, body["data"]["line_number"])
165+
self.assertIn(
166+
"invalid column type for column 'temp'",
167+
body["data"]["error_message"],
168+
)
158169

159170
def test_v2_error(self):
160171
lp = "\n".join([
161172
"home,room=Sunroom temp=96 1735545600",
162173
"home,room=Sunroom temp=\"hi\" 1735549200",
163174
])
164175

165-
with InfluxDBClient3(
166-
host=self.host,
167-
database=self.database,
168-
token=self.token,
169-
write_client_options=write_client_options(write_options=WriteOptions(
170-
write_type=WriteType.synchronous,
171-
use_v2_api=True,
172-
accept_partial=False
173-
))
174-
) as client:
175-
with self.assertRaises(InfluxDBError) as err:
176-
client.write(lp)
177-
178-
self.assertNotIsInstance(err.exception, InfluxDBPartialWriteError)
179-
self.assertIsNotNone(err.exception.response)
180-
self.assertEqual(400, err.exception.response.status)
181-
self.assertTrue(err.exception.message)
176+
for accept_partial in [True, False]:
177+
with self.subTest(accept_partial=accept_partial):
178+
with InfluxDBClient3(
179+
host=self.host,
180+
database=self.database,
181+
token=self.token,
182+
write_client_options=write_client_options(write_options=WriteOptions(
183+
write_type=WriteType.synchronous,
184+
use_v2_api=True,
185+
accept_partial=accept_partial
186+
))
187+
) as client:
188+
with self.assertRaises(ApiException) as err:
189+
client.write(lp)
190+
191+
self.assertEqual(400, err.exception.status)
192+
self.assertNotIsInstance(err.exception, InfluxDBPartialWriteError)
193+
body = json.loads(err.exception.body)
194+
self.assertEqual("invalid", body["code"])
195+
self.assertIn("write buffer error", body["message"])
182196

183197
def test_auth_error_token(self):
184198
self.client = InfluxDBClient3(host=self.host, database=self.database, token='fake token')

0 commit comments

Comments
 (0)