Skip to content

Commit a217390

Browse files
Grégory Starckaviau
authored andcommitted
adapté:
+ test_write_points_check_read + test_write_multiple_points_different_series + test_create_retention_policy_default
1 parent 37be5b2 commit a217390

File tree

1 file changed

+102
-38
lines changed

1 file changed

+102
-38
lines changed

tests/influxdb/client_test_with_server.py

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from __future__ import print_function
1414
import random
15-
15+
from collections import OrderedDict
1616
import datetime
1717
import distutils.spawn
1818
from functools import partial
@@ -360,22 +360,40 @@ def test_write_points_check_read(self):
360360
''' same as test_write_check_read() but with write_points \o/ '''
361361
self.test_write_points()
362362
time.sleep(1) # same as test_write_check_read()
363+
rsp = self.cli.query('SELECT * FROM cpu_load_short')
363364
self.assertEqual(
364-
{'cpu_load_short': [
365-
{'value': 0.64, 'time': '2009-11-10T23:00:00Z'}]},
366-
self.cli.query('SELECT * FROM cpu_load_short'))
365+
[{'values': [['2009-11-10T23:00:00Z', 0.64]],
366+
'name': 'cpu_load_short',
367+
'columns': ['time', 'value']}],
368+
list(rsp)
369+
)
370+
371+
rsp2 = list(rsp['cpu_load_short'])
372+
self.assertEqual(len(rsp2), 1)
373+
pt = rsp2[0]
374+
375+
self.assertEqual(
376+
['cpu_load_short', ['time', 'value'], {}, ['2009-11-10T23:00:00Z', 0.64]],
377+
[pt.serie, pt.columns, pt.tags, [pt.values.time, pt.values.value]]
378+
)
367379

368380
def test_write_multiple_points_different_series(self):
369381
self.assertIs(True, self.cli.write_points(dummy_points))
370382
time.sleep(1)
383+
rsp = self.cli.query('SELECT * FROM cpu_load_short')
384+
lrsp = list(rsp)
371385
self.assertEqual(
372-
{'cpu_load_short': [
373-
{'value': 0.64, 'time': '2009-11-10T23:00:00Z'}]},
374-
self.cli.query('SELECT * FROM cpu_load_short'))
386+
[{'values': [['2009-11-10T23:00:00Z', 0.64]],
387+
'name': 'cpu_load_short',
388+
'columns': ['time', 'value']}],
389+
lrsp)
390+
rsp = list(self.cli.query('SELECT * FROM memory'))
375391
self.assertEqual(
376-
{'memory': [
377-
{'time': '2009-11-10T23:01:35Z', 'value': 33}]},
378-
self.cli.query('SELECT * FROM memory'))
392+
[{
393+
'values': [['2009-11-10T23:01:35Z', 33]],
394+
'name': 'memory', 'columns': ['time', 'value']}],
395+
rsp
396+
)
379397

380398
@unittest.skip('Not implemented for 0.9')
381399
def test_write_points_batch(self):
@@ -465,7 +483,7 @@ def test_write_points_with_precision(self):
465483
time.sleep(sleep_time)
466484

467485
rsp = self.cli.query('SELECT * FROM cpu_load_short', database=db)
468-
486+
rsp = list(rsp)[0]
469487
# sys.stderr.write('precision=%s rsp_timestamp = %r\n' % (
470488
# precision, rsp['cpu_load_short'][0]['time']))
471489
m = re.match(expected_regex, rsp['cpu_load_short'][0]['time'])
@@ -524,13 +542,10 @@ def test_create_retention_policy_default(self):
524542
default=True)
525543
self.assertIsNone(rsp)
526544
rsp = self.cli.get_list_retention_policies()
527-
self.assertEqual(
528-
[
529-
{'duration': '0', 'default': False,
530-
'replicaN': 1, 'name': 'default'},
531-
{'duration': '24h0m0s', 'default': True,
532-
'replicaN': 4, 'name': 'somename'}
533-
],
545+
self.assertEqual([
546+
{'columns': ['name', 'duration', 'replicaN', 'default'],
547+
'values': [['default', '0', 1, False],
548+
['somename', '24h0m0s', 4, True]]}],
534549
rsp
535550
)
536551

@@ -548,23 +563,27 @@ def test_create_retention_policy(self):
548563
)
549564

