Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 import roslib; roslib.load_manifest('program_queue')
00010 import rospy
00011
00012 from program_queue.srv import *
00013 from program_queue.msg import *
00014
00015 def client(name, t):
00016 rospy.wait_for_service(name)
00017 return rospy.ServiceProxy(name, t)
00018
00019 if __name__ == '__main__':
00020 rospy.init_node('test_queue')
00021
00022
00023 user = client('create_user', CreateUser)('testuser', 'testpw')
00024 token = user.token
00025
00026 if token == 0:
00027 print "Failed to create user"
00028
00029
00030 program = client('create_program', CreateProgram)(token)
00031 program_id = program.id
00032 print "Program ID: %d"%program_id
00033
00034
00035 client('update_program', UpdateProgram)(token, Program(ProgramInfo(
00036 program_id, 'testprogram', ProgramInfo.PYTHON, 'testuser'), 'print "Hello World"\n'))
00037
00038
00039 client('logout', Logout)(token)
00040
00041
00042 user = client('login', Login)('testuser', 'testpw')
00043 token = user.token
00044
00045 if token == 0:
00046 print "Failed to log in"
00047
00048 if user.is_admin:
00049 print "Test user is admin and shouldn't be"
00050
00051
00052 program = client('get_program', GetProgram)(program_id)
00053 if program.program.info.id != program_id:
00054 print "Failed to retrieve program"
00055
00056 if program.program.info.name != 'testprogram':
00057 print "Failed to set program name"
00058
00059 if program.program.info.type != ProgramInfo.PYTHON:
00060 print "Failed to set program type"
00061
00062 if program.program.code != 'print "Hello World"\n':
00063 print "Failed to set program code"
00064
00065
00066 q = client('queue_program', QueueProgram)(token, program_id)
00067 print "Queue position %d"%q.queue_position
00068 queue_position = q.queue_position
00069
00070
00071 q = client('get_queue', GetQueue)()
00072 if not program_id in [ p.id for p in q.programs ]:
00073 print "Failed to put program into queue"
00074
00075
00076 if q.programs[queue_position].id != program_id:
00077 print "Queue position does not match returned queue"
00078
00079
00080
00081 client('dequeue_program', DequeueProgram)(token, program_id)
00082
00083
00084
00085 programs = client('get_my_programs', GetMyPrograms)(token)
00086
00087
00088 if len(programs.programs) != 1:
00089 print "GetMyPrograms expected one program; got %d"%len(programs.programs)
00090
00091
00092
00093 admin = client('login', Login)('admin', 'admin')
00094 if admin.token == 0:
00095 print "Failed to log in as admin"
00096
00097 if not admin.is_admin:
00098 print "Admin user should be an admin but isn't"
00099
00100
00101 client('run_program', RunProgram)(admin.token, program_id)
00102
00103
00104 output = client('get_output', GetOutput)(token, program_id, 0)
00105
00106 if len(output.output) != 1:
00107 print "Expected 1 output; got %d"%len(output.output)
00108 else:
00109 print "Run date: " + str(output.output[0].header.stamp.to_sec())
00110 print "Output: %s"%output.output[0].output
00111
00112
00113
00114 programs = client('get_programs', GetPrograms)()
00115
00116 if len(programs.programs) != 1:
00117 print "Expected 1 program, got %d"%len(programs.programs)
00118
00119
00120
00121
00122
00123