Created
January 12, 2017 19:40
-
-
Save 3mb3dw0rk5/1f8868dceac8e40226bc360abac7c9ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from zeep import Client | |
| from zeep.plugins import HistoryPlugin | |
| import re | |
| from lxml.etree import Element | |
| from lxml import etree | |
| class Project(object): | |
| def __init__(self, polarion, project_id): | |
| self.polarion = polarion | |
| self.project_id = project_id | |
| def __query_workitems(self, type): | |
| return self.polarion.tracker.service.queryWorkItems('project.id:%s AND type:%s' % (self.project_id, type),'id',['id','title','description', 'linkedWorkItems']) | |
| @property | |
| def testcases(self): | |
| return self.__query_workitems('testcase') | |
| @property | |
| def modules(self): | |
| return self.polarion.tracker.service.getModules(self.project_id, '') | |
| @property | |
| def solutionimplementations(self): | |
| return self.__query_workitems('solutionimplementation') | |
| def document_workitems(self, document_folder, document_name): | |
| #uri = 'subterra:data-service:objects:/default/PUCC${Module}{moduleFolder}16 Solution Planning and Implementation#1 SSS Software Module Specification Firmware PUCC' | |
| uri = 'subterra:data-service:objects:/default/%s${Module}{moduleFolder}%s#%s' % (self.project_id, document_folder, document_name) | |
| return self.polarion.tracker.service.getModuleWorkItems(uri, None, True, ['id','title','type','description', 'linkedWorkItems']) | |
| class Polarion(object): | |
| def __init__(self, url, username, password): | |
| self.url = url | |
| self.username = username | |
| self.password = password | |
| self.history = HistoryPlugin() | |
| self.session = Client(wsdl=self.url + '/ws/services/SessionWebService?wsdl', plugins=[self.history]) | |
| self.session.service.logIn(self.username, self.password) | |
| tree = self.history.last_received['envelope'].getroottree() | |
| self.sessionHeaderElement = tree.find('.//{http://ws.polarion.com/session}sessionID') | |
| self.__tracker = Client(wsdl=self.url + '/ws/services/TrackerWebService?wsdl', plugins=[self.history]) | |
| self.__tracker.set_default_soapheaders([self.sessionHeaderElement]) | |
| self.__tracker.wsdl.messages['{http://ws.polarion.com/TrackerWebService}getModuleWorkItemsRequest'].parts['parameters'].element.type._element[1].nillable = True | |
| self.__tracker.service.getModuleWorkItemUris._proxy._binding.get('getModuleWorkItemUris').input.body.type._element[1].nillable = True | |
| self.__tracker.service.getModuleWorkItemUris._proxy._binding.get('getModuleWorkItems').input.body.type._element[1].nillable = True | |
| @property | |
| def tracker(self): | |
| return self.__tracker | |
| def get_project(self, project_id): | |
| #TODO: check if project exists | |
| return Project(self, project_id) | |
| if __name__ == "__main__": | |
| polarion = Polarion('http://link.to/polarion', 'user', 'pw') | |
| project = polarion.get_project('PUCC') | |
| #testcase = project.testcases[50] | |
| #print(str(testcase)) | |
| #print(type(testcase)) | |
| #print(dir(testcase)) | |
| try: | |
| print(project.document_workitems('16 Solution Planning and Implementation', '1 SSS Software Module Specification Firmware PUCC')) | |
| except Exception as e: | |
| print(e) | |
| print(polarion.tracker.wsdl.messages['{http://ws.polarion.com/TrackerWebService}getModuleWorkItemsRequest'].parts['parameters'].element.type._element[1].nillable) | |
| print(etree.tostring(polarion.history.last_sent['envelope'].getroottree(), pretty_print=True).decode('ascii')) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a basic script describing how to access the Polarion WebService SDK. It uses zeep, a well maintained soap client for python.
The script allows a user-access with password and also demonstrate how to change the web-service description if a bug prevents you from using a service. In this example an actual bug in the
getModuleWorkItemsandgetModuleWorkItemUrisis fixed by changing the attributenillableof the second service paramter to True.