Skip to content

Commit 7cc9bf8

Browse files
committed
Merge pull request UWPCE-PythonCert#90 from dfugelso/master
Sessions 7, 8, 9 Homework
2 parents 9acf6f5 + f2fbe05 commit 7cc9bf8

File tree

129 files changed

+5091
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+5091
-0
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
#
2+
# TestHarness.py
3+
# Copyright (c) 2014 Airbiquity
4+
#
5+
# The tester emulates the body of requests coming over the network interface
6+
#
7+
8+
import sys
9+
import threading
10+
import json
11+
import time
12+
import Templates
13+
import FileCache
14+
import logger
15+
16+
# Remove this import if non interface to Alpine
17+
import HupInterface
18+
19+
msglogger = logger.Logger()
20+
21+
22+
'''
23+
The following are test for the Template interface
24+
'''
25+
26+
def testTemplate1 (filename):
27+
#print 'template1 file: ' + filename
28+
#msglogger.logMessage(logger.DEBUG, 'testTemplate1', filename)
29+
try:
30+
with open(filename) as tmp1_file:
31+
t = Templates.Template1 ()
32+
t.HandleRequest (tmp1_file.read())
33+
#print json.dumps(tmp1_file, indent=2)
34+
except IOError as e:
35+
print 'File read error' # TBD goes to error handler
36+
37+
def testTemplate2 (filename):
38+
try:
39+
with open(filename) as tmp1_file:
40+
t = Templates.Template2 ()
41+
t.HandleRequest (tmp1_file.read())
42+
#print json.dumps(tmp1_file, indent=2)
43+
except IOError as e:
44+
print 'File read error' # TBD goes to error handler
45+
46+
def testTemplate3 (filename):
47+
try:
48+
with open(filename) as tmp1_file:
49+
t = Templates.Template3 ()
50+
t.HandleRequest (tmp1_file.read())
51+
#print json.dumps(tmp1_file, indent=2)
52+
except IOError as e:
53+
print 'File read error' # TBD goes to error handler
54+
55+
def testTemplate4 (filename):
56+
try:
57+
with open(filename) as tmp1_file:
58+
t = Templates.Template4 ()
59+
t.HandleRequest (tmp1_file.read())
60+
#print json.dumps(tmp1_file, indent=2)
61+
except IOError as e:
62+
print 'File read error' # TBD goes to error handler
63+
64+
def testTemplate5 (filename):
65+
try:
66+
with open(filename) as tmp1_file:
67+
t = Templates.Template5 ()
68+
t.HandleRequest (tmp1_file.read())
69+
#print json.dumps(tmp1_file, indent=2)
70+
except IOError as e:
71+
print 'File read error' # TBD goes to error handler
72+
73+
def testTemplate6 (filename):
74+
try:
75+
with open(filename) as tmp1_file:
76+
t = Templates.Template6 ()
77+
t.HandleRequest (tmp1_file.read())
78+
#print json.dumps(tmp1_file, indent=2)
79+
except IOError as e:
80+
print 'File read error' # TBD goes to error handler
81+
82+
def testTemplate7 (filename):
83+
try:
84+
with open(filename) as tmp1_file:
85+
t = Templates.Template7 ()
86+
t.HandleRequest (tmp1_file.read())
87+
#print json.dumps(tmp1_file, indent=2)
88+
except IOError as e:
89+
print 'File read error' # TBD goes to error handler
90+
91+
def testTemplate8 (filename):
92+
try:
93+
with open(filename) as tmp1_file:
94+
t = Templates.Template8 ()
95+
t.HandleRequest (tmp1_file.read())
96+
#print json.dumps(tmp1_file, indent=2)
97+
except IOError as e:
98+
print 'File read error' # TBD goes to error handler
99+
100+
101+
def testApplicationList(filename):
102+
try:
103+
with open(filename) as tmp1_file:
104+
t = Templates.SendApplicationInformation()
105+
t.HandleRequest (tmp1_file.read())
106+
#print json.dumps(tmp1_file, indent=2)
107+
except IOError as e:
108+
print 'File read error' # TBD goes to error handler
109+
110+
def testNowExecuting(filename):
111+
try:
112+
with open(filename) as tmp1_file:
113+
t = Templates.RequestNowExecutingInfomation()
114+
t.HandleRequest(tmp1_file.read())
115+
except IOError as e:
116+
print 'File read error nowExecuting.json'
117+
118+
def testRequestAudioFocus(filename):
119+
try:
120+
with open(filename) as tmp1_file:
121+
t = Templates.RequestAudioFocusInformation()
122+
t.HandleRequest(tmp1_file.read())
123+
except IOError as e:
124+
print 'File read error requestAudioFocus.json'
125+
126+
def testSetLocation(filename):
127+
try:
128+
with open(filename) as tmp1_file:
129+
t = Templates.RequestSetLocationInformation()
130+
t.HandleRequest(tmp1_file.read())
131+
except IOError as e:
132+
print 'File read error setlocation.json'
133+
134+
def testPhoneIsAvailable(filename):
135+
try:
136+
with open(filename) as tmp1_file:
137+
t = Templates.RequestSetPhoneAvailabilityInformation()
138+
t.HandleRequest(tmp1_file.read())
139+
except IOError as e:
140+
print 'File read error setPhoneAvailability.json'
141+
142+
def testGoToKeyboard():
143+
t = Templates.RequestRequestGoToKeyboard()
144+
t.HandleRequest()
145+
146+
def startMIPApp ():
147+
dictionary = dict()
148+
dict['appType'] = 1
149+
dict['appName'] = 'Pandora'
150+
# Create event broker with path '/hap/api/1.0/StartApplication'
151+
# and json code json.dumps(dict)
152+
153+
154+
155+
# Removed Native Platform Testing for TestHarness for template testers. Creating separate
156+
# Native Platform Test Harness.
157+
158+
159+
def starttest(testfilepath):
160+
161+
msglogger.logMessage(logger.DEBUG, 'starttest', 'start')
162+
163+
164+
#print 'Make a connection'
165+
#MakeAConnection()
166+
#time.sleep(5)
167+
#print 'Done with connection'
168+
169+
# print 'test NowExecuting'
170+
# testNowExecuting(testfilepath + 'nowExecuting.json')
171+
# print 'test RequestAudioFocus'
172+
# testRequestAudioFocus(testfilepath + 'requestAudioFocus.json')
173+
# print 'test setLocation'
174+
# testSetLocation(testfilepath + 'setlocation.json')
175+
# print 'test PhoneIsAvailable'
176+
# testPhoneIsAvailable(testfilepath + 'setPhoneAvailability.json')
177+
# print 'test GoToKeyboard'
178+
# testGoToKeyboard()
179+
# time.sleep(2)
180+
181+
182+
testTemplate1( testfilepath + 'template1A.json' )
183+
print 'testTemplate1A done.'
184+
time.sleep(2)
185+
186+
# testTemplate1( testfilepath + 'template1A2.json' )
187+
# print 'testTemplate1A2 done.'
188+
# time.sleep (3)
189+
190+
# testTemplate1( testfilepath + 'template1A3.json' )
191+
# print 'testTemplate1A3 done.'
192+
# time.sleep(2)
193+
194+
# testTemplate1( testfilepath + 'template1B.json' )
195+
# print 'testTemplate1B done.'
196+
# time.sleep(2)
197+
198+
# testTemplate2(testfilepath + 'template2A.json')
199+
# print 'testTemplate2A done.'
200+
# time.sleep(2)
201+
202+
# testTemplate2(testfilepath + 'template2B.json')
203+
# print 'testTemplate2B done.'
204+
# time.sleep(2)
205+
206+
# testTemplate3(testfilepath + 'template3A.json')
207+
# print 'testTemplate3A done.'
208+
# time.sleep(2)
209+
210+
# testTemplate3(testfilepath + 'template3B.json')
211+
# print 'testTemplate3B done.'
212+
# time.sleep(2)
213+
214+
# testTemplate4(testfilepath + 'template4A.json')
215+
# print 'testTemplate4A done.'
216+
# time.sleep(2)
217+
218+
# testTemplate4(testfilepath + 'template4B.json')
219+
# print 'testTemplate4B done.'
220+
# time.sleep(2)
221+
222+
# testTemplate5(testfilepath + 'template5.json')
223+
# print 'testTemplate5 done.'
224+
# time.sleep(2)
225+
226+
# testTemplate6(testfilepath + 'template6.json')
227+
# print 'testTemplate6 done.'
228+
# time.sleep(2)
229+
230+
# testTemplate7(testfilepath + 'template7.json')
231+
# print 'testTemplate7 done.'
232+
# time.sleep(2)
233+
234+
# testTemplate8(testfilepath + 'template8A.json')
235+
# print 'testTemplate8A done.'
236+
# time.sleep(2)
237+
238+
# testTemplate8(testfilepath + 'template8B.json')
239+
# print 'testTemplate8B done.'
240+
# time.sleep(2)
241+
242+
# testApplicationList(testfilepath + 'applications.json')
243+
244+
#uncomment following to run an infinite loop to test incoming messages
245+
# otherwise execution will end at the end of this script.
246+
while (True):
247+
time.sleep(1)
248+
249+
250+
print 'Okay we\'re done.'
251+
HupInterface.stopHupInterface()
252+
253+
print 'call exit'
254+
exit()
255+
256+
257+
'''
258+
Run tests as needed. Modify json files in testfiles to get different behaviors on tempaltes.
259+
'''
260+
if __name__ == "__main__":
261+
HupInterface.startHupInterface()
262+
starttest('testfiles/')
111 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6.01 KB
10.8 KB
9.38 KB

0 commit comments

Comments
 (0)