Closed krishtej23 closed 3 years ago
To do this, you would need to build a new customField type. I made an example for you to try, please let me know if this works out.
# create new workitem
new_workitem = project.createWorkitem('task')
# load the types needed from polarion
custom_type_array = client.getTypeFromService('Tracker', 'ns2:ArrayOfCustom')
custom_type = client.getTypeFromService('Tracker', 'ns2:Custom')
# build the custom types into an array
custom_array = custom_type_array()
custom_array.Custom.append(custom_type(key='string_field', value='Test string'))
custom_array.Custom.append(custom_type(key='int_field', value='1234'))
# assign it to the custom fields of the new workitem
new_workitem.customFields = custom_array
# save it
new_workitem.save()
For the logging out problem i have no solution ready yet.
Thank you, I will try this. What about the values with id
, like this
{
'key': 'field3',
'value': {
'id': 'Expert'
}
Is this how we do it?
custom_array.Custom.append(custom_type(key='int_field', value={'id':'1234'}))
Is that an Enum type? and if so, is it a predefined one or a custom one as well?
That might work, but it might not be the right type if you want to edit it later.
Yes it is an Enum type and it is also custom one. Can you please explain but it might not be the right type if you want to edit it later
?
So you can build the the type manually and save it to polarion. If you then load it again, there is no difference. But if you work with the same object as the one you created it on, there might be a type difference.
I would recommend to try and do it like this (snippet from workitem.py):
self.resolution = self._polarion.EnumOptionIdType(
id=resolution)
So something alike should work:
custom_array.Custom.append(custom_type(key='int_field', polarion.EnumOptionIdType(id='234'))
Great! so if the custom field is a value type then I get it updated but if the custom field is an enum type then I am getting:
>>> custom_array.Custom.append(custom_type(key='int_field', polarion.EnumOptionIdType(id='local')))
File "<stdin>", line 1
custom_array.Custom.append(custom_type(key='int_field', polarion.EnumOptionIdType(id='local')))
^
SyntaxError: positional argument follows keyword argument
To recover I interchanged the args and I get this error:
>>> custom_array.Custom.append(custom_type(polarion.EnumOptionIdType(id='local'), key='int_field'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'polarion.polarion' has no attribute 'EnumOptionIdType'
I changed the code to:
custom_array.Custom.append(custom_type(client.EnumOptionIdType(id='local'), key='int_field'))
Now it passes but the result is NOT what I want:
{
'key': {
'id': 'local'
},
'value': None
}
I need it like:
{
'key': 'int_field',
'value': {
'id': 'local'
}
}
Try it like this; otherwise i need to check when i get home.
custom_array.Custom.append(custom_type(key='int_field', value=client.EnumOptionIdType(id='local')))
perfect. It works based on the preliminary testing. Thanks a lot.
Hi, I have following questions:
Thanks.
I've created a new branch to add the workitem linking. Please see that if you want it now, I still need to improve the tests before i publish it, but it seems to work (even with custom links).
Can you provide an example of when the exception occurs? Or is the goal to find wrongly entered data before trying to save it?
I will try to find the work item linking. Thank you for creating it quickly.
I want to catch it before saving the incorrect data.
Hi, I encountered 2 more issues. How do we set multi select custom fields and rich text fields?
{
'key': 'contactMethod',
'value': {
'EnumOptionId': [
{
'id': 'phone'
},
{
'id': 'email'
}
]
}
}
{
'key': 'notes',
'value': {
'type': 'text/html',
'content': 'This is a sample note',
'contentLossy': False
}
I tried the following and there are no errors but the end result is values for the "contactMethod" custom field are cleared out completely.
ps = polarion.Polarion(server, username, pwd)
tempArray = []
tempArray.append(ps.EnumOptionIdType(id='phone'))
tempArray.append(ps.EnumOptionIdType(id='email'))
tempArray.append(ps.EnumOptionIdType(id='mail'))
custom_type = ps.getTypeFromService('Tracker', 'ns2:Custom')
tempWi.customFields.Custom.append(custom_type(key='contactMethod', value={'EnumOptionId':tempArray}))
You're close. It needs to be build in an 'ArrayOfEnumOptionId'. Go ahead and try it with this example:
# create new workitem
new_workitem = project.createWorkitem('task')
# load the types needed from polarion
custom_type_array = client.getTypeFromService('Tracker', 'ns2:ArrayOfCustom')
custom_type = client.getTypeFromService('Tracker', 'ns2:Custom')
array_enum_id = client.getTypeFromService('Tracker', 'ns2:ArrayOfEnumOptionId')
# build the custom types into an array
enum_array = array_enum_id()
enum_array.EnumOptionId.append(client.EnumOptionIdType(id='open'))
enum_array.EnumOptionId.append(client.EnumOptionIdType(id='done'))
custom_array = custom_type_array()
custom_array.Custom.append(custom_type(key='string_field', value='Test string'))
custom_array.Custom.append(custom_type(key='int_field', value='1234'))
custom_array.Custom.append(custom_type(key='multi_enum_field', value=enum_array))
# assign it to the custom fields of the new workitem
new_workitem.customFields = custom_array
# save it
new_workitem.save()
I've taken some of you feedback and integrated it in the V0.1.13 release which is available now. See https://python-polarion.readthedocs.io/en/latest/workitem.html#linking for the new bits.
Feel free to try it and provide more feedback if you find anything.
Thank you for updating. I didn't check yet but will check and let you know.
Hi, the code for multi select fields works but for string type custom fields fail. I got the below format from the existing work item. This is how polarion expects I think
'value': {
'type': 'text/html',
'content': 'notes.',
'contentLossy': False
}
but this line custom_array.Custom.append(custom_type(key='string_field', value='Test string'))
generates this:
'value': 'Notes.'
giving me this error
Traceback (most recent call last):
File "C:\Users\Desktop\importWorkItems.py", line 92, in create_wi
temp_wi.save()
File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 509, in save
service.updateWorkItem(updated_item)
File "C:\Users\Desktop\venv\lib\site-packages\zeep\proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "C:\Users\Desktop\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 135, in send
return self.process_reply(client, operation_obj, response)
File "C:\Users\Desktop\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 229, in process_reply
return self.process_error(doc, operation)
File "C:\Users\Desktop\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 329, in process_error
raise Fault(
zeep.exceptions.Fault: java.lang.IllegalArgumentException: type cannot be null
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Desktop\workItemImportExcel.py", line 35, in <module>
WI.create_wi(ps, projectObj, projID, excel_sheet)
File "C:\Users\Desktop\importDamageWorkItems.py", line 96, in create_wi
temp_wi.save()
File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 509, in save
service.updateWorkItem(updated_item)
File "C:\Users\Desktop\venv\lib\site-packages\zeep\proxy.py", line 46, in __call__
return self._proxy._binding.send(
File "C:\Users\Desktop\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 135, in send
return self.process_reply(client, operation_obj, response)
File "C:\Users\Desktop\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 229, in process_reply
return self.process_error(doc, operation)
File "C:\Users\Desktop\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 329, in process_error
raise Fault(
zeep.exceptions.Fault: java.lang.IllegalArgumentException: type cannot be null
Looks like value
should have type
with text/html
You can create that text/html type like this:
client.TextType(content='text here', type='text/html', contentLossy=False)
Not tested, but it should be something alike this:
custom_array.Custom.append(custom_type(key='string_field', value=client.TextType(content='text here', type='text/html', contentLossy=False))
Your code worked. So what difference does the below code has with your code? I tried the below one but got the same error.
custom_array.Custom.append(custom_type(key='string_field', value= { 'type': 'text/html', 'content': 'notes.', 'contentLossy': False}
The only difference is the type used is now the one supplied by polarion (or rather the zeep module). To be honest, i expected that line of code to work just fine. You can see in an older version i used to do the same thing with the description field: https://github.com/jesper-raemaekers/python-polarion/blob/3a7e7958bb47d739f49a99e0a2ad5b932237b843/polarion/workitem.py#L159
ok. Is there a way to get a list of work items based on a query?
https://python-polarion.readthedocs.io/en/latest/project.html#polarion.project.Project.searchWorkitemFullItem This should work in the same way the query within polarion work. I cannot make an example for you at the moment.
Hi,
I know you mentioned no access to live docs but I see that when I retrieve a work item, there is a location
attribute. This results in
'default:/Sandbox/projID/modules/compValidation/doc/workitems/projID-10430/workitem.xml'
Can we use this to move the newly created work items to specific doc
?
Good question; I'm not sure. I haven't played around much with the documents.
I do see some options in the polarion API to move workitem in a document (See the java docs for example). So there should be options, but i cannot give any example unfortunately.
In Polarion API, for moveWorkItemToDocument()
, I could get workitemuri
and moduleuri
but unable to work out the function call. Looks like I need to write the request
calls to access that api directly from python without your package. Correct?
I have multiple issues with test case work item.
temp = projectObj.getWorkitem("proj-10430")
temp._polarion_test_steps
or temp._parsed_test_steps
resulted nothing.
temp.getAuthor()
gives me error
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 110, in getAuthor
return User(self._polarion, self.author)
File "C:\UsersDesktop\venv\lib\site-packages\polarion\user.py", line 27, in __init__
raise Exception(f'User not retrieved from Polarion')
Exception: User not retrieved from Polarion
projectObj = client.getProject(projID)
and projectObj.getUsers()
throws below error. Same error for projectObj.findUser("john")
also tried with company userid.
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Desktop\venv\lib\site-packages\polarion\project.py", line 49, in getUsers
users.append(User(self.polarion, user))
File "C:\Users\Desktop\venv\lib\site-packages\polarion\user.py", line 27, in __init__
raise Exception(f'User not retrieved from Polarion')
Exception: User not retrieved from Polarion
<html>
<body>
<!--StartFragment-->
Hi, I have an excel sheet with each sheet corresponding to multiple work items of same type with many attributes. I am developing python script to create work items and fill the custom fields with those attributes. Problem is for existing work item in polarion, I am able to get the custom fields as an array but for new work item, how do I fill the custom field values? There are really lot of work items and this will help me reduce lot of manual work. Fields for already existing work item but for new work item I get nothing.
Also, polarion keeps logging me out and I have create a session every sometime. Is there a way to hold the session from logging out? Thanks.