Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Adapted tests to rc30
Browse files Browse the repository at this point in the history
  • Loading branch information
aviau committed May 13, 2015
1 parent 5d5661a commit 47c6fbc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 35 deletions.
2 changes: 1 addition & 1 deletion influxdb/_dataframe_client.py
Expand Up @@ -140,7 +140,7 @@ def _convert_dataframe_to_json(self, dataframe, measurement, tags=None):
{'name': measurement,
'tags': tags if tags else {},
'fields': rec,
'timestamp': ts.isoformat()
'time': ts.isoformat()
}
for ts, rec in zip(dataframe.index, dataframe.to_dict('record'))]
return points
Expand Down
17 changes: 11 additions & 6 deletions tests/influxdb/client_test.py
Expand Up @@ -137,7 +137,8 @@ def test_write(self):
with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.POST,
"http://localhost:8086/write"
"http://localhost:8086/write",
status_code=204
)
cli = InfluxDBClient(database='db')
cli.write(
Expand Down Expand Up @@ -165,7 +166,8 @@ def test_write_points(self):
with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.POST,
"http://localhost:8086/write"
"http://localhost:8086/write",
status_code=204
)

cli = InfluxDBClient(database='db')
Expand All @@ -184,7 +186,8 @@ def test_write_points_toplevel_attributes(self):
with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.POST,
"http://localhost:8086/write"
"http://localhost:8086/write",
status_code=204
)

cli = InfluxDBClient(database='db')
Expand Down Expand Up @@ -222,7 +225,8 @@ def test_write_points_batch(self):
"fields": {"value": 12.00}}]}
with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write")
"http://localhost:8086/write",
status_code=204)
cli = InfluxDBClient(database='db')
cli.write_points(points=dummy_points,
database='db',
Expand Down Expand Up @@ -278,7 +282,8 @@ def test_write_points_with_precision(self):
with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.POST,
"http://localhost:8086/write"
"http://localhost:8086/write",
status_code=204
)

cli = InfluxDBClient(database='db')
Expand Down Expand Up @@ -559,7 +564,7 @@ def connection_error(self, *args, **kwargs):
raise requests.exceptions.ConnectionError
else:
r = requests.Response()
r.status_code = 200
r.status_code = 204
return r

mock_request.side_effect = CustomMock().connection_error
Expand Down
26 changes: 13 additions & 13 deletions tests/influxdb/client_test_with_server.py
Expand Up @@ -79,7 +79,7 @@
def point(serie_name, timestamp=None, tags=None, **fields):
res = {'name': serie_name}
if timestamp:
res['timestamp'] = timestamp
res['time'] = timestamp
if tags:
res['tags'] = tags
res['fields'] = fields
Expand All @@ -93,7 +93,7 @@ def point(serie_name, timestamp=None, tags=None, **fields):
"host": "server01",
"region": "us-west"
},
"timestamp": "2009-11-10T23:00:00Z",
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
Expand All @@ -108,7 +108,7 @@ def point(serie_name, timestamp=None, tags=None, **fields):
"host": "server01",
"region": "us-west"
},
"timestamp": "2009-11-10T23:01:35Z",
"time": "2009-11-10T23:01:35Z",
"fields": {
"value": 33
}
Expand Down Expand Up @@ -331,6 +331,7 @@ def test_create_database(self):
[{'name': 'new_db_1'}, {'name': 'new_db_2'}]
)

@unittest.skip("Broken as of 0.9.0-rc30")
def test_create_database_fails(self):
self.assertIsNone(self.cli.create_database('new_db'))
with self.assertRaises(InfluxDBClientError) as ctx:
Expand All @@ -344,13 +345,15 @@ def test_drop_database(self):
self.assertIsNone(self.cli.drop_database('new_db_1'))
self.assertEqual([{'name': 'new_db_2'}], self.cli.get_list_database())

