jesper-raemaekers / python-polarion

A Python package to access the Polarion WSDL API.
MIT License
54 stars 34 forks source link

How to edit/update workItems Rich text customfields? #72

Closed armanoj closed 1 year ago

armanoj commented 2 years ago

Am getting the following error while updating rich text customfields in work items. Exception has occurred: ValidationError (note: full exception trace is shown but execution is paused at: ) Missing element content (updateWorkItem.content.customFields.Custom.value.content)

I have copied my code below:

Imports

from msilib.schema import CustomAction from urllib.parse import urljoin from polarion import polarion import openpyxl from openpyxl.styles.fills import PatternFill import os

class ConnectPolarion:

def __init__(self, alm_link, username, passwd, project_name):
    self.client = polarion.Polarion(alm_link, username, passwd, skip_cert_verification=True)
    self.my_project_name = project_name
    self.my_project = self.client.getProject(self.my_project_name)
    self.all_workitems_data = {}

def update_svcp_cases(self):
    self.spaces = self.my_project.getDocumentSpaces()
    self.document = self.my_project.getDocument(f'Preliminary Collaboration/Test_SVCP')
    self.all_workitems = self.document.getWorkitems()
    #Process the work item
    self.workitem = self.my_project.getWorkitem('VMM-20804')
    print(self.workitem)
    print(self.workitem._polarion_item)
    cond_cont = self.client.TextType
    val = cond_cont(type='text/html', content='This is my string', contentLossy=False)
    self.workitem.setCustomField('conditions', val)

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

Program Start

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

if name == "main": link_url = 'https://alm.collins.com/polarion' my_username = 'xxx' my_password = 'yyy' my_project = 'VMM_H'

myConnectPolarion = ConnectPolarion(link_url, my_username, my_password, my_project)
myConnectPolarion.update_svcp_cases()
jesper-raemaekers commented 2 years ago

Hi @armanoj ,

I have taken your code (and simplified it a little) and this seems to work just fine on this side. what Python version and polarion package version are you using?

For reference, this is was i ended up with code wise:

from polarion import polarion

class ConnectPolarion:

    def __init__(self, alm_link, username, passwd, project_name):
        self.client = polarion.Polarion(alm_link, username, passwd, skip_cert_verification=True)
        self.my_project_name = project_name
        self.my_project = self.client.getProject(self.my_project_name)
        self.all_workitems_data = {}

    def update_svcp_cases(self):
        self.workitem = self.my_project.getWorkitem('PYTH-513')
        print(self.workitem)
        print(self.workitem._polarion_item)
        cond_cont = self.client.TextType

        val = cond_cont(type='text/html', content='This is my string', contentLossy=False)
        self.workitem.setCustomField('conditions', val)

myConnectPolarion = ConnectPolarion('http://localhost/polarion', '', '', '')
myConnectPolarion.update_svcp_cases()
armanoj commented 2 years ago

Python Version: 3.8.5 Polarion Version: polarion in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (0.4.0) lxml in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from polarion) (4.6.1) texttable in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from polarion) (1.6.4) zeep in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from polarion) (4.1.0) attrs>=17.2.0 in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from zeep->polarion) (20.3.0) requests-file>=1.5.1 in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from zeep->polarion) (1.5.1) cached-property>=1.3.0 in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from zeep->polarion) (1.5.2) requests-toolbelt>=0.7.1 in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from zeep->polarion) (0.9.1) requests>=2.7.0 in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from zeep->polarion) (2.24.0) pytz in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from zeep->polarion) (2020.1) isodate>=0.5.4 in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from zeep->polarion) (0.6.1) platformdirs>=1.4.0 in c:\users\manoj.andiyappanraju\appdata\roaming\python\python38\site-packages (from zeep->polarion) (2.5.2) six in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from requests-file>=1.5.1->zeep->polarion) (1.15.0) chardet<4,>=3.0.2 in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from requests>=2.7.0->zeep->polarion) (3.0.4) idna<3,>=2.5 in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from requests>=2.7.0->zeep->polarion) (2.10) urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from requests>=2.7.0->zeep->polarion) (1.25.11) certifi>=2017.4.17 in c:\users\manoj.andiyappanraju\anaconda3\lib\site-packages (from requests>=2.7.0->zeep->polarion) (2020.6.20)

armanoj commented 2 years ago

Still am getting this error zeep.exceptions.ValidationError: Missing element content (updateWorkItem.content.customFields.Custom.value.content)

jesper-raemaekers commented 2 years ago

Sorry for the delay.

I tried reproducing this, but with little luck. I have the same python and packages versions but the code still works. I can only reproduce this if i manually set the content to None.

val = cond_cont(type='text/html', content=None, contentLossy=False)

zeep.exceptions.ValidationError: Missing element content (updateWorkItem.content.customFields.Custom.value.content)