Cosmo/Scooby Testing Tools Overview
Accessing the test framework: Currently all of these tools are contained in the qa-sandbox: svn co svn://svn.osafoundation.org/svn/qa qa-sandbox
runSuite.sh: Invokes python on each of the tests specified within, to send this output to a file use: sh runSuite.sh > output.txt
#Suite for running mutliple tests
#!/bin/bash
echo "---Running Test Suite----"
echo "Running test 1: Calendar Stress Test Recurrence 100"
python TESTRunner.py file=scoobyCalendarStress.py classname=scoobyCalendarStress recurrence=100 debug=0
echo "Running test 2: Multiple Adding and Removing of Events, Recurrence 100"
python TESTRunner.py file=scoobyMultiAddRemEventsTest.py classname=scoobyMultiAddRemEventsTest recurrence=100 debug=0
echo "Running test 3: Multiple Events, Recurrence 100"
python TESTRunner.py file=scoobyMultipleEventsTest.py classname=scoobyMultipleEventsTest recurrence=100 debug=0
echo "Running test 3: Multiple events and Status Changes, Recurrence 100"
python TESTRunner.py file=scoobyStatusTest.py classname=scoobyStatusTest recurrence=100 debug=0
echo "---Ended Test Suite---"
exit
TESTRunner.py: Used to call tests dynamically by passing test parameters as arguments.
# This is the test runner script, its used to run cosmo and scooby tests using cmp and json-rpc
#
# Example:
# adam$ python TESTRunner.py file=scoobyCalendarStress.py classname=scoobyCalendarStress recurrence=10 debug=0
#
# Available Parameters:
#
# host - Location of cosmo server with scooby instance, defaults localhost
# port - The port its running, defaults to 8080
# path - This is the url path to either /cosmo or /scooby. Defaults to /scooby
# recurrence - This is how many times its going to execute. (add 100 events, or calendars etc. depending on the test.) defaults 0
# debug - this defines the level of output, defauts to 0
# file - The path to the file where the tests is located. (ie /Users/adam/Documents/scoobytests/mytest.py)
# classname - The class in that file you will be instantiating to run the test: scoobyCalendarStress.py
if __name__ == "__main__":
#host, port, path, username, password, debug
#TestFile, class
import sys
#Set the cosmo server, and scooby path
host = 'localhost'
port = '8080'
path = '/scooby'
#Set the target user
#username = 'scoobyTest'
#password = 'scoobyTest'
#Set your debug
debug = 0
recurrence = 0
for arg in sys.argv:
args = arg.split("=")
if args[0] == "host":
host = args[1]
elif args[0] == "port":
port = int(args[1])
elif args[0] == "path":
path = args[1]
elif args[0] == "recurrence":
recurrence = int(args[1])
elif args[0] == "debug":
debug = int(args[1])
# elif args[0] == "username":
# username = args[1]
# elif args[0] == "password":
# password = args[1]
elif args[0] == "file":
file = args[1]
elif args[0] == "classname":
classname = args[1]
#Append py if the tester forgets
if ".py" not in file:
file += '.py'
f = open(file)
classToRun = f.read()
exec (classToRun)
# instantiationString = ("%s=%s(host='%s', port='%s', path='%s')" % (classname, classname, host, port, path))
instantiationString = '%s = %s(host="%s", port=%s, path="%s")' % (classname, classname, host, port, path)
exec (instantiationString)
#set other params
#setUsername = "%s.username = '%s'" % (classname, username)
#exec (setUsername)
#setPassword = "%s.password = '%s'" % (classname, username)
#exec (setPassword)
setDebug = "%s.debug = %i" % (classname, debug)
exec (setDebug)
setRecurrence = "%s.recurrence = %i" % (classname, recurrence)
exec (setRecurrence)
doFullrun = "%s.fullRun()" % (classname)
exec(doFullrun)
BroadSword: This is the test framework, these are extensive so I advise you to check them out and look at them via svn.
scoobyGeneralTest.py: This is an example that uses many of scoobys features via JSON-RPC calls, to demonstrate how they are accessed.
from JSONTest import JSONTest
class generalScoobyTest(JSONTest):
def startRun(self):
self.testStart('Setup Accounts')
self.username = "scoobyGeneralTest"
self.password = "scooby"
cmpheaders = self.headerAdd({'Content-Type' : "text/xml; charset=UTF-8"})
cmpheaders = self.headerAddAuth("root", "cosmo", headers=cmpheaders)
#CMP path
#cmppath = self.pathBuilder('/cmp/user/scoobyMETest')
cmppath = '/cosmo/cmp/user/%s' % (self.username)
#Create testing account
bodycreateaccount = '<?xml version="1.0" encoding="utf-8" ?> <user xmlns="http://osafoundation.org/cosmo/CMP"> <username>%s</username> <password>%s</password> <firstName>scoobyMETest</firstName> <lastName>Test</lastName> <email>scoobyMETest@osafoundation.org</email> </user>' % (self.username, self.password)
#Create account and check status
self.request('PUT', cmppath, body=bodycreateaccount, headers=cmpheaders)
self.checkStatus(201)
self.path = '/scooby'
#We need to acquire the Jsession ID that is provided in the SET-COOKIE header of the response
self.my_headers = {'Accept': '*/*', 'Referrer' : 'http://%s:%s/' % (host, port)}
self.request(method='GET',url=self.pathBuilder('/'), headers = self.my_headers)
self.parseJSID() #Parse and store JSID
self.my_headers = self.headerAdd({'Cookie' : 'JSESSIONID=%s; username=%s' % (self.parseJSID(), self.username)})
self.verifyListInResponse(negative=['error'])
#Authenticate
self.my_headers.update({'Accept': '*/*', 'Content-type' : 'application/x-www-form-urlencoded'})
self.request(method='POST',url=self.pathBuilder('/j_acegi_security_check'), body='j_username=%s&j_password=%s' % (username,password), headers = self.my_headers)
self.verifyListInResponse(negative=['error'])
#JSON-RPC: Get the available system methods
self.my_headers.update({'Accept': '*/*', 'Content-type' : 'text/plain'})
self.request(method='POST', url=self.pathBuilder('/JSON-RPC'), body='{"id": 1, "method": "system.listMethods", "params": []}', headers = self.my_headers)
self.verifyListInResponse(negative=['error'])
#JSON-RPC: Call to getVersion
self.request(method='POST', url=self.pathBuilder('/JSON-RPC'), body='{"id": 2, "method": "scoobyService.getVersion", "params": []}', headers = self.my_headers)
self.verifyListInResponse(negative=['error'])
#JSON-RPC: Call to getEvents
self.request(method='POST', url=self.pathBuilder('/JSON-RPC'), body='{"id": 3, "method": "scoobyService.getEvents", "params": ["Scooby", 1148713200000, 1149490799000]}', headers = self.my_headers)
self.verifyListInResponse(negative=['error'])
#JSON-RPC: Get the calendars
self.request(method='POST', url=self.pathBuilder('/JSON-RPC'), body='{"id": 4, "method": "scoobyService.getCalendars", "params": []}', headers = self.my_headers)
self.verifyListInResponse(negative=['error'])
#JSON-RPC: Create a calendar (for scooby it will be scooby, and will fail if scooby already exists)
self.request(method='POST', url=self.pathBuilder('/JSON-RPC'), body='{"id": 5, "method": "scoobyService.createCalendar", "params": ["Scooby", "Scooby"]}', headers = self.my_headers)
self.verifyListInResponse(negative=['error'])
#JSON-RPC: Create an event
self.request(method='POST', url=self.pathBuilder('/JSON-RPC'), body='{"id": 6, "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"}]}', headers = my_headers)
self.verifyListInResponse(negative=['error'])
Recurring tests are done using the recurringRun(self) method, this is called as many times as recurrence is set where its called by runSuite.sh