r2 - 19 Jul 2007 - 06:24:01 - MimiYinYou are here: OSAF >  Journal Web  >  QualityAssuranceTeam > AdamChristianNotes > AdamChristianScoobyTestingCode

Scooby Testing Code and Documenatation

Ultimately the goal is to integrate the following functionality into the HTTPTest object to extend its functionality to
handle Scooby testing and Cosmo within the one object.

The following code is all available in the QA-Sandbox in the scoobyTests directory.

scoobyRequest.py

----------------

import httplib

class scoobyRequest:

#Initiate base parameters
def __init__(self, host, port, method, path):
self.host = host
self.port = port
self.path = path
self.method = method
self.httpobj = httplib.HTTP(self.host, self.port)
self.httpobj.putrequest(self.method, self.path)
#In order to run multiple tests with the same instance
self.lastContentLength = ''

#Create http request object with passed params
def addHeaders(self, headerList):
for set in headerList:
self.httpobj.putheader(set[0], set[1])

#Sends the request to the server
def runRequest(self, paramString):
self.httpobj.putheader('Content-length', '%d' % len(paramString))
self.httpobj.endheaders()
self.httpobj.send(paramString)
self.reply = self.httpobj.getreply()

#Parses the response and gets the set jsessionID

def getJsessionID(self):
mystring = str(self.reply[2])
array = mystring.split('\n')
array = array[1].split(':')
array = array[1].split('=')
array = array[1].split(';')
array = array[0]
return array
#Allows you to do specified output, all prints the message aswell, this is preferred to automatic output built into runRequest
def printSummary(self, all=''):
if all == "all":
print "Code: %s Status: %s \nMessage: %s" % (self.reply[0], self.reply[1], self.reply[2])
else:
print "Code: %s Status: %s" % (self.reply[0], self.reply[1])

Running scooby test procedures: objectScoobyTest.py

---------------------------

import scoobyRequest as scoobyRequest

if name == "__main__":

import sys
host = '192.168.103.148' #Set the cosmo server IP
port = '8080' #Set the port
path = '/scooby/' #directory used to access scooby
#the default user, this can obviously be tailored to the account you would like to use
username = 'test2'
password = 'test2'

#When there is a newly created user (which would be done using HTTPTest, talking to cosmo) you must create the scooby calendar.

#Initiate the scooby session
#Get index, returns 302 Moved Temporarily

getScooby = scoobyRequest.scoobyRequest(host, port, 'GET', path)
getScooby.addHeaders([('Accept','*/*'),('Referrer','http://%s:%s/' % (host, port))])
getScooby.runRequest('')
getScooby.getJsessionID() #This parses the jsessionID returned with the set-cookie header in the response from this get
getScooby.printSummary()

#Authenticate your user
#Post j_acegi_security_check, returns 302 moved temporarily

postSecurtyCheck = scoobyRequest.scoobyRequest(host, port, 'POST', '%sj_acegi_security_check' % (path))
postSecurtyCheck.addHeaders([('Cookie', 'JSESSIONID=%s; username=%s' % (getScooby.getJsessionID(), username)),('Accept','*/*'),('Content-type', 'application/x-www-form-urlencoded')])
postSecurtyCheck.runRequest('j_username=%s&j_password=%s' % (username,password))
postSecurtyCheck.printSummary()

#The following is the JSON-RPC call listing the available scooby methods
#This currently returns something like:
#{"result":["scoobyService.saveEvent","scoobyService.createCalendar","scoobyService.moveEvent","scoobyService.getTestString","scoobyService.getEvent","scoobyService.setPreference","scoobyService.getPreference","scoobyService.removeEvent","scoobyService.removeCalendar","scoobyService.getCalendars","scoobyService.getVersion","scoobyService.getEvents"],"id":1}
# A call to any of these can be constructed using the shown post method used in the next few examples

#Post listmethods to json-rpc, returns 200

postListMethods = scoobyRequest.scoobyRequest(host, port, 'POST', '%sJSON-RPC' % (path))
postListMethods.addHeaders([('Cookie', 'JSESSIONID=%s; username=%s' % (getScooby.getJsessionID(), username)),('Accept','*/*'),('Content-type', 'text/plain')])
postListMethods.runRequest('{"id": 1, "method": "system.listMethods", "params": []}')
postListMethods.printSummary()

