Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 262 additions & 0 deletions Students/Dave Fugelso/Project/Alpine/TestHarness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
#
# TestHarness.py
# Copyright (c) 2014 Airbiquity
#
# The tester emulates the body of requests coming over the network interface
#

import sys
import threading
import json
import time
import Templates
import FileCache
import logger

# Remove this import if non interface to Alpine
import HupInterface

msglogger = logger.Logger()


'''
The following are test for the Template interface
'''

def testTemplate1 (filename):
#print 'template1 file: ' + filename
#msglogger.logMessage(logger.DEBUG, 'testTemplate1', filename)
try:
with open(filename) as tmp1_file:
t = Templates.Template1 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate2 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template2 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate3 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template3 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate4 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template4 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate5 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template5 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate6 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template6 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate7 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template7 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testTemplate8 (filename):
try:
with open(filename) as tmp1_file:
t = Templates.Template8 ()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler


def testApplicationList(filename):
try:
with open(filename) as tmp1_file:
t = Templates.SendApplicationInformation()
t.HandleRequest (tmp1_file.read())
#print json.dumps(tmp1_file, indent=2)
except IOError as e:
print 'File read error' # TBD goes to error handler

def testNowExecuting(filename):
try:
with open(filename) as tmp1_file:
t = Templates.RequestNowExecutingInfomation()
t.HandleRequest(tmp1_file.read())
except IOError as e:
print 'File read error nowExecuting.json'

def testRequestAudioFocus(filename):
try:
with open(filename) as tmp1_file:
t = Templates.RequestAudioFocusInformation()
t.HandleRequest(tmp1_file.read())
except IOError as e:
print 'File read error requestAudioFocus.json'

def testSetLocation(filename):
try:
with open(filename) as tmp1_file:
t = Templates.RequestSetLocationInformation()
t.HandleRequest(tmp1_file.read())
except IOError as e:
print 'File read error setlocation.json'

def testPhoneIsAvailable(filename):
try:
with open(filename) as tmp1_file:
t = Templates.RequestSetPhoneAvailabilityInformation()
t.HandleRequest(tmp1_file.read())
except IOError as e:
print 'File read error setPhoneAvailability.json'

def testGoToKeyboard():
t = Templates.RequestRequestGoToKeyboard()
t.HandleRequest()

def startMIPApp ():
dictionary = dict()
dict['appType'] = 1
dict['appName'] = 'Pandora'
# Create event broker with path '/hap/api/1.0/StartApplication'
# and json code json.dumps(dict)



# Removed Native Platform Testing for TestHarness for template testers. Creating separate
# Native Platform Test Harness.


def starttest(testfilepath):

msglogger.logMessage(logger.DEBUG, 'starttest', 'start')


#print 'Make a connection'
#MakeAConnection()
#time.sleep(5)
#print 'Done with connection'

# print 'test NowExecuting'
# testNowExecuting(testfilepath + 'nowExecuting.json')
# print 'test RequestAudioFocus'
# testRequestAudioFocus(testfilepath + 'requestAudioFocus.json')
# print 'test setLocation'
# testSetLocation(testfilepath + 'setlocation.json')
# print 'test PhoneIsAvailable'
# testPhoneIsAvailable(testfilepath + 'setPhoneAvailability.json')
# print 'test GoToKeyboard'
# testGoToKeyboard()
# time.sleep(2)


testTemplate1( testfilepath + 'template1A.json' )
print 'testTemplate1A done.'
time.sleep(2)

# testTemplate1( testfilepath + 'template1A2.json' )
# print 'testTemplate1A2 done.'
# time.sleep (3)

# testTemplate1( testfilepath + 'template1A3.json' )
# print 'testTemplate1A3 done.'
# time.sleep(2)

# testTemplate1( testfilepath + 'template1B.json' )
# print 'testTemplate1B done.'
# time.sleep(2)

