@@ -89,49 +89,51 @@ def setUp(self):
89
89
}
90
90
]
91
91
92
+ self .dsn_string = 'influxdb://uSr:pWd@host:1886/db'
93
+
92
94
def test_scheme (self ):
93
95
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'database' )
94
- assert cli ._baseurl == 'http://host:8086'
96
+ self . assertEqual ( cli ._baseurl , 'http://host:8086' )
95
97
96
98
cli = InfluxDBClient (
97
99
'host' , 8086 , 'username' , 'password' , 'database' , ssl = True
98
100
)
99
- assert cli ._baseurl == 'https://host:8086'
101
+ self . assertEqual ( cli ._baseurl , 'https://host:8086' )
100
102
101
103
def test_dsn (self ):
102
- cli = InfluxDBClient .from_DSN ('influxdb://usr:pwd@host:1886/db' )
103
- assert cli . _baseurl == 'http://host:1886'
104
- assert cli ._username == 'usr'
105
- assert cli ._password == 'pwd'
106
- assert cli . _database == 'db'
107
- assert cli .use_udp is False
104
+ cli = InfluxDBClient .from_DSN (self . dsn_string )
105
+ self . assertEqual ( 'http://host:1886' , cli . _baseurl )
106
+ self . assertEqual ( 'uSr' , cli ._username )
107
+ self . assertEqual ( 'pWd' , cli ._password )
108
+ self . assertEqual ( 'db' , cli . _database )
109
+ self . assertFalse ( cli .use_udp )
108
110
109
- cli = InfluxDBClient .from_DSN ('udp+influxdb://usr:pwd@host:1886/db' )
110
- assert cli .use_udp is True
111
+ cli = InfluxDBClient .from_DSN ('udp+' + self . dsn_string )
112
+ self . assertTrue ( cli .use_udp )
111
113
112
- cli = InfluxDBClient .from_DSN ('https+influxdb://usr:pwd@host:1886/db' )
113
- assert cli . _baseurl == 'https://host:1886'
114
+ cli = InfluxDBClient .from_DSN ('https+' + self . dsn_string )
115
+ self . assertEqual ( 'https://host:1886' , cli . _baseurl )
114
116
115
- cli = InfluxDBClient .from_DSN ('https+influxdb://usr:pwd@host:1886/db' ,
117
+ cli = InfluxDBClient .from_DSN ('https+' + self . dsn_string ,
116
118
** {'ssl' : False })
117
- assert cli . _baseurl == 'http://host:1886'
119
+ self . assertEqual ( 'http://host:1886' , cli . _baseurl )
118
120
119
121
def test_switch_database (self ):
120
122
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'database' )
121
123
cli .switch_database ('another_database' )
122
- assert cli ._database == 'another_database'
124
+ self . assertEqual ( cli ._database , 'another_database' )
123
125
124
126
@raises (FutureWarning )
125
127
def test_switch_db_deprecated (self ):
126
128
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'database' )
127
129
cli .switch_db ('another_database' )
128
- assert cli ._database == 'another_database'
130
+ self . assertEqual ( cli ._database , 'another_database' )
129
131
130
132
def test_switch_user (self ):
131
133
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'database' )
132
134
cli .switch_user ('another_username' , 'another_password' )
133
- assert cli ._username == 'another_username'
134
- assert cli ._password == 'another_password'
135
+ self . assertEqual ( cli ._username , 'another_username' )
136
+ self . assertEqual ( cli ._password , 'another_password' )
135
137
136
138
def test_write (self ):
137
139
with requests_mock .Mocker () as m :
@@ -250,8 +252,8 @@ def test_write_points_udp(self):
250
252
251
253
received_data , addr = s .recvfrom (1024 )
252
254
253
- assert self .dummy_points == \
254
- json .loads (received_data .decode (), strict = True )
255
+ self .assertEqual ( self . dummy_points ,
256
+ json .loads (received_data .decode (), strict = True ) )
255
257
256
258
def test_write_bad_precision_udp (self ):
257
259
cli = InfluxDBClient (
@@ -277,7 +279,7 @@ def test_write_points_fails(self):
277
279
def test_write_points_with_precision (self ):
278
280
with _mocked_session ('post' , 200 , self .dummy_points ):
279
281
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
280
- assert cli .write_points (self .dummy_points ) is True
282
+ self . assertTrue ( cli .write_points (self .dummy_points ))
281
283
282
284
def test_write_points_bad_precision (self ):
283
285
cli = InfluxDBClient ()
@@ -299,13 +301,14 @@ def test_write_points_with_precision_fails(self):
299
301
def test_delete_points (self ):
300
302
with _mocked_session ('delete' , 204 ) as mocked :
301
303
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
302
- assert cli .delete_points ("foo" ) is True
304
+ self . assertTrue ( cli .delete_points ("foo" ))
303
305
304
- assert len (mocked .call_args_list ) == 1
306
+ self . assertEqual ( len (mocked .call_args_list ), 1 )
305
307
args , kwds = mocked .call_args_list [0 ]
306
308
307
- assert kwds ['params' ] == {'u' : 'username' , 'p' : 'password' }
308
- assert kwds ['url' ] == 'http://host:8086/db/db/series/foo'
309
+ self .assertEqual (kwds ['params' ],
310
+ {'u' : 'username' , 'p' : 'password' })
311
+ self .assertEqual (kwds ['url' ], 'http://host:8086/db/db/series/foo' )
309
312
310
313
@raises (Exception )
311
314
def test_delete_points_with_wrong_name (self ):
@@ -342,7 +345,7 @@ def test_query(self):
342
345
with _mocked_session ('get' , 200 , data ):
343
346
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
344
347
result = cli .query ('select column_one from foo;' )
345
- assert len (result [0 ]['points' ]) == 4
348
+ self . assertEqual ( len (result [0 ]['points' ]), 4 )
346
349
347
350
def test_query_chunked (self ):
348
351
cli = InfluxDBClient (database = 'db' )
@@ -422,7 +425,7 @@ def test_query_bad_precision(self):
422
425
def test_create_database (self ):
423
426
with _mocked_session ('post' , 201 , {"name" : "new_db" }):
424
427
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
425
- assert cli .create_database ('new_db' ) is True
428
+ self . assertTrue ( cli .create_database ('new_db' ))
426
429
427
430
@raises (Exception )
428
431
def test_create_database_fails (self ):
@@ -433,7 +436,7 @@ def test_create_database_fails(self):
433
436
def test_delete_database (self ):
434
437
with _mocked_session ('delete' , 204 ):
435
438
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
436
- assert cli .delete_database ('old_db' ) is True
439
+ self . assertTrue ( cli .delete_database ('old_db' ))
437
440
438
441
@raises (Exception )
439
442
def test_delete_database_fails (self ):
@@ -447,8 +450,8 @@ def test_get_list_database(self):
447
450
]
448
451
with _mocked_session ('get' , 200 , data ):
449
452
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' )
450
- assert len (cli .get_list_database ()) == 1
451
- assert cli .get_list_database ()[0 ]['name' ] == 'a_db'
453
+ self . assertEqual ( len (cli .get_list_database ()), 1 )
454
+ self . assertEqual ( cli .get_list_database ()[0 ]['name' ], 'a_db' )
452
455
453
456
@raises (Exception )
454
457
def test_get_list_database_fails (self ):
@@ -463,8 +466,8 @@ def test_get_database_list_deprecated(self):
463
466
]
464
467
with _mocked_session ('get' , 200 , data ):
465
468
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' )
466
- assert len (cli .get_database_list ()) == 1
467
- assert cli .get_database_list ()[0 ]['name' ] == 'a_db'
469
+ self . assertEqual ( len (cli .get_database_list ()), 1 )
470
+ self . assertEqual ( cli .get_database_list ()[0 ]['name' ], 'a_db' )
468
471
469
472
def test_delete_series (self ):
470
473
with _mocked_session ('delete' , 204 ):
0 commit comments