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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
from .base import TestCase
from graphite.errors import InputParameterError
class ErrorTest(TestCase):
def test_input_parameter_error_basic(self):
e = InputParameterError('exception details')
self.assertEqual(
str(e),
'Invalid parameters (exception details)',
)
def test_input_parameter_error_with_func(self):
e = InputParameterError('exception details')
e.setFunction('test_func', [], {})
self.assertEqual(
str(e),
'Invalid parameters (exception details); func: "test_func()"',
)
def test_input_parameter_error_with_func_and_args(self):
e = InputParameterError('exception details')
e.setFunction('test_func', [1, 'a'], {})
self.assertEqual(
str(e),
'Invalid parameters (exception details); func: "test_func(1, \'a\')"',
)
def test_input_parameter_error_with_func_and_kwargs(self):
e = InputParameterError('exception details')
e.setFunction('test_func', [], {'a': 1, 'b': 'b'})
self.assertEqual(
str(e),
'Invalid parameters (exception details); func: "test_func(a=1, b=\'b\')"',
)
def test_input_parameter_error_with_func_args_kwargs(self):
e = InputParameterError('exception details')
e.setFunction('test_func', [3, 'd'], {'a': 1, 'b': 'b'})
self.assertEqual(
str(e),
'Invalid parameters (exception details); func: "test_func(3, \'d\', a=1, b=\'b\')"',
)
def test_input_parameter_error_with_target(self):
e = InputParameterError('exception details')
e.setTargets(['some_func(a.b.c)'])
self.assertEqual(
str(e),
'Invalid parameters (exception details); targets: "some_func(a.b.c)"',
)
def test_input_parameter_error_with_multiple_targets(self):
e = InputParameterError('exception details')
e.setTargets(['some_func(a.b.c)', 'otherfunc(c.b.a)'])
self.assertEqual(
str(e),
'Invalid parameters (exception details); targets: "some_func(a.b.c), otherfunc(c.b.a)"',
)
def test_input_parameter_error_with_grafana_org_id(self):
e = InputParameterError('exception details')
e.setSourceIdHeaders({'X-GRAFANA-ORG-ID': 3})
self.assertEqual(
str(e),
'Invalid parameters (exception details); source: "X-GRAFANA-ORG-ID: 3"',
)
def test_input_parameter_error_with_dashboard_id(self):
e = InputParameterError('exception details')
e.setSourceIdHeaders({'X-DASHBOARD-ID': 'abcde123'})
self.assertEqual(
str(e),
'Invalid parameters (exception details); source: "X-DASHBOARD-ID: abcde123"',
)
def test_input_parameter_error_with_panel_id(self):
e = InputParameterError('exception details')
e.setSourceIdHeaders({'X-PANEL-ID': 12})
self.assertEqual(
str(e),
'Invalid parameters (exception details); source: "X-PANEL-ID: 12"',
)
def test_input_parameter_error_with_all_source_id(self):
e = InputParameterError('exception details')
e.setSourceIdHeaders({'X-GRAFANA-ORG-ID': 25, 'X-DASHBOARD-ID': 12})
e.setSourceIdHeaders({'X-PANEL-ID': 3})
self.assertEqual(
str(e),
'Invalid parameters (exception details); source: "X-DASHBOARD-ID: 12, X-GRAFANA-ORG-ID: 25, X-PANEL-ID: 3"',
)
def test_input_parameter_error_with_all_properties(self):
e = InputParameterError('exception details')
e.setSourceIdHeaders({'X-DASHBOARD-ID': 'a'})
e.setSourceIdHeaders({'X-GRAFANA-ORG-ID': 'b'})
e.setSourceIdHeaders({'X-PANEL-ID': 'c'})
e.setTargets(['some(target, extra="value")'])
e.setFunction('some', ['target'], {'extra': 'value'})
self.assertEqual(
str(e),
'Invalid parameters (exception details)'
'; targets: "some(target, extra="value")"'
'; source: "X-DASHBOARD-ID: a, X-GRAFANA-ORG-ID: b, X-PANEL-ID: c"'
'; func: "some(\'target\', extra=\'value\')"'
)
|