2
2
"""
3
3
unit tests
4
4
"""
5
+ import json
5
6
import requests
6
7
from nose .tools import raises
7
8
from mock import patch
@@ -24,7 +25,14 @@ def _mocked_session( method="GET", status_code=200, content=""):
24
25
def check_method (* args , ** kwargs ):
25
26
# Check method
26
27
assert method == kwargs .get ('method' , 'GET' )
27
- return _build_response_object (status_code = status_code , content = content )
28
+ c = content
29
+ if method == 'POST' :
30
+ if not isinstance (c , dict ):
31
+ c = json .dumps (c )
32
+ assert c == kwargs .get ('data' )
33
+ c = ''
34
+
35
+ return _build_response_object (status_code = status_code , content = c )
28
36
29
37
mocked = patch .object (
30
38
session ,
@@ -67,7 +75,7 @@ def test_write_points(self):
67
75
}
68
76
]
69
77
70
- with _mocked_session ('post' , 200 ) as mocked :
78
+ with _mocked_session ('post' , 200 , data ) as mocked :
71
79
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
72
80
assert cli .write_points (data ) is True
73
81
@@ -89,7 +97,7 @@ def test_write_points_with_precision(self):
89
97
}
90
98
]
91
99
92
- with _mocked_session ('post' , 200 ) as mocked :
100
+ with _mocked_session ('post' , 200 , data ) as mocked :
93
101
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
94
102
assert cli .write_points_with_precision (data ) is True
95
103
@@ -148,7 +156,7 @@ def test_query_fail(self):
148
156
cli .query ('select column_one from foo;' )
149
157
150
158
def test_create_database (self ):
151
- with _mocked_session ('post' , 201 ) as mocked :
159
+ with _mocked_session ('post' , 201 , { "name" : "new_db" } ) as mocked :
152
160
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
153
161
assert cli .create_database ('new_db' ) is True
154
162
0 commit comments