#Post getCalendars to json-rpc, returns 200, cookie still needs timestamp

postGetCalendars = scoobyRequest.scoobyRequest(host, port, 'POST', '%sJSON-RPC' % (path))
postGetCalendars.addHeaders([('Cookie', 'JSESSIONID=%s; username=%s' % (getScooby.getJsessionID(), username)),('Accept','*/*'),('Content-type', 'text/plain')])
postGetCalendars.runRequest('{"id": 2, "method": "scoobyService.getCalendars", "params": []}')
#Post createCalendars to json-rpc, returns 200
postCreateCalendars = scoobyRequest.scoobyRequest(host, port, 'POST', '%sJSON-RPC' % (path))
postCreateCalendars.addHeaders([('Cookie', 'JSESSIONID=%s; username=%s' % (getScooby.getJsessionID(), username)),('Accept','*/*'),('Content-type', 'text/plain')])
postCreateCalendars.runRequest('{"id": 1, "method": "scoobyService.createCalendar", "params": ["Scooby", "Scooby"]}')
postCreateCalendars.printSummary()

#Post createEvent to json-rpc, returns 200

postCreateEvent = scoobyRequest.scoobyRequest(host, port, 'POST', '%sJSON-RPC' % (path))
postCreateEvent.addHeaders([('Cookie', 'JSESSIONID=%s; username=%s' % (getScooby.getJsessionID(), username)),('Accept','*/*'),('Content-type', 'text/plain')])
postCreateEvent.runRequest('{"id": 2, "method": "scoobyService.saveEvent", "params": ["Scooby", {"id": null, "title": "Welcome to Scooby!", "description": "Welcome to Scooby!", "start": {"year": 2006, "month": 4, "date": 31, "hours": "9", "minutes": "00", "seconds": 0, "timezone": null, "utc": false}, "end": {"year": 2006, "month": 4, "date": 31, "hours": 10, "minutes": 0, "seconds": 0, "timezone": null, "utc": false}, "allDay": false, "pointInTime": false, "anyTime": false, "recurrenceRule": null, "status": null, "masterEvent": false, "instance": false, "javaClass": "org.osaf.scooby.model.Event"}]}')
postCreateEvent.printSummary()

#To view the headers executed for a scoobyRequest:
#print scoobyRequest.httpobj.headers

#To remove an event also returns 200 OK, obviously the second parameter will be the ID of the event you wish the remove.

postRemoveEvent = scoobyRequest.scoobyRequest(host, port, 'POST', '%sJSON-RPC' % (path))
postRemoveEvent.addHeaders([('Cookie', 'JSESSIONID=%s; username=%s' % (getScooby.getJsessionID(), username)),('Accept','*/*'),('Content-type', 'text/plain')])
postRemoveEvent.runRequest('{"id": 7, "method": "scoobyService.removeEvent", "params": ["Scooby", "1c18b4ae-5e85-42f4-b74a-b7b5c0c2ac30"]}')
postRemoveEvent.printSummary()

-------------------

Output: The response code is automatically printed after execution and stored in the scoobyRequest object.
This can be accessed in scoobyObject.reply after the runRequest is called.
An instance of the message response is stored in the tuple and can be accessed with the following:

print scoobyRequest.reply[2]

-----------------

Example:
The following output is from a test that gets the cookie, authenticates, calls listmethods,
gets the calendars, creates an event, then removes that event.

AdamsMB17:~/Documents/projects/qa-sandbox/scoobyTests adam$ python objectScoobyTest.py
Default Parameters- Host: 192.168.103.148, Port: 8080, Path: /scooby/

Code: 302 Status: Moved Temporarily
Code: 302 Status: Moved Temporarily
Code: 200 Status: OK
Code: 200 Status: OK
Code: 200 Status: OK
Code: 200 Status: OK
AdamsMB17:~/Documents/projects/qa-sandbox/scoobyTests adam$

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.