|
|
ViewsPersonal toolsTestTrack SOAP SDK Tutorial - PythonFrom Seapine LabsThis article includes everything you ever wanted to know about writing TestTrack SDK applications in Python! Don't like Python? We have tutorials for a variety of languages. Be sure to check out the TestTrack SDK Help pages for more information. Want Seapine to write your SOAP app for you? Email us for more information.
[edit] Getting StartedYou must install the TestTrack SDK as part of your server installation. If you haven't done this, you'll need to run the TestTrack installer for the version you have installed. Once installed, there are 2 files of interest.
Once you've installed the TestTrack SDK, you're pretty much ready to roll. [edit] sudsRecent versions of the suds library work well. Examples in this tutorial use suds 0.3.9 under Python 2.6.5.
[edit] Create a ConnectionThe TestTrack SDK requires authentication before you can retrieve and save data.
server = suds.client.Client("http://myserver/ttsoapcgi.wsdl")
# Fetch a list of projects you have access to.
aproject = server.service.getProjectList(username, password)
# Or, build your own.
project = server.factory.create("CProject")
project.database = server.factory.create("CDatabase")
project.database.name = "MyProject"
project.options = server.factory.create("ArrayOfCProjectDataOption")
project.options.append(server.factory.create("CProjectDataOption"))
project.options.append(server.factory.create("CProjectDataOption"))
project.options.append(server.factory.create("CProjectDataOption"))
project.options[0].name = "TestTrack Pro" # add TTP functionality.
project.options[1].name = "TestTrack TCM" # add TCM functionality.
project.options[2].name = "TestTrack RM" # add RM functionality.
# Login.
cookie = server.service.DatabaseLogon(database_name, username, password)
# ...do some stuff...
# When you're finished, log off.
response = server.service.DatabaseLogoff(cookie)
Things to Know:
[edit] Query ObjectsThere are two ways to retrieve data through the TestTrack SDK. You can explicitly call a getObject method or you can call the getRecordListForTable method. [edit] getObjectCalling the get method on an object is useful when you know exactly which object you need. For performance reasons, this is not recommended when you want to extract data from multiple objects of the same type. # retrieve defect #45, with attachments. defect = server.service.getDefect(cookie, 45, bDownloadAttachments=False) # retrieve test case #312, with attachments. tCase = server.service.getTestCase(cookie, 312, bDownloadAttachments=True) # retrieve requirement #23, with attachments. req = server.service.getRequirement(lSession, 23, bDownloadAttachments=True) # retrieve requirement document #3, with attachments. reqDoc = server.service.getRequirementDocument(lSession, 3, bDownloadAttachments=True) [edit] getRecordListForTableIf you'd rather query multiple objects of the same type, similar to a SELECT statement in SQL, use getRecordListForTable. This method allows you to specify what data you want to retrieve and apply a filter to the results. # number, summary, custom field, product and type astrFields = ["Number", "Summary", "My Custom", "Product", "Type"] # fetch all defects rows = server.service.getRecordListForTable(cookie, "Defect", columnlist=astrFields) When calling getRecordListForTable you must specify both the object type you want to query and a list of fields you want to retrieve. Optionally, you can also specify a filter that you've pre-configured in TestTrack. All of this information can be hard-coded as shown in the previous example, or dynamically passed as shown below. # What object types can I query? adt = server.service.getTableList(cookie) # What field data is available for a given object type? atc = server.service.getColumnsForTable(cookie, tablename) # What filters are available? af = server.service.getFilterList(cookie) Things to Know:
[edit] Querying the Requirement DocumentA Requirement Document is a collection of requirements. If you need a list of the requirements associated with a specific document you can use the getRequirementIDsForDocument() call. # get a list of requirement numbers associated with Requirement Document #4 reqs = server.service.getRequirementIDsForDocument(cookie, 4) # Returns requirement numbers, not record ids. [edit] Create ObjectAdding an object is simply a matter of creating a new instance and calling the addObject method. For example, to create a defect:
# Create the CDefect object.
defect = server.factory.create("CDefect")
#suds doesn't automatically initialize the record id
defect.recordid = 0;
defect.summary = "This is a new defect"
defect.product = "My Product"
defect.priority = "Immediate"
# Add the defect to TestTrack.
lNewNum = server.service.addDefect(cookie, defect)
Things to Know:
[edit] Update ObjectBefore updating an object, you must first lock it for editing by calling editObject. # Open defect #11 for editing. defect = server.service.editDefect(cookie, 11, bDownloadAttachments=True) # Change the Priority. defect.priority = "Immediate" # Save the defect changes server.service.saveDefect(cookie, defect) # Or, you can release the edit lock w/o saving changes. server.service.cancelSaveDefect(cookie, defect.recordid) Things to Know:
[edit] Update Custom Field
# Lock the defect for edit.
defect = server.editDefect(cookie, 1284, bDownloadAttachments=False)
# Find and update the 'My Custom' custom field.
for item in defect.customFieldList:
if item.name == "My Custom":
item.value = "Testing"
# Save changes.
server.service.saveDefect(cookie, defect)
[edit] Update Workflow StateTestTrack calculates state based on event history. This means you can't simply set a value to change state. Instead, you have to apply the necessary events to move the object into the desired state.
# Lock the defect for edit.
defect = server.service.editDefect(cookie, 1284, bDownloadAttachments=False)
# Create the Fix event.
event = server.factory.create("CEvent")
event.name = "Fix"
event.user = username
event.date = datetime.datetime.now()
event.fieldlist = server.factory.create("ArrayOfCField")
event.fieldlist[0] = server.factory.create("CDropdownField")
event.fieldlist[0].name = "Resolution"
event.fieldlist[0].value = "Code Change"
# Add the event to defect's eventlist
length = len(defect.eventlist)
defect.eventlist[length] = event
# Save our changes.
server.service.saveDefect(cookie, defect)
[edit] Add File Attachment
# Lock the defect for edit.
defect = server.service.editDefect(cookie, 1284, bDownloadAttachments=False)
# Create the file attachment.
filename = "C:\\readme.txt"
f = open(filename, "rb")
data = f.read().encode("base64")
f.close()
attachment = server.factory.create("CFileAttachment")
#use the setattr command since we have a - in the name
setattr(attachment,'m-strFileName', os.path.basename(filename))
setattr(attachment,'m-pFileData', data)
# Add the attachment to the defect
afile = defect.reportedbylist[0].attachmentlist
length = len(afile)
afile[length] = attachment
# Save changes
server.service.saveDefect(cookie, defect)
[edit] Promote User/CustomerAt times you may need to turn a local user or customer into a global account. There are essentially two ways to do this. You can promote them as a new global user, or you can link them to an existing global user.
# Promte as new global user iResult = server.service.promoteUser(cookie, "John Bark", None, "jbark") # check that iResult == 0
# Promte to existing global user iResult = server.service.promoteUser(cookie, "John Bark", "Sarah Kaiser", None) #check that iResult == 0 Note: The name parameters are searched based on your user settings in TT. So if you have names setup to display as 'lname, fname', then that's the format you should use when passing them to the call. If you passed them exactly as shown in the examples above (fname lname), they won't be found and the promote will fail.
[edit] Troubleshooting
|
|


