-
Notifications
You must be signed in to change notification settings - Fork 63
/
test_widget.py
108 lines (94 loc) · 3.16 KB
/
test_widget.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
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
import pytest
from cartoframes.viz import Widget
class TestWidget(object):
def test_is_widget_defined(self):
"""Widget"""
assert Widget is not None
def test_widget_init(self):
"""Widget should be properly initialized"""
widget = Widget({
'type': 'formula',
'value': 'viewportSum($amount)',
'title': '[TITLE]',
'description': '[description]',
'footer': '[footer]'
})
assert widget._type == 'formula'
assert widget._title == '[TITLE]'
assert widget._description == '[description]'
assert widget._footer == '[footer]'
def test_widget_info(self):
"""Widget should return a proper information object"""
widget = Widget({
'type': 'formula',
'value': 'viewportSum($amount)',
'title': '[TITLE]',
'description': '[description]',
'footer': '[footer]'
})
assert widget.get_info() == {
'type': 'formula',
'value': 'viewportSum($amount)',
'title': '[TITLE]',
'description': '[description]',
'footer': '[footer]',
'has_bridge': False,
'prop': '',
'variable_name': 'vb6dbcf',
'options': {
'readOnly': False,
'buckets': 20
}
}
def test_wrong_input(self):
"""Widget should raise an error if the input is not valid"""
msg = 'Wrong widget input.'
with pytest.raises(ValueError) as e:
Widget(1234)
assert str(e.value) == msg
def test_wrong_type(self):
"""Widget should raise an error if widget type is not valid"""
msg = 'Widget type is not valid. Valid widget types are: ' + \
'default, formula, histogram, category, animation, time-series.'
with pytest.raises(ValueError) as e:
Widget({'type': 'xxx'}).get_info()
assert str(e.value) == msg
def test_animation_widget(self):
"""An Animation widget should be created successfully with the default property"""
widget = Widget({
'type': 'animation',
})
assert widget.get_info() == {
'type': 'animation',
'title': '',
'value': '',
'description': '',
'footer': '',
'has_bridge': True,
'prop': 'filter',
'variable_name': '',
'options': {
'readOnly': False,
'buckets': 20
}
}
def test_animation_widget_prop(self):
"""An Animation widget should be created successfully with a custom property"""
widget = Widget({
'type': 'animation',
'prop': 'width'
})
assert widget.get_info() == {
'type': 'animation',
'title': '',
'value': '',
'description': '',
'footer': '',
'has_bridge': True,
'prop': 'width',
'variable_name': '',
'options': {
'readOnly': False,
'buckets': 20
}
}