Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Remove dsn.lower() from influxdb08.InfluxDBClient.from_DSN() #190

Merged
merged 3 commits into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion influxdb/influxdb08/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def from_DSN(dsn, **kwargs):
udp_port parameter (cf. examples).
:raise ValueError: if the provided DSN has any unexpected value.
"""
dsn = dsn.lower()

init_args = {}
conn_params = urlparse(dsn)
Expand Down
37 changes: 18 additions & 19 deletions tests/influxdb/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def setUp(self):
}
]

self.dsn_string = 'influxdb://uSr:pWd@host:1886/db'

def test_scheme(self):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'database')
self.assertEqual('http://host:8086', cli._baseurl)
Expand All @@ -105,20 +107,20 @@ def test_scheme(self):
self.assertEqual('https://host:8086', cli._baseurl)

def test_dsn(self):
cli = InfluxDBClient.from_DSN('influxdb://usr:pwd@host:1886/db')
cli = InfluxDBClient.from_DSN(self.dsn_string)
self.assertEqual('http://host:1886', cli._baseurl)
self.assertEqual('usr', cli._username)
self.assertEqual('pwd', cli._password)
self.assertEqual('uSr', cli._username)
self.assertEqual('pWd', cli._password)
self.assertEqual('db', cli._database)
self.assertFalse(cli.use_udp)

cli = InfluxDBClient.from_DSN('udp+influxdb://usr:pwd@host:1886/db')
cli = InfluxDBClient.from_DSN('udp+' + self.dsn_string)
self.assertTrue(cli.use_udp)

cli = InfluxDBClient.from_DSN('https+influxdb://usr:pwd@host:1886/db')
cli = InfluxDBClient.from_DSN('https+' + self.dsn_string)
self.assertEqual('https://host:1886', cli._baseurl)

cli = InfluxDBClient.from_DSN('https+influxdb://usr:pwd@host:1886/db',
cli = InfluxDBClient.from_DSN('https+' + self.dsn_string,
**{'ssl': False})
self.assertEqual('http://host:1886', cli._baseurl)

Expand Down Expand Up @@ -742,6 +744,7 @@ def setUp(self):
warnings.simplefilter('error', FutureWarning)

self.hosts = [('host1', 8086), ('host2', 8086), ('host3', 8086)]
self.dsn_string = 'influxdb://uSr:pWd@host1:8086,uSr:pWd@host2:8086/db'

def test_init(self):
cluster = InfluxDBClusterClient(hosts=self.hosts,
Expand Down Expand Up @@ -808,33 +811,29 @@ def test_recovery(self):
self.assertEqual(2, len(cluster.bad_clients))

def test_dsn(self):
cli = InfluxDBClusterClient.from_DSN(
'influxdb://usr:pwd@host1:8086,usr:pwd@host2:8086/db')
cli = InfluxDBClusterClient.from_DSN(self.dsn_string)
self.assertEqual(2, len(cli.clients))
self.assertEqual('http://host1:8086', cli.clients[0]._baseurl)
self.assertEqual('usr', cli.clients[0]._username)
self.assertEqual('pwd', cli.clients[0]._password)
self.assertEqual('uSr', cli.clients[0]._username)
self.assertEqual('pWd', cli.clients[0]._password)
self.assertEqual('db', cli.clients[0]._database)
self.assertFalse(cli.clients[0].use_udp)
self.assertEqual('http://host2:8086', cli.clients[1]._baseurl)
self.assertEqual('usr', cli.clients[1]._username)
self.assertEqual('pwd', cli.clients[1]._password)
self.assertEqual('uSr', cli.clients[1]._username)
self.assertEqual('pWd', cli.clients[1]._password)
self.assertEqual('db', cli.clients[1]._database)
self.assertFalse(cli.clients[1].use_udp)

cli = InfluxDBClusterClient.from_DSN(
'udp+influxdb://usr:pwd@host1:8086,usr:pwd@host2:8086/db')
cli = InfluxDBClusterClient.from_DSN('udp+' + self.dsn_string)
self.assertTrue(cli.clients[0].use_udp)
self.assertTrue(cli.clients[1].use_udp)

cli = InfluxDBClusterClient.from_DSN(
'https+influxdb://usr:pwd@host1:8086,usr:pwd@host2:8086/db')
cli = InfluxDBClusterClient.from_DSN('https+' + self.dsn_string)
self.assertEqual('https://host1:8086', cli.clients[0]._baseurl)
self.assertEqual('https://host2:8086', cli.clients[1]._baseurl)

cli = InfluxDBClusterClient.from_DSN(
'https+influxdb://usr:pwd@host1:8086,usr:pwd@host2:8086/db',
**{'ssl': False})
cli = InfluxDBClusterClient.from_DSN('https+' + self.dsn_string,
**{'ssl': False})
self.assertEqual('http://host1:8086', cli.clients[0]._baseurl)
self.assertEqual('http://host2:8086', cli.clients[1]._baseurl)

Expand Down
4 changes: 2 additions & 2 deletions tests/influxdb/dataframe_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_write_points_from_dataframe_in_batches(self):
status_code=204)

cli = DataFrameClient(database='db')
assert cli.write_points(dataframe, "foo", batch_size=1) is True
self.assertTrue(cli.write_points(dataframe, "foo", batch_size=1))

def test_write_points_from_dataframe_with_numeric_column_names(self):
now = pd.Timestamp('1970-01-01 00:00+00:00')
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_query_with_empty_result(self):
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
with _mocked_session(cli, 'GET', 200, {"results": [{}]}):
result = cli.query('select column_one from foo;')
assert result == {}
self.assertEqual(result, {})

def test_list_series(self):
response = {
Expand Down
67 changes: 35 additions & 32 deletions tests/influxdb/influxdb08/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,49 +89,51 @@ def setUp(self):
}
]

self.dsn_string = 'influxdb://uSr:pWd@host:1886/db'

def test_scheme(self):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'database')
assert cli._baseurl == 'http://host:8086'
self.assertEqual(cli._baseurl, 'http://host:8086')

cli = InfluxDBClient(
'host', 8086, 'username', 'password', 'database', ssl=True
)
assert cli._baseurl == 'https://host:8086'
self.assertEqual(cli._baseurl, 'https://host:8086')

def test_dsn(self):
cli = InfluxDBClient.from_DSN('influxdb://usr:pwd@host:1886/db')
assert cli._baseurl == 'http://host:1886'
assert cli._username == 'usr'
assert cli._password == 'pwd'
assert cli._database == 'db'
assert cli.use_udp is False
cli = InfluxDBClient.from_DSN(self.dsn_string)
self.assertEqual('http://host:1886', cli._baseurl)
self.assertEqual('uSr', cli._username)
self.assertEqual('pWd', cli._password)
self.assertEqual('db', cli._database)
self.assertFalse(cli.use_udp)

cli = InfluxDBClient.from_DSN('udp+influxdb://usr:pwd@host:1886/db')
assert cli.use_udp is True
cli = InfluxDBClient.from_DSN('udp+' + self.dsn_string)
self.assertTrue(cli.use_udp)

cli = InfluxDBClient.from_DSN('https+influxdb://usr:pwd@host:1886/db')
assert cli._baseurl == 'https://host:1886'
cli = InfluxDBClient.from_DSN('https+' + self.dsn_string)
self.assertEqual('https://host:1886', cli._baseurl)

cli = InfluxDBClient.from_DSN('https+influxdb://usr:pwd@host:1886/db',
cli = InfluxDBClient.from_DSN('https+' + self.dsn_string,
**{'ssl': False})
assert cli._baseurl == 'http://host:1886'
self.assertEqual('http://host:1886', cli._baseurl)

def test_switch_database(self):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'database')
cli.switch_database('another_database')
assert cli._database == 'another_database'
self.assertEqual(cli._database, 'another_database')

@raises(FutureWarning)
def test_switch_db_deprecated(self):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'database')
cli.switch_db('another_database')
assert cli._database == 'another_database'
self.assertEqual(cli._database, 'another_database')

def test_switch_user(self):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'database')
cli.switch_user('another_username', 'another_password')
assert cli._username == 'another_username'
assert cli._password == 'another_password'
self.assertEqual(cli._username, 'another_username')
self.assertEqual(cli._password, 'another_password')

def test_write(self):
with requests_mock.Mocker() as m:
Expand Down Expand Up @@ -250,8 +252,8 @@ def test_write_points_udp(self):

received_data, addr = s.recvfrom(1024)

assert self.dummy_points == \
json.loads(received_data.decode(), strict=True)
self.assertEqual(self.dummy_points,
json.loads(received_data.decode(), strict=True))

def test_write_bad_precision_udp(self):
cli = InfluxDBClient(
Expand All @@ -277,7 +279,7 @@ def test_write_points_fails(self):
def test_write_points_with_precision(self):
with _mocked_session('post', 200, self.dummy_points):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
assert cli.write_points(self.dummy_points) is True
self.assertTrue(cli.write_points(self.dummy_points))

def test_write_points_bad_precision(self):
cli = InfluxDBClient()
Expand All @@ -299,13 +301,14 @@ def test_write_points_with_precision_fails(self):
def test_delete_points(self):
with _mocked_session('delete', 204) as mocked:
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
assert cli.delete_points("foo") is True
self.assertTrue(cli.delete_points("foo"))

assert len(mocked.call_args_list) == 1
self.assertEqual(len(mocked.call_args_list), 1)
args, kwds = mocked.call_args_list[0]

assert kwds['params'] == {'u': 'username', 'p': 'password'}
assert kwds['url'] == 'http://host:8086/db/db/series/foo'
self.assertEqual(kwds['params'],
{'u': 'username', 'p': 'password'})
self.assertEqual(kwds['url'], 'http://host:8086/db/db/series/foo')

@raises(Exception)
def test_delete_points_with_wrong_name(self):
Expand Down Expand Up @@ -342,7 +345,7 @@ def test_query(self):
with _mocked_session('get', 200, data):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
result = cli.query('select column_one from foo;')
assert len(result[0]['points']) == 4
self.assertEqual(len(result[0]['points']), 4)

def test_query_chunked(self):
cli = InfluxDBClient(database='db')
Expand Down Expand Up @@ -422,7 +425,7 @@ def test_query_bad_precision(self):
def test_create_database(self):
with _mocked_session('post', 201, {"name": "new_db"}):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
assert cli.create_database('new_db') is True
self.assertTrue(cli.create_database('new_db'))

@raises(Exception)
def test_create_database_fails(self):
Expand All @@ -433,7 +436,7 @@ def test_create_database_fails(self):
def test_delete_database(self):
with _mocked_session('delete', 204):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
assert cli.delete_database('old_db') is True
self.assertTrue(cli.delete_database('old_db'))

@raises(Exception)
def test_delete_database_fails(self):
Expand All @@ -447,8 +450,8 @@ def test_get_list_database(self):
]
with _mocked_session('get', 200, data):
cli = InfluxDBClient('host', 8086, 'username', 'password')
assert len(cli.get_list_database()) == 1
assert cli.get_list_database()[0]['name'] == 'a_db'
self.assertEqual(len(cli.get_list_database()), 1)
self.assertEqual(cli.get_list_database()[0]['name'], 'a_db')

@raises(Exception)
def test_get_list_database_fails(self):
Expand All @@ -463,8 +466,8 @@ def test_get_database_list_deprecated(self):
]
with _mocked_session('get', 200, data):
cli = InfluxDBClient('host', 8086, 'username', 'password')
assert len(cli.get_database_list()) == 1
assert cli.get_database_list()[0]['name'] == 'a_db'
self.assertEqual(len(cli.get_database_list()), 1)
self.assertEqual(cli.get_database_list()[0]['name'], 'a_db')

def test_delete_series(self):
with _mocked_session('delete', 204):
Expand Down
9 changes: 4 additions & 5 deletions tests/influxdb/influxdb08/dataframe_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def test_write_points_from_dataframe_in_batches(self):
"http://localhost:8086/db/db/series")

cli = DataFrameClient(database='db')
assert cli.write_points({"foo": dataframe},
batch_size=1) is True
self.assertTrue(cli.write_points({"foo": dataframe}, batch_size=1))

def test_write_points_from_dataframe_with_numeric_column_names(self):
now = pd.Timestamp('1970-01-01 00:00+00:00')
Expand Down Expand Up @@ -239,15 +238,15 @@ def test_query_multiple_time_series(self):
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
result = cli.query("""select mean(value), min(value), max(value),
stddev(value) from series1, series2, series3""")
assert dataframes.keys() == result.keys()
self.assertEqual(dataframes.keys(), result.keys())
for key in dataframes.keys():
assert_frame_equal(dataframes[key], result[key])

def test_query_with_empty_result(self):
with _mocked_session('get', 200, []):
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
result = cli.query('select column_one from foo;')
assert result == []
self.assertEqual(result, [])

def test_list_series(self):
response = [
Expand All @@ -260,7 +259,7 @@ def test_list_series(self):
with _mocked_session('get', 200, response):
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
series_list = cli.get_list_series()
assert series_list == ['seriesA', 'seriesB']
self.assertEqual(series_list, ['seriesA', 'seriesB'])

def test_datetime_to_epoch(self):
timestamp = pd.Timestamp('2013-01-01 00:00:00.000+00:00')
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy