mirror of
https://github.com/getredash/redash.git
synced 2026-03-22 10:00:17 -04:00
* Consistently use simplejson to loading and dumping JSON. This introduces the new functions redash.utils.json_dumps and redash.utils.json_loads and simplifies the custom encoder setup. UUIDs are now handled by the default encoder, too. Fixes #2807. Use string comparison in parse_boolean instead of the (simple)json module.
99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
import datetime
|
|
from unittest import TestCase
|
|
|
|
from redash.query_runner.prometheus import get_instant_rows, get_range_rows
|
|
|
|
|
|
class TestPrometheus(TestCase):
|
|
def setUp(self):
|
|
self.instant_query_result = [
|
|
{
|
|
"metric": {
|
|
"name": "example_metric_name",
|
|
"foo_bar": "foo",
|
|
},
|
|
"value": [1516937400.781, "7400_foo"]
|
|
},
|
|
{
|
|
"metric": {
|
|
"name": "example_metric_name",
|
|
"foo_bar": "bar",
|
|
},
|
|
"value": [1516937400.781, "7400_bar"]
|
|
}
|
|
]
|
|
|
|
self.range_query_result = [
|
|
{
|
|
"metric": {
|
|
"name": "example_metric_name",
|
|
"foo_bar": "foo",
|
|
},
|
|
"values": [
|
|
[1516937400.781, "7400_foo"],
|
|
[1516938000.781, "8000_foo"],
|
|
]
|
|
},
|
|
{
|
|
"metric": {
|
|
"name": "example_metric_name",
|
|
"foo_bar": "bar",
|
|
},
|
|
"values": [
|
|
[1516937400.781, "7400_bar"],
|
|
[1516938000.781, "8000_bar"],
|
|
]
|
|
}
|
|
]
|
|
|
|
def test_get_instant_rows(self):
|
|
instant_rows = [
|
|
{
|
|
"name": "example_metric_name",
|
|
"foo_bar": "foo",
|
|
"timestamp": datetime.datetime.fromtimestamp(1516937400.781),
|
|
"value": "7400_foo"
|
|
},
|
|
{
|
|
"name": "example_metric_name",
|
|
"foo_bar": "bar",
|
|
"timestamp": datetime.datetime.fromtimestamp(1516937400.781),
|
|
"value": "7400_bar"
|
|
},
|
|
]
|
|
|
|
rows = get_instant_rows(self.instant_query_result)
|
|
self.assertEqual(instant_rows, rows)
|
|
|
|
def test_get_range_rows(self):
|
|
|
|
range_rows = [
|
|
{
|
|
"name": "example_metric_name",
|
|
"foo_bar": "foo",
|
|
"timestamp": datetime.datetime.fromtimestamp(1516937400.781),
|
|
"value": "7400_foo"
|
|
},
|
|
{
|
|
"name": "example_metric_name",
|
|
"foo_bar": "foo",
|
|
"timestamp": datetime.datetime.fromtimestamp(1516938000.781),
|
|
"value": "8000_foo"
|
|
},
|
|
{
|
|
"name": "example_metric_name",
|
|
"foo_bar": "bar",
|
|
"timestamp": datetime.datetime.fromtimestamp(1516937400.781),
|
|
"value": "7400_bar"
|
|
},
|
|
{
|
|
"name": "example_metric_name",
|
|
"foo_bar": "bar",
|
|
"timestamp": datetime.datetime.fromtimestamp(1516938000.781),
|
|
"value": "8000_bar"
|
|
},
|
|
]
|
|
|
|
rows = get_range_rows(self.range_query_result)
|
|
self.assertEqual(range_rows, rows)
|