@unittest.skip("Broken as of 0.9.0-rc30")
def test_drop_database_fails(self):
with self.assertRaises(InfluxDBClientError) as ctx:
self.cli.drop_database('db')
self.assertEqual(500, ctx.exception.code)
self.assertIn('{"results":[{"error":"database not found: db',
ctx.exception.content)

@unittest.skip("Broken as of 0.9.0-rc30")
def test_query_fail(self):
with self.assertRaises(InfluxDBClientError) as ctx:
self.cli.query('select column_one from foo')
Expand Down Expand Up @@ -396,6 +399,7 @@ def test_drop_user(self):
users = list(self.cli.query("SHOW USERS")['results'])
self.assertEqual(users, [])

@unittest.skip("Broken as of 0.9.0-rc30")
def test_drop_user_nonexisting(self):
with self.assertRaises(InfluxDBClientError) as ctx:
self.cli.drop_user('test')
Expand Down Expand Up @@ -506,12 +510,10 @@ def test_write_check_read(self):
)

def test_write_points(self):
""" same as test_write() but with write_points \o/ """
self.assertIs(True, self.cli.write_points(dummy_point))

@skipIfPYpy
def test_write_points_DF(self):
""" same as test_write() but with write_points \o/ """
self.assertIs(
True,
self.cliDF.write_points(
Expand All @@ -522,7 +524,6 @@ def test_write_points_DF(self):
)

def test_write_points_check_read(self):
""" same as test_write_check_read() but with write_points \o/ """
self.test_write_points()
time.sleep(1) # same as test_write_check_read()
rsp = self.cli.query('SELECT * FROM cpu_load_short')
Expand All @@ -543,7 +544,6 @@ def test_write_points_check_read(self):

@skipIfPYpy
def test_write_points_check_read_DF(self):
""" same as test_write_check_read() but with write_points \o/ """
self.test_write_points_DF()
time.sleep(1) # same as test_write_check_read()

Expand Down Expand Up @@ -605,11 +605,11 @@ def test_write_multiple_points_different_series_DF(self):
def test_write_points_batch(self):
dummy_points = [
{"name": "cpu_usage", "tags": {"unit": "percent"},
"timestamp": "2009-11-10T23:00:00Z", "fields": {"value": 12.34}},
"time": "2009-11-10T23:00:00Z", "fields": {"value": 12.34}},
{"name": "network", "tags": {"direction": "in"},
"timestamp": "2009-11-10T23:00:00Z", "fields": {"value": 123.00}},
"time": "2009-11-10T23:00:00Z", "fields": {"value": 123.00}},
{"name": "network", "tags": {"direction": "out"},
"timestamp": "2009-11-10T23:00:00Z", "fields": {"value": 12.00}}
"time": "2009-11-10T23:00:00Z", "fields": {"value": 12.00}}
]
self.cli.write_points(points=dummy_points,
tags={"host": "server01",
Expand All @@ -626,9 +626,9 @@ def test_write_points_batch(self):
self.assertIn(12.34, cpu['series'][0]['values'][0])

def test_write_points_with_precision(self):
''' check that points written with an explicit precision have
""" check that points written with an explicit precision have
actually that precision used.
'''
"""
# for that we'll check that - for each precision - the actual 'time'
# value returned by a select has the correct regex format..
# n : u'2015-03-20T15:23:36.615654966Z'
Expand All @@ -646,7 +646,7 @@ def test_write_points_with_precision(self):
"host": "server01",
"region": "us-west"
},
"timestamp": "2009-11-10T12:34:56.123456789Z",
"time": "2009-11-10T12:34:56.123456789Z",
"fields": {
"value": 0.64
}
Expand Down
37 changes: 22 additions & 15 deletions tests/influxdb/dataframe_client_test.py
Expand Up @@ -34,14 +34,14 @@ def test_write_points_from_dataframe(self):
expected = {
'database': 'db',
'points': [
{'timestamp': '1970-01-01T00:00:00+00:00',
{'time': '1970-01-01T00:00:00+00:00',
'fields': {
'column_two': 1,
'column_three': 1.0,
'column_one': '1'},
'tags': {},
'name': 'foo'},
{'timestamp': '1970-01-01T01:00:00+00:00',
{'time': '1970-01-01T01:00:00+00:00',
'fields': {
'column_two': 2,
'column_three': 2.0,
Expand All @@ -52,7 +52,8 @@ def test_write_points_from_dataframe(self):

with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write")
"http://localhost:8086/write",
status_code=204)

cli = DataFrameClient(database='db')

Expand All @@ -70,7 +71,8 @@ def test_write_points_from_dataframe_in_batches(self):
"column_three"])
with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write")
"http://localhost:8086/write",
status_code=204)

cli = DataFrameClient(database='db')
assert cli.write_points(dataframe, "foo", batch_size=1) is True
Expand All @@ -89,20 +91,21 @@ def test_write_points_from_dataframe_with_numeric_column_names(self):
'1': 1,
'2': 1.0},
'tags': {'hello': 'there'},
'timestamp': '1970-01-01T00:00:00+00:00',
'time': '1970-01-01T00:00:00+00:00',
'name': 'foo'},
{'fields': {
'0': '2',
'1': 2,
'2': 2.0},
'tags': {'hello': 'there'},
'timestamp': '1970-01-01T01:00:00+00:00',
'time': '1970-01-01T01:00:00+00:00',
'name': 'foo'}],
}

with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write")
"http://localhost:8086/write",
status_code=204)

cli = DataFrameClient(database='db')
cli.write_points(dataframe, "foo", {"hello": "there"})
Expand All @@ -123,20 +126,21 @@ def test_write_points_from_dataframe_with_period_index(self):
'column_one': '1',
'column_two': 1,
'column_three': 1.0},
'timestamp': '1970-01-01T00:00:00+00:00'},
'time': '1970-01-01T00:00:00+00:00'},
{'name': 'foo',
'tags': {},
'fields': {
'column_one': '2',
'column_two': 2,
'column_three': 2.0},
'timestamp': '1970-01-02T00:00:00+00:00'}],
'time': '1970-01-02T00:00:00+00:00'}],
'database': 'db',
}

with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write")
"http://localhost:8086/write",
status_code=204)

cli = DataFrameClient(database='db')
cli.write_points(dataframe, "foo")
Expand All @@ -152,19 +156,20 @@ def test_write_points_from_dataframe_with_time_precision(self):

with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/write")
"http://localhost:8086/write",
status_code=204)

points = {
'database': 'db',
'points': [
{'timestamp': '1970-01-01T00:00:00+00:00',
{'time': '1970-01-01T00:00:00+00:00',
'fields': {
'column_one': '1',
'column_three': 1.0,
'column_two': 1},
'tags': {},
'name': 'foo'},
{'timestamp': '1970-01-01T01:00:00+00:00',
{'time': '1970-01-01T01:00:00+00:00',
'fields': {
'column_one': '2',
'column_three': 2.0,
Expand Down Expand Up @@ -196,7 +201,8 @@ def test_write_points_from_dataframe_fails_without_time_index(self):

with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/db/db/series")
"http://localhost:8086/db/db/series",
status_code=204)

cli = DataFrameClient(database='db')
cli.write_points(dataframe, "foo")
Expand All @@ -209,7 +215,8 @@ def test_write_points_from_dataframe_fails_with_series(self):

with requests_mock.Mocker() as m:
m.register_uri(requests_mock.POST,
"http://localhost:8086/db/db/series")
"http://localhost:8086/db/db/series",
status_code=204)

cli = DataFrameClient(database='db')
cli.write_points(dataframe, "foo")
Expand Down

0 comments on commit 47c6fbc

Please sign in to comment.