@@ -31,24 +31,10 @@ def test_write_points_from_dataframe(self):
31
31
index = [now , now + timedelta (hours = 1 )],
32
32
columns = ["column_one" , "column_two" ,
33
33
"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
+ )
52
38
53
39
with requests_mock .Mocker () as m :
54
40
m .register_uri (requests_mock .POST ,
@@ -58,10 +44,10 @@ def test_write_points_from_dataframe(self):
58
44
cli = DataFrameClient (database = 'db' )
59
45
60
46
cli .write_points (dataframe , 'foo' )
61
- self .assertEqual (json . loads ( m .last_request .body ) , expected )
47
+ self .assertEqual (m .last_request .body , expected )
62
48
63
49
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 )
65
51
66
52
def test_write_points_from_dataframe_in_batches (self ):
67
53
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):
83
69
dataframe = pd .DataFrame (data = [["1" , 1 , 1.0 ], ["2" , 2 , 2.0 ]],
84
70
index = [now , now + timedelta (hours = 1 )])
85
71
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
+ )
104
76
105
77
with requests_mock .Mocker () as m :
106
78
m .register_uri (requests_mock .POST ,
@@ -110,32 +82,18 @@ def test_write_points_from_dataframe_with_numeric_column_names(self):
110
82
cli = DataFrameClient (database = 'db' )
111
83
cli .write_points (dataframe , "foo" , {"hello" : "there" })
112
84
113
- self .assertEqual (json . loads ( m .last_request .body ) , expected )
85
+ self .assertEqual (m .last_request .body , expected )
114
86
115
87
def test_write_points_from_dataframe_with_period_index (self ):
116
88
dataframe = pd .DataFrame (data = [["1" , 1 , 1.0 ], ["2" , 2 , 2.0 ]],
117
89
index = [pd .Period ('1970-01-01' ),
118
90
pd .Period ('1970-01-02' )],
119
91
columns = ["column_one" , "column_two" ,
120
92
"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
+ )
139
97
140
98
with requests_mock .Mocker () as m :
141
99
m .register_uri (requests_mock .POST ,
@@ -145,7 +103,7 @@ def test_write_points_from_dataframe_with_period_index(self):
145
103
cli = DataFrameClient (database = 'db' )
146
104
cli .write_points (dataframe , "foo" )
147
105
148
- self .assertEqual (json . loads ( m .last_request .body ) , expected )
106
+ self .assertEqual (m .last_request .body , expected )
149
107
150
108
def test_write_points_from_dataframe_with_time_precision (self ):
151
109
now = pd .Timestamp ('1970-01-01 00:00+00:00' )
0 commit comments