Seapine Labs

TestTrack SOAP SDK Tutorial - Python

From Seapine Labs

Jump to: navigation, search

This 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.

Contents

[edit] Getting Started

You 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.

  • http://yourserver/cgi-bin/ttsoapcgi.exe - CGI Executable that all TestTrack SDK commands go through. It's not important to understand CGI, just know where this file was installed.
  • http://server/ttsoapcgi.wsdl - The WSDL file that defines the language you use when talking to the CGI executable. Anyone that uses the TestTrack SDK uses this wsdl, there is no need to generate a specific wsdl for your installation. Everything is genericized so that, no matter how you customize TestTrack, this one wsdl file will handle it.

Once you've installed the TestTrack SDK, you're pretty much ready to roll.

[edit] suds

Recent versions of the suds library work well. Examples in this tutorial use suds 0.3.9 under Python 2.6.5.


[edit] Create a Connection

The 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:

  • You cannot logon via the TestTrack SDK if you are already logged in via one of the TestTrack clients. It's best to use a dedicated account for your SDK scripting, this ensures you'll always be able to login.
  • If you do not explicitly call DatabaseLogoff, your user will remain logged in until the TestTrack SDK times out. This could present a problem if you try to re-run the script inside that timeframe. It's important to use try/catch exception handling to ensure that an exception in your program doesn't skip logging you off.
  • The CProjectDataOption array governs what licenses you use and functionality you have access to. For example, you can't use a TestTrack TCM license if you don't specify one in the CProjectDataOption array.

[edit] Query Objects

There 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] getObject

Calling 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] getRecordListForTable

If 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:

  • TableColumn elements use the field's Short Label value.
  • You can use getRecordListForTable to retrieve pretty much anything you can view in a list view column within the GUI clients.

[edit] Querying the Requirement Document

A 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 Object

Adding 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:

  • When setting drop-down list values, you must match exactly (case-sensitive) with an existing value in the drop-down list.
  • When setting date/time values, you must also set the set{FieldName} value to true.

[edit] Update Object

Before 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:

  • You cannot edit an object that is being edited by another user. For example, if someone else had defect #11 open for edit in their client, the example above would fail.
  • If you successfully lock a defect for edit, that lock remains until you save it, cancel the save or logout. You should use try/catch exception handling to ensure that you release the lock as soon as possible.

[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 State

TestTrack 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.


The following example adds a Fix event, which in turn, sets the state to Fixed. Please note, that in this example, the Fix event only has one resulting state, and therefore the Resulting State field does not need to be set.

# 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/Customer

At 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.


In the examples below, John Bark is a local user in our TestTrack project, Sarah Kaiser is a global user in the Seapine License Server.

# 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

  • MS SOAP Toolkit - This is a small app from Microsoft that helps you trace SOAP requests. Start a formatted trace, point your SOAP client toward the tools listening port, then have the tool redirect to the real web server port. With that configured, you can intercept the response/request loop and see exactly what is being communicated to the TestTrack Server.
  • soap UI - A free tool that lets you send raw SOAP envelopes. We sometimes use this internally to debug issues, since you can control the data being being sent.













Issue Management Software | Source Code Control Software | Test Case Management | Requirements Management Software