Skip to content

Commit d61f1d0

Browse files
author
aviau
committed
ResultSet: query using only tags
1 parent 3ab875a commit d61f1d0

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

influxdb/resultset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ def __getitem__(self, key):
2727
tags = key[1]
2828
if not isinstance(tags, dict) and tags is not None:
2929
raise TypeError('tags should be a dict')
30+
elif isinstance(key, dict):
31+
name = None
32+
tags = key
3033
else:
3134
name = key
3235
tags = None
36+
3337
# TODO(aviau): Fix for python 3.2
3438
# if not isinstance(name, (str, bytes, type(None))) \
3539
# and not isinstance(name, type("".decode("utf-8"))):

tests/influxdb/resultset_test.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def setUp(self):
2222
"region": "us-west"},
2323
"columns": ["time", "value"],
2424
"values": [
25-
["2015-01-29T21:51:28.968422294Z", 0.64]
25+
["2015-01-29T21:51:28.968422294Z", 0.65]
2626
]},
2727
{"name": "other_serie",
2828
"tags": {"host": "server01",
2929
"region": "us-west"},
3030
"columns": ["time", "value"],
3131
"values": [
32-
["2015-01-29T21:51:28.968422294Z", 0.64]
32+
["2015-01-29T21:51:28.968422294Z", 0.66]
3333
]}]}
3434
]
3535
}
@@ -40,11 +40,20 @@ def test_filter_by_name(self):
4040
list(self.rs['cpu_load_short']),
4141
[
4242
{'value': 0.64, 'time': '2015-01-29T21:51:28.968422294Z'},
43-
{'value': 0.64, 'time': '2015-01-29T21:51:28.968422294Z'}
43+
{'value': 0.65, 'time': '2015-01-29T21:51:28.968422294Z'}
4444
]
4545
)
4646

4747
def test_filter_by_tags(self):
48+
self.assertEqual(
49+
list(self.rs[{"host": "server01"}]),
50+
[
51+
{'time': '2015-01-29T21:51:28.968422294Z', 'value': 0.64},
52+
{'time': '2015-01-29T21:51:28.968422294Z', 'value': 0.66}
53+
]
54+
)
55+
56+
def test_filter_by_name_and_tags(self):
4857
self.assertEqual(
4958
list(self.rs[('cpu_load_short', {"host": "server01"})]),
5059
[{'time': '2015-01-29T21:51:28.968422294Z', 'value': 0.64}]
@@ -54,7 +63,7 @@ def test_filter_by_tags(self):
5463
list(self.rs[('cpu_load_short', {"region": "us-west"})]),
5564
[
5665
{'value': 0.64, 'time': '2015-01-29T21:51:28.968422294Z'},
57-
{'value': 0.64, 'time': '2015-01-29T21:51:28.968422294Z'}
66+
{'value': 0.65, 'time': '2015-01-29T21:51:28.968422294Z'}
5867
]
5968
)
6069

@@ -89,12 +98,12 @@ def test_items(self):
8998
(
9099
('cpu_load_short',
91100
{'host': 'server02', 'region': 'us-west'}),
92-
[{'value': 0.64, 'time': '2015-01-29T21:51:28.968422294Z'}]
101+
[{'value': 0.65, 'time': '2015-01-29T21:51:28.968422294Z'}]
93102
),
94103
(
95104
('other_serie',
96105
{'host': 'server01', 'region': 'us-west'}),
97-
[{'value': 0.64, 'time': '2015-01-29T21:51:28.968422294Z'}]
106+
[{'value': 0.66, 'time': '2015-01-29T21:51:28.968422294Z'}]
98107
)
99108
]
100109
)

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