Skip to content

Commit 1350d05

Browse files
committed
update some more test cases
1 parent 7fae65f commit 1350d05

File tree

3 files changed

+26
-75
lines changed

3 files changed

+26
-75
lines changed

tests/influxdb/client_test.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,9 @@ def test_write_points(self):
170170
cli.write_points(
171171
self.dummy_points,
172172
)
173-
self.assertDictEqual(
174-
{
175-
"database": "db",
176-
"points": self.dummy_points,
177-
},
178-
json.loads(m.last_request.body)
173+
self.assertEqual(
174+
"cpu_load_short,host=server01,region=us-west value=0.64 1257894000000000000\n",
175+
m.last_request.body.decode('utf-8'),
179176
)
180177

181178
def test_write_points_toplevel_attributes(self):
@@ -193,14 +190,9 @@ def test_write_points_toplevel_attributes(self):
193190
tags={"tag": "hello"},
194191
retention_policy="somepolicy"
195192
)
196-
self.assertDictEqual(
197-
{
198-
"database": "testdb",
199-
"tags": {"tag": "hello"},
200-
"points": self.dummy_points,
201-
"retentionPolicy": "somepolicy"
202-
},
203-
json.loads(m.last_request.body)
193+
self.assertEqual(
194+
"cpu_load_short,host=server01,region=us-west,tag=hello value=0.64 1257894000000000000\n",
195+
m.last_request.body.decode('utf-8'),
204196
)
205197

206198
def test_write_points_batch(self):

tests/influxdb/client_test_with_server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,10 @@ class CommonTests(ManyTestCasesWithServerMixin,
504504
influxdb_template_conf = os.path.join(THIS_DIR, 'influxdb.conf.template')
505505

506506
def test_write(self):
507-
new_dummy_point = dummy_point[0].copy()
508-
new_dummy_point['database'] = 'db'
509-
self.assertIs(True, self.cli.write(new_dummy_point))
507+
self.assertIs(True, self.cli.write(
508+
{'points': dummy_point},
509+
params={'db': 'db'},
510+
))
510511

511512
@unittest.skip("fail against real server instance, "
512513
"don't know if it should succeed actually..")

tests/influxdb/dataframe_client_test.py

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,10 @@ def test_write_points_from_dataframe(self):
3131
index=[now, now + timedelta(hours=1)],
3232
columns=["column_one", "column_two",
3333
"column_three"])
34-
expected = {
35-
'database': 'db',
36-
'points': [
37-
{'time': '1970-01-01T00:00:00+00:00',
38-
'fields': {
39-
'column_two': 1,
40-
'column_three': 1.0,
41-
'column_one': '1'},
42-
'tags': {},
43-
'measurement': 'foo'},
44-
{'time': '1970-01-01T01:00:00+00:00',
45-
'fields': {
46-
'column_two': 2,
47-
'column_three': 2.0,
48-
'column_one': '2'},
49-
'tags': {},
50-
'measurement': 'foo'}]
51-
}
34+
expected = (
35+
b"foo column_one=\"1\",column_three=1.0,column_two=1 0\n"
36+
b"foo column_one=\"2\",column_three=2.0,column_two=2 3600000000000\n"
37+
)
5238

5339
with requests_mock.Mocker() as m:
5440
m.register_uri(requests_mock.POST,
@@ -58,10 +44,10 @@ def test_write_points_from_dataframe(self):
5844
cli = DataFrameClient(database='db')
5945

6046
cli.write_points(dataframe, 'foo')
61-
self.assertEqual(json.loads(m.last_request.body), expected)
47+
self.assertEqual(m.last_request.body, expected)
6248

6349
cli.write_points(dataframe, 'foo', tags=None)
64-
self.assertEqual(json.loads(m.last_request.body), expected)
50+
self.assertEqual(m.last_request.body, expected)
6551

6652
def test_write_points_from_dataframe_in_batches(self):
6753
now = pd.Timestamp('1970-01-01 00:00+00:00')
@@ -83,24 +69,10 @@ def test_write_points_from_dataframe_with_numeric_column_names(self):
8369
dataframe = pd.DataFrame(data=[["1", 1, 1.0], ["2", 2, 2.0]],
8470
index=[now, now + timedelta(hours=1)])
8571

86-
expected = {
87-
'database': 'db',
88-
'points': [
89-
{'fields': {
90-
'0': '1',
91-
'1': 1,
92-
'2': 1.0},
93-
'tags': {'hello': 'there'},
94-
'time': '1970-01-01T00:00:00+00:00',
95-
'measurement': 'foo'},
96-
{'fields': {
97-
'0': '2',
98-
'1': 2,
99-
'2': 2.0},
100-
'tags': {'hello': 'there'},
101-
'time': '1970-01-01T01:00:00+00:00',
102-
'measurement': 'foo'}],
103-
}
72+
expected = (
73+
b"foo,hello=there 0=\"1\",1=1,2=1.0 0\n"
74+
b"foo,hello=there 0=\"2\",1=2,2=2.0 3600000000000\n"
75+
)
10476

10577
with requests_mock.Mocker() as m:
10678
m.register_uri(requests_mock.POST,
@@ -110,32 +82,18 @@ def test_write_points_from_dataframe_with_numeric_column_names(self):
11082
cli = DataFrameClient(database='db')
11183
cli.write_points(dataframe, "foo", {"hello": "there"})
11284

113-
self.assertEqual(json.loads(m.last_request.body), expected)
85+
self.assertEqual(m.last_request.body, expected)
11486

11587
def test_write_points_from_dataframe_with_period_index(self):
11688
dataframe = pd.DataFrame(data=[["1", 1, 1.0], ["2", 2, 2.0]],
11789
index=[pd.Period('1970-01-01'),
11890
pd.Period('1970-01-02')],
11991
columns=["column_one", "column_two",
12092
"column_three"])
121-
expected = {
122-
'points': [
123-
{'measurement': 'foo',
124-
'tags': {},
125-
'fields': {
126-
'column_one': '1',
127-
'column_two': 1,
128-
'column_three': 1.0},
129-
'time': '1970-01-01T00:00:00+00:00'},
130-
{'measurement': 'foo',
131-
'tags': {},
132-
'fields': {
133-
'column_one': '2',
134-
'column_two': 2,
135-
'column_three': 2.0},
136-
'time': '1970-01-02T00:00:00+00:00'}],
137-
'database': 'db',
138-
}
93+
expected = (
94+
b"foo column_one=\"1\",column_three=1.0,column_two=1 0\n"
95+
b"foo column_one=\"2\",column_three=2.0,column_two=2 86400000000000\n"
96+
)
13997

14098
with requests_mock.Mocker() as m:
14199
m.register_uri(requests_mock.POST,
@@ -145,7 +103,7 @@ def test_write_points_from_dataframe_with_period_index(self):
145103
cli = DataFrameClient(database='db')
146104
cli.write_points(dataframe, "foo")
147105

148-
self.assertEqual(json.loads(m.last_request.body), expected)
106+
self.assertEqual(m.last_request.body, expected)
149107

150108
def test_write_points_from_dataframe_with_time_precision(self):
151109
now = pd.Timestamp('1970-01-01 00:00+00:00')

0 commit comments

Comments
 (0)