-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
134 lines (106 loc) · 4.94 KB
/
tests.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import unittest
from popily_api import *
from settings import API_KEY, CONNECTION_STRING
URL = 'https://staging.popily.com'
class APITest(unittest.TestCase):
def test_add_source(self):
popily = Popily(API_KEY, url=URL)
source_data = {
'connection_string': CONNECTION_STRING,
'query': 'SELECT * FROM employees LIMIT 100;',
'columns': [
{
'data_type': 'rowlabel',
'column_header': 'emp_no'
},
{
'data_type': 'unknown',
'column_header': 'first_name'
},
{
'data_type': 'unknown',
'column_header': 'last_name'
},
{
'data_type': 'datetime',
'column_header': 'birth_date'
},
{
'data_type': 'datetime',
'column_header': 'hire_date'
},
{
'data_type': 'category',
'column_header': 'gender'
}
]
}
#source = popily.add_source(**source_data)
#self.assertTrue('id' in source)
def test_get_sources(self):
popily = Popily(API_KEY, url=URL)
sources = popily.get_sources()
self.assertTrue('results' in sources)
self.assertTrue(len(sources['results']) > 0)
def test_get_source(self):
popily = Popily(API_KEY, url=URL)
source = popily.get_source('employees-limit-100-1')
self.assertTrue('id' in source)
def test_get_insights(self):
popily = Popily(API_KEY, url=URL)
insights = popily.get_insights('employees-limit-100-1')
self.assertTrue('results' in insights)
self.assertTrue(len(insights['results']) > 0)
def test_get_insights_columns(self):
popily = Popily(API_KEY, url=URL)
insights = popily.get_insights('employees-limit-100-1',columns=['gender'])
all_insights = popily.get_insights('employees-limit-100-1')
self.assertTrue('results' in insights)
self.assertTrue(len(insights['results']) > 0)
self.assertTrue(len(all_insights['results']) > len(insights['results']))
def test_get_insights_filters(self):
popily = Popily(API_KEY, url=URL)
insights = popily.get_insights('employees-limit-100-1',
columns=['gender','hire_date'],
filters=[{'column':'gender','values': ['F']}],
full=True)
self.assertTrue('results' in insights)
self.assertTrue(len(insights['results']) > 0)
for result in insights['results']:
self.assertTrue(all([v == 'F' for v in result['z_values']]))
def test_get_insights_single(self):
popily = Popily(API_KEY, url=URL)
insight = popily.get_insights('employees-limit-100-1',
columns=['gender','hire_date'],
filters=[{'column':'gender','values': ['F']}],
full=True,
single=True,
insight_actions=['count'])
self.assertTrue('id' in insight)
self.assertTrue(all([v == 'F' for v in insight['z_values']]))
self.assertTrue(insight['insight_action'] == 'count')
insight = popily.get_insights('employees-limit-100-1',
columns=['hire_date'],
full=True,
single=True,
insight_actions=['ratio'])
self.assertTrue(insight['insight_action'] == 'ratio')
insight = popily.get_insights('employees-limit-100-1',
columns=['hire_date'],
full=True,
single=True,
insight_actions=['count'])
self.assertTrue(insight['insight_action'] == 'count')
def test_customize_insight(self):
import uuid
popily = Popily(API_KEY, url=URL)
random_title = str(uuid.uuid4().get_hex().upper()[0:6])
insight = popily.get_insights('employees-limit-100-1',
columns=['gender','hire_date'],
filters=[{'column':'gender','values': ['F']}],
full=True,
single=True,
insight_actions=['count'],
title=random_title)
self.assertTrue(insight['title'] == random_title)
self.assertTrue('embed_url' in insight)