|
1
|
|
|
import json |
|
2
|
|
|
|
|
3
|
|
|
from datetime import datetime as dt |
|
4
|
|
|
|
|
5
|
|
|
import pytest |
|
6
|
|
|
|
|
7
|
|
|
from flask_jsondash import charts_builder |
|
8
|
|
|
|
|
9
|
|
|
# Py2/3 compat. |
|
10
|
|
|
try: |
|
11
|
|
|
_unicode = unicode |
|
12
|
|
|
except NameError: |
|
13
|
|
|
_unicode = str |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
@pytest.mark.filters |
|
17
|
|
|
def test_getdims_normal(ctx, client): |
|
18
|
|
|
app, test = client |
|
19
|
|
|
data = dict(width=100, height=100, dataSource='...', type='sometype') |
|
20
|
|
|
expected = dict(width=100, height=100) |
|
21
|
|
|
assert charts_builder.get_dims(object, data) == expected |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
@pytest.mark.filters |
|
25
|
|
|
def test_getdims_youtube_invalid_url(ctx, client): |
|
26
|
|
|
app, test = client |
|
27
|
|
|
data = dict(type='youtube', dataSource=None, width=100, height=100) |
|
28
|
|
|
with pytest.raises(ValueError): |
|
29
|
|
|
charts_builder.get_dims(object, data) |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
@pytest.mark.filters |
|
33
|
|
|
def test_getdims_youtube(ctx, client): |
|
34
|
|
|
app, test = client |
|
35
|
|
|
yt = ('<iframe width="650" height="366" ' |
|
36
|
|
|
'src="https://www.youtube.com/embed/' |
|
37
|
|
|
'_hI0qMtdfng?list=RD_hI0qMtdfng&' |
|
38
|
|
|
'controls=0&showinfo=0" frameborder="0"' |
|
39
|
|
|
' allowfullscreen></iframe>') |
|
40
|
|
|
data = dict(type='youtube', dataSource=yt, width=100, height=100) |
|
41
|
|
|
expected = dict(width=650 + 20, height=366 + 60) |
|
42
|
|
|
assert charts_builder.get_dims(object, data) == expected |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
@pytest.mark.filters |
|
46
|
|
|
def test_jsonstring(ctx, client): |
|
47
|
|
|
app, test = client |
|
48
|
|
|
now = dt.now() |
|
49
|
|
|
data = dict(date=now, foo='bar') |
|
50
|
|
|
res = charts_builder.jsonstring(object, data) |
|
51
|
|
|
assert 'foo' in res |
|
52
|
|
|
assert isinstance(res, str) |
|
53
|
|
|
d = json.loads(res) |
|
54
|
|
|
assert isinstance(d['date'], _unicode) |
|
55
|
|
|
|