-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
189 lines (154 loc) · 5.04 KB
/
tests.py
File metadata and controls
189 lines (154 loc) · 5.04 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import OMdata
import dex
import requests
import json
"""
Tests for OMdata.py
"""
def TESTgetSurveyList():
results = OMdata.getSurveyList
if (results != None):
print 'getSurveyList() [PASSES]'
else:
print 'getSurveyList() [FAILED]'
def TESTgetEmailQuestionID():
sur = {
'LNGS': [
{'QUES' : [
{'Id': 'wrong', 'Type': 7, 'Text': 'lorem ip', 'IsHiddenQues': False},
{'Id': 'wrong 2', 'Type': 5, 'Text': 'ringdingdingding', 'IsHiddenQues': False},
{'Id': 'correct', 'Type': 7, 'Text': 'I want email please', 'IsHiddenQues': False}
]
}
]
}
results = OMdata.getEmailQuestionID(sur)
if (results == 'correct'):
print 'getEmailQuestionID() [PASSES]'
else:
print 'getEmailQuestionID() [FAILS]'
def TESTgetQuestionIdFromStrings():
sur = {
'LNGS': [
{'QUES' : [
{'Id': 'wrong', 'Type': 7, 'Text': 'lorem ip', 'IsHiddenQues': False},
{'Id': 'wrong 2', 'Type': 5, 'Text': 'ringdingdi email ngding', 'IsHiddenQues': False},
{'Id': 'correct', 'Type': 7, 'Text': 'I want zip please', 'IsHiddenQues': False}
]
}
]
}
results = OMdata.getQuestionIdFromStrings(sur, 'zip', 'postal')
if (results == 'correct'):
print 'getQuestionIdFromStrings() [PASSES]'
else:
print 'getQuestionIdFromStrings() [FAILS]'
def TESTgetEmailQuestionIndex():
sur = {
'LNGS': [
{'QUES' : [
{'Id': 'wrong', 'Type': 7, 'Text': 'lorem ip', 'IsHiddenQues': False},
{'Id': 'wrong 2', 'Type': 5, 'Text': 'ringdingdingding', 'IsHiddenQues': False},
{'Id': 'correct', 'Type': 7, 'Text': 'I want email please', 'IsHiddenQues': False}
]
}
]
}
results = OMdata.getEmailQuestionIndex(sur)
if (results == 2):
print 'getEmailQuestionIndex() [PASSES]'
else:
print 'getEmailQuestionIndex() [FAILS]'
def TESTgetQuestionIndexFromStrings():
sur = {
'LNGS': [
{'QUES' : [
{'Id': 'wrong', 'Type': 7, 'Text': 'lorem ip', 'IsHiddenQues': False},
{'Id': 'wrong 2', 'Type': 5, 'Text': 'ringd zip dingding', 'IsHiddenQues': False},
{'Id': 'correct', 'Type': 7, 'Text': 'I want fjksd please', 'IsHiddenQues': False}
]
}
]
}
results = OMdata.getQuestionIndexFromStrings(sur, ['hnksf', 'zip'])
if (results == 1):
print 'getQuestionIndexFromStrings() [PASSES]'
else:
print 'getQuestionIndexFromStrings() [FAILS]'
def TESTextractFieldsFromResponses():
surveySample = {
"Id" : 48688,
"SurveyResponses": [
{
"SurveyResponseID": 1618161487,
"Responses": [
{ "QId": 01561156, "Res": "dGVzdEB0ZXN0dHQuY29t"},
{ "QId": 1564, "Res": "0000"},
{ "QId": 456, "Res": "NDMyODc="}
]
},
{
"SurveyResponseID": 4878456,
"Responses": [
{ "QId": 445, "Res": "dGhpc0B0aGlzLmNvbQ=="},
{ "QId": 111222, "Res": "4444"},
{ "QId": 78, "Res": ""}
]
}
]
}
results = OMdata.extractFieldsFromResponses(surveySample, 0, {2:'ZIP'})
'''should return:
[
{
'merge_vars': {
'LOCATION': 'Baltimore',
'zip': '43287'
},
'email': {'email': 'test@testtt.com'},
'email_type': 'html'
},
{
'merge_vars': {
'LOCATION': 'Baltimore',
'zip': ''
},
'email': {'email': 'this@this.com'},
'email_type': 'html'
}
]
'''
if ( results[0]['merge_vars']['ZIP'] == '43287' and
results[1]['email']['email'] == 'this@this.com'):
print 'OMdata.extractFieldsFromResponses() [PASSES]'
else:
print 'OMdata.extractFieldsFromResponses() [FAILS]'
# def TESTgetEmailQuestionIndex():
# res = requests.get('http://www.ripleys.com/test.json')
# resObj = res.json()
# for sur in resObj:
# print sur['Name']
# emailIndex = OMdata.getEmailQuestionIndex(sur)
# print emailIndex
"""
TESTS FOR dex.py
"""
def TESTgetLocationName():
result = dex.getLocationName(48688)
if (result == 'Baltimore'):
print 'dex.getLocationName() [PASSES]'
else:
print 'dex.getLocationName() [FAILS]'
if __name__ == "__main__":
#OMdata
print 'TESTS for OMdata.py ---------'
TESTgetEmailQuestionID()
TESTgetSurveyList()
TESTgetQuestionIdFromStrings()
TESTgetEmailQuestionIndex()
TESTgetQuestionIndexFromStrings()
TESTextractFieldsFromResponses()
TESTgetEmailQuestionIndex()
#dex
print 'TESTS for dex.py-------------'
TESTgetLocationName()