# testTemplate2(testfilepath + 'template2A.json')
# print 'testTemplate2A done.'
# time.sleep(2)

# testTemplate2(testfilepath + 'template2B.json')
# print 'testTemplate2B done.'
# time.sleep(2)

# testTemplate3(testfilepath + 'template3A.json')
# print 'testTemplate3A done.'
# time.sleep(2)

# testTemplate3(testfilepath + 'template3B.json')
# print 'testTemplate3B done.'
# time.sleep(2)

# testTemplate4(testfilepath + 'template4A.json')
# print 'testTemplate4A done.'
# time.sleep(2)

# testTemplate4(testfilepath + 'template4B.json')
# print 'testTemplate4B done.'
# time.sleep(2)

# testTemplate5(testfilepath + 'template5.json')
# print 'testTemplate5 done.'
# time.sleep(2)

# testTemplate6(testfilepath + 'template6.json')
# print 'testTemplate6 done.'
# time.sleep(2)

# testTemplate7(testfilepath + 'template7.json')
# print 'testTemplate7 done.'
# time.sleep(2)

# testTemplate8(testfilepath + 'template8A.json')
# print 'testTemplate8A done.'
# time.sleep(2)

# testTemplate8(testfilepath + 'template8B.json')
# print 'testTemplate8B done.'
# time.sleep(2)

# testApplicationList(testfilepath + 'applications.json')

#uncomment following to run an infinite loop to test incoming messages
# otherwise execution will end at the end of this script.
while (True):
time.sleep(1)


print 'Okay we\'re done.'
HupInterface.stopHupInterface()

print 'call exit'
exit()


'''
Run tests as needed. Modify json files in testfiles to get different behaviors on tempaltes.
'''
if __name__ == "__main__":
HupInterface.startHupInterface()
starttest('testfiles/')
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Students/Dave Fugelso/Project/Alpine/testfiles/HUinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"headUnitSerialNumber": "<head unit serial number",
"vehicleMake": "<make>",
"vehicleModel": "<model>",
"distance" : <"mi" | "km">,
"time": <"12" | "24">,
"date": <"MMDDYY" | "DDMMYY">,
"Temperature": <"C" | "F">
"versioninfo": [
{
"<Component Name>" : "<component version">,
"<updateable>" : <1 | 0>
}
]
}
50 changes: 50 additions & 0 deletions Students/Dave Fugelso/Project/Alpine/testfiles/HupWrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#////////////////////////////////////////////////////////////////////////////////////////////////////
# Image Request

# This expects the body to contain the appId and a path of a locally stored image file
class AlpineFetchImageResponseHandler(ResponseHandler):
def response(self, responseCode, headers, mimeType, body):
print 'have image for : ' + headers
try:
d = json.loads(body)
if (d.has_key('path') and d.has_key('appId'):
#TBD: Check if appId is still current appId
SendImage (d['path'], d['appId'])
else:
print 'Bad format for SendImage'
except:
print 'bad json into response handler for image request'


def imageRequest (d):
eb.request('GET','/RequestImage/', None, json.dumps(d),'application/json',[], AlpineFetchImageResponseHandler())



# This will be replaced by Configurator!
def RegisterHandlers (eb):
# Except these. These are not MIP callback handlers
HupInterface.requestCallback('RequestImage', imageRequest)
imageHandler =


#////////////////////////////////////////////////////////////////////////////////////////////////////
# Register callbacks for Alpine initiated request
def setup():
global srv, eb, myHandler


#handler1 = AlpineRequestHandler('HeadUnitID', RequestHeadUnitID)
#handler3 = AlpineRequestHandler('SetTemplate1', template1)
myHandler = MyResponseHandler()


# HttpGatewayRequestHandler is currently stubbed out and will be fixed by Jack Friday morning.
handler2 = HttpGatewayRequestHandler(btMCSSF, host=address_to_handset, port=port_of_handset_server)

# Template 1 handler

eb = EventBroker()

RegisterHandlers (eb)
Loading