-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_query.py
46 lines (34 loc) · 1.59 KB
/
test_query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import unittest
from config import Config
from query import Query
class QueryTest(unittest.TestCase):
""" Test query class. """
def setUp(self):
self.config = Config(default_endpoint='default', endpoints=[], indices=[],
field_format={}, default_fields={}, queries=[])
def test_parse_defaults(self):
""" Test defaults. """
query = Query(self.config)
self.assert_defaults(query)
def test_parse_simple(self):
""" Test simple query. """
query = Query(self.config, application_name="my-app", level='WARN')
self.assert_defaults(query,
args={'application_name': 'my-app',
'level': 'WARN'}
)
def test_as_url(self):
""" Test url conversion. """
query = Query(self.config)
self.assertEqual(query.as_url('/'), '/?dc=default&index=application-%2A&from=now-15m&to=now&interval=auto')
query = Query(self.config, level='WARN')
self.assertEqual(query.as_url('/'), '/?dc=default&index=application-%2A&from=now-15m&to=now&interval=auto&level=WARN')
def assert_defaults(self, query, args=None):
""" Assert query params. """
self.assertEqual(query.datacenter, 'default')
self.assertEqual(query.index, 'application-*')
self.assertEqual(query.from_timestamp, 'now-15m')
self.assertEqual(query.to_timestamp, 'now')
self.assertEqual(query.query_string, None)
self.assertEqual(query.fields, None)
self.assertEqual(query.args, args or {})