550565
def test_issue_143(self):
551-
pt = partial(point, 'serie', timestamp='2015-03-30T16:16:37Z')
566+
pt = partial(point, 'a_serie_name', timestamp='2015-03-30T16:16:37Z')
552567
pts = [
553568
pt(value=15),
554569
pt(tags={'tag_1': 'value1'}, value=5),
555570
pt(tags={'tag_1': 'value2'}, value=10),
556571
]
557572
self.cli.write_points(pts)
558573
time.sleep(1)
559-
rsp = self.cli.query('SELECT * FROM serie GROUP BY tag_1')
574+
rsp = list(self.cli.query('SELECT * FROM a_serie_name GROUP BY tag_1'))
560575
# print(rsp, file=sys.stderr)
561-
self.assertEqual({
562-
('serie', (('tag_1', ''),)): [
563-
{'time': '2015-03-30T16:16:37Z', 'value': 15}],
564-
('serie', (('tag_1', 'value1'),)): [
565-
{'time': '2015-03-30T16:16:37Z', 'value': 5}],
566-
('serie', (('tag_1', 'value2'),)): [
567-
{'time': '2015-03-30T16:16:37Z', 'value': 10}]},
576+
577+
self.assertEqual([
578+
{'name': 'a_serie_name', 'columns': ['time', 'value'],
579+
'values': [['2015-03-30T16:16:37Z', 15]],
580+
'tags': {'tag_1': ''}},
581+
{'name': 'a_serie_name', 'columns': ['time', 'value'],
582+
'values': [['2015-03-30T16:16:37Z', 5]],
583+
'tags': {'tag_1': 'value1'}},
584+
{'name': 'a_serie_name', 'columns': ['time', 'value'],
585+
'values': [['2015-03-30T16:16:37Z', 10]],
586+
'tags': {'tag_1': 'value2'}}],
568587
rsp
569588
)
570589

@@ -579,20 +598,38 @@ def test_issue_143(self):
579598
time.sleep(1)
580599
rsp = self.cli.query('SELECT * FROM serie2 GROUP BY tag1,tag2')
581600
# print(rsp, file=sys.stderr)
601+
self.assertEqual([
602+
{'name': 'serie2', 'columns': ['time', 'value'],
603+
'values': [['2015-03-30T16:16:37Z', 0]],
604+
'tags': {'tag2': 'v1', 'tag1': 'value1'}},
605+
{'name': 'serie2', 'columns': ['time', 'value'],
606+
'values': [['2015-03-30T16:16:37Z', 5]],
607+
'tags': {'tag2': 'v2', 'tag1': 'value1'}},
608+
{'name': 'serie2', 'columns': ['time', 'value'],
609+
'values': [['2015-03-30T16:16:37Z', 10]],
610+
'tags': {'tag2': 'v1', 'tag1': 'value2'}}],
611+
list(rsp)
612+
)
613+
614+
d = all_tag2_equal_v1 = list(rsp[None, {'tag2': 'v1'}])
582615
self.assertEqual(
583-
{
584-
('serie2', (('tag1', 'value1'), ('tag2', 'v1'))): [
585-
{'time': '2015-03-30T16:16:37Z', 'value': 0}
586-
],
587-
('serie2', (('tag1', 'value1'), ('tag2', 'v2'))): [
588-
{'time': '2015-03-30T16:16:37Z', 'value': 5}
589-
],
590-
('serie2', (('tag1', 'value2'), ('tag2', 'v1'))): [
591-
{'time': '2015-03-30T16:16:37Z', 'value': 10}]
592-
},
593-
rsp
616+
[
617+
2,
618+
['time', 'value'],
619+
{'tag2': 'v1', 'tag1': 'value1'},
620+
['2015-03-30T16:16:37Z', 0],
621+
{'tag2': 'v1', 'tag1': 'value2'},
622+
['2015-03-30T16:16:37Z', 10]
623+
],
624+
[
625+
len(d),
626+
d[0].columns,
627+
d[0].tags, [d[0].values.time, d[0].values.value],
628+
d[1].tags, [d[1].values.time, d[1].values.value]
629+
]
594630
)
595631

632+
596633
def test_tags_json_order(self):
597634
n_pts = 100
598635
n_tags = 5 # that will make 120 possible orders (fact(5) == 120)
@@ -647,6 +684,33 @@ def test_tags_json_order(self):
647684
rsp_tags = tuple(t[0] for t in serie_key[1])
648685
self.assertEqual(expected_ordered_tags, rsp_tags)
649686

687+
688+
def test_query_multiple_series(self):
689+
pt = partial(point, 'serie1', timestamp='2015-03-30T16:16:37Z')
690+
pts = [
691+
pt(tags={'tag1': 'value1', 'tag2': 'v1'}, value=0),
692+
#pt(tags={'tag1': 'value1', 'tag2': 'v2'}, value=5),
693+
#pt(tags={'tag1': 'value2', 'tag2': 'v1'}, value=10),
694+
]
695+
self.cli.write_points(pts)
696+
697+
pt = partial(point, 'serie2', timestamp='1970-03-30T16:16:37Z')
698+
pts = [
699+
pt(tags={'tag1': 'value1', 'tag2': 'v1'}, value=0, data1=33, data2="bla"),
700+
#pt(tags={'tag1': 'value1', 'tag2': 'v2'}, value=5),
701+
#pt(tags={'tag1': 'value2', 'tag2': 'v3'}, value=10), # data2="what"),
702+
]
703+
self.cli.write_points(pts)
704+
705+
rsp = self.cli.query('SELECT * FROM serie1, serie2')
706+
print(rsp)
707+
708+
# same but with the tags given :
709+
#rsp = self.cli.query('SELECT * FROM serie1, serie2 GROUP BY *')
710+
print(rsp)
711+
712+
713+
650714
############################################################################
651715

652716

0 commit comments

Comments
 (0)
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