jesper-raemaekers / python-polarion

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

Fill in custom fields for new work items #17

Closed krishtej23 closed 3 years ago

krishtej23 commented 3 years ago

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.

>>> tempWI.customFields
{
    'Custom': [
        {
            'key': 'field1',
            'value': {
                'id': 'lessThan6Months'
            }
        },
        {
            'key': 'field2',
            'value': 4
        },
        {
            'key': 'field3',
            'value': {
                'id': 'Expert'
            }
        }
]}

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.

jesper-raemaekers commented 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.

krishtej23 commented 3 years ago

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'}))
jesper-raemaekers commented 3 years ago

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.

krishtej23 commented 3 years ago

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?

jesper-raemaekers commented 3 years ago

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'))
krishtej23 commented 3 years ago

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'
            }
}
jesper-raemaekers commented 3 years ago

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')))
krishtej23 commented 3 years ago

perfect. It works based on the preliminary testing. Thanks a lot.

krishtej23 commented 3 years ago

Hi, I have following questions:

  1. How to catch login issues or incompatible setting for any fields (zeep.exceptions.Fault: org.xml.sax.SAXException: SimpleDeserializer encountered a child element)?
  2. How to link work items with custom roles?

Thanks.

jesper-raemaekers commented 3 years ago

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?

krishtej23 commented 3 years ago

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.

krishtej23 commented 3 years ago

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}))
jesper-raemaekers commented 3 years ago

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()
jesper-raemaekers commented 3 years ago

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.

krishtej23 commented 3 years ago

Thank you for updating. I didn't check yet but will check and let you know.

krishtej23 commented 3 years ago

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

jesper-raemaekers commented 3 years ago

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))
krishtej23 commented 3 years ago

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}
jesper-raemaekers commented 3 years ago

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

krishtej23 commented 3 years ago

ok. Is there a way to get a list of work items based on a query?

jesper-raemaekers commented 3 years ago

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.

krishtej23 commented 3 years ago

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?

jesper-raemaekers commented 3 years ago

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.

krishtej23 commented 3 years ago

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?

krishtej23 commented 3 years ago

I have multiple issues with test case work item.

  1. How do I access test steps?
    temp = projectObj.getWorkitem("proj-10430")

    temp._polarion_test_steps or temp._parsed_test_steps resulted nothing.

  2. Unable to get author for the work item. 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
  3. Unable to get list of users for the project. 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
  4. Here is my workitem xml:
    
    <html>
    <body>
    <!--StartFragment-->

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

JIRA-12455 S. John 2021-01-26 23:04:29.705 -0600 verifies Proj-6561 open 50.0 basic tobereviewed failed step description <span style="font-family: Arial, Helvetica, sans-serif;font-size: 8pt;">Verify User Received call <span style="font-family: Arial, Helvetica, sans-serif;font-size: 8pt;">Continue from above<br/>1. Make call<br/>2. Click Dial<br/>3. Verify call received</span> automated_software 12/14/2020 4:09:29 PM Debouncing 6 testcase

I do have Test Steps:
![image](https://user-images.githubusercontent.com/9395217/125140636-94dcfb00-e0d8-11eb-9a8d-5dad19f6e10e.png)
If I call `temp.customFields.Custom`, I get this but even here I do NOT see `test steps`.

[{ 'key': 'testType', 'value': { 'id': 'automated_software' } }, { 'key': 'testResults', 'value': { 'id': 'failed' } }, { 'key': 'JIRA', 'value': JIRA-12455' }, { 'key': 'testdate', 'value': '12/14/2020 4:09:29 PM' }]


Sorry for long issues but I need to have these for my project. Thanks a lot.
jesper-raemaekers commented 3 years ago

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?

Yes, i will play around with it a bit and see if i can make something useful.

The test step bug should now be fixed in V0.1.14. The user issue is not something i have here. Can you try and edit project.py to add a print, like so:

    def getUsers(self):
        """
        Gets all users in this project
        """
        users = []
        service = self.polarion.getService('Project')
        project_users = service.getProjectUsers(self.id)
        print(project_users)
        for user in project_users:
            users.append(User(self.polarion, user))
        return users

You can post the output, after removing names ofcourse, or compare it. This is what i get:


[{
    'description': None,
    'disabledNotifications': False,
    'email': None,
    'homePageContent': None,
    'id': 'admin',
    'name': 'System Administrator',
    'voteURIs': None,
    'watcheURIs': None,
    'uri': 'subterra:data-service:objects:/default/${User}admin',
    'unresolvable': False
}, {
    'description': None,
    'disabledNotifications': False,
    'email': None,
    'homePageContent': None,
    'id': 'user_a',
    'name': 'user_a',
    'voteURIs': None,
    'watcheURIs': None,
    'uri': 'subterra:data-service:objects:/default/${User}user_a',
    'unresolvable': False
}]
krishtej23 commented 3 years ago

Thanks Jesper. For the print statement for getUsers I can see the full list of users printed to console and then I see the same error. I can see the test steps now but how do I add test steps for a new test case work item? How about setting an author to a new work item?

jesper-raemaekers commented 3 years ago

Can you confirm the value for unresolvable is False?

For the tests steps, I've started making some code, but it's not ready to release yet since its missing documentation and tests. Have a look at this commit and copy the changes to your local installation to use it. An example:

workitem1 = project.createWorkitem('softwaretestcase')

workitem1.addTestStep(['a', 'b', 'c'])
workitem1.addTestStep(['d', 'e', 'f'])
workitem1.addTestStep(['g', 'h', 'i'])

workitem1.removeTestStep(1)

The author is set based on the user you logged in with. You cannot change it, as you also cannot do that in Polarion.

krishtej23 commented 3 years ago

Yes, unresolvable is False.

Add and remove test step works.

In regards to author, there is an import excel option in polarion to import all the test cases from excel sheet and create work items. Irrespective of the logged in user, we can map any author in the excel to any author in the polarion. Shown below at annotation 1 image.

jesper-raemaekers commented 3 years ago

Okay, than when you request the users from the project step through the code. you'll find that it will pass the printed data to the User class. Please step through to and see what causes the exception. To me, if there is data and unresolvable is False, there should not be an exception. I'm not sure about the amount of users, but can you see if it's a specific user causing the issue?

Perhaps you can get away with commenting out the exception. If there is one user causing this, you might not run into issues.

If you want, and are allowed, you can send me the print of the full user list so i can have a look whats going on.

You are correct. Please modify your local copy like this:

project.py:71

def createWorkitem(self, workitem_type: str, user):
        return Workitem(self.polarion, self, new_workitem_type=workitem_type, new_user=user)

workitem.py:34

def __init__(self, polarion, project, id=None, uri=None, new_workitem_type=None, new_user=None):

workitem.py:61

self._polarion_item.project = self._project.polarion_data
self._polarion_item.author = new_user._polarion_record #< this one is new
new_uri = service.createWorkItem(self._polarion_item)

I will make this properly in the future.

krishtej23 commented 3 years ago

I am NOT sure why but ONLY one user has unresolvable as True.

{
    'description': None,
    'disabledNotifications': None,
    'email': None,
    'homePageContent': None,
    'id': None,
    'name': None,
    'voteURIs': None,
    'watcheURIs': None,
    'uri': 'subterra:data-service:objects:/default/${User}1234uid',
    'unresolvable': True
}

I edited the code as below temporarily:

        else:
            print(f'User not retrieved from Polarion')
            print(f'{polarion_record}')
            # raise Exception(f'User not retrieved from Polarion')

How to use the new createWorkItem? Like this createWorkItem('testcase', 'john')?

jesper-raemaekers commented 3 years ago

I did it like this, so a search in that array would do.

x = project.getUsers()
workitem1 = project.getWorkitem('PYTH-1073')
workitem1 = project.createWorkitem('softwaretestcase', x[0])

For the users, for now, something like this could help you out:

    def getUsers(self):
        """
        Gets all users in this project
        """
        users = []
        service = self.polarion.getService('Project')
        project_users = service.getProjectUsers(self.id)
        for user in project_users:
            if user.unresolvable is False:
                users.append(User(self.polarion, user))
        return users

This is untested, but you get the idea. It's just to check if it's resolvable.

krishtej23 commented 3 years ago

Yes, that works too for getUsers(). For createWorkItem, are you going to create the function call to take either 2 arguments (work item type and user) OR 1 argument (work item type)? This way createWorkItem can be used with or without user defined.

krishtej23 commented 3 years ago

While linking work items, with this temp_wi.addLinkedItem('proj-6561','verifies'), I am getting this error

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 441, in addLinkedItem
    service = self._polarion.getService('Tracker')
AttributeError: 'str' object has no attribute 'uri'

How about external hyperlinks? I get the error for this temp_wi.addHyperlink('google.com,'ref_ext')

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 429, in addHyperlink
    service = self._polarion.getService('Tracker')
AttributeError: 'str' object has no attribute 'value'

I get the error for this temp_wi.addHyperlink('google.com',{'id': 'ref_ext'})

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 429, in addHyperlink
    service = self._polarion.getService('Tracker')
AttributeError: 'dict' object has no attribute 'value'
jesper-raemaekers commented 3 years ago

The linking requires another workitem object, not the ID.

 new_workitem_1 = project.createWorkitem('task')
 new_workitem_2 = project.createWorkitem('task')
 new_workitem_2.addLinkedItem(new_workitem_1, 'relates_to')

The hyperlink expect the Workitem.Hyperlinkroles class:

from polarion.workitem import Workitem
workitem1.addHyperlink('<url>', Workitem.HyperlinkRoles.EXTERNAL_REF)
krishtej23 commented 3 years ago

Those suggestions worked. Thank you. Just following up on the moving work item to document, any update on it?

jesper-raemaekers commented 3 years ago

Very little. I checked i can get 'locations' from the interface, but haven't tried yet.

krishtej23 commented 3 years ago

Is there any reason to reload work item from server in this function? I see this for removeLinkedItem() as well. https://github.com/jesper-raemaekers/python-polarion/blob/7da63f47b6c61d071ae9995bbf838ca6a56a09c1/polarion/workitem.py#L396 The reason I am asking is, lets say I have done some operations like creating Custom array and updated work item title and then when I call the addLinkedItem without .save(), all the updates I have made are being cleared and reloaded from server. I do not see this for any other function in work item. Can this be removed or is there any reason to keep?

After digging more, it seems like the issue is with self._reloadFromPolarion(). This function is used in 10 other places, so I will have to work around on this. Thanks.

krishtej23 commented 3 years ago

For the code below,

try:                                             
    temp_wi.save()                               
except:                                          
    ps = polarion.Polarion(server, username, pwd)
    project_obj = ps.getProject(proj_id)         
    temp_wi.save()

I am getting this error when saving the work item. There are 2 .save() and so getting the exception twice. What might be causing that?

Traceback (most recent call last):
  File "C:\Users\Desktop\importTestCases.py", line 116, in create_testcase_wi
    temp_wi.save()
  File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 556, 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: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:/Users/Desktop/main.py", line 31, in <module>
    importTestCases.create_testcase_wi(ps, projectObj, projID, dvp_sheet, proj_user_list)
  File "C:\Users\Desktop\importTestCases.py", line 120, in create_testcase_wi
    temp_wi.save()
  File "C:\Users\Desktop\venv\lib\site-packages\polarion\workitem.py", line 556, 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: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
python-BaseException
jesper-raemaekers commented 3 years ago

The reload is there to keep the local object and polarion in sync as some operations are done on the data locally and send to polarion and some are polarion functions and then loaded to the local data. I would just call save after you edited the data you need to and then call the other functions.

Those exceptions look like something in temp_wi is not as polarion expects. I think the problem is to be found in what you did to temp_wi beforehand.

krishtej23 commented 3 years ago

Yeah, I had alternate way for work item reload. For temp_wi, I was providing html type formatting for a simple straight value. Now everything works. In regards to createworkitem() with user, can be done as function overloading? Or what are your thoughts?

jesper-raemaekers commented 3 years ago

Yes, I think you can just set None as default since that's the value of the property when no user is being set.

jesper-raemaekers commented 3 years ago

Yes there is some progress. I have been able to move a newly created workitem to a document. I'll give a brief description of the steps:

preparations in polarion.py:107

self.services[service]['client'].service.moveWorkItemToDocument._proxy._binding.get(
                    'moveWorkItemToDocument').input.body.type._element[2].nillable = True

creating and moving:

w = project.createWorkitem('Test workitem A')
w.setDescription('Just a test description')
service = client.getService('Tracker')
spaces = service.getDocumentSpaces('Python') # be aware this changes order sometimes
u = service.getModuleUris('Python', spaces[0])
service.moveWorkItemToDocument(w.uri, u[0], None, -1, True)

I hopes this helps you get going. This will be refined at some point, but i cannot give a timeline on that. If absolutely critical we can discuss commercial support options.

krishtej23 commented 3 years ago

Thank you very much for building the code. It worked. and also thank you for proposing the commercial support. I will definitely work with you if needed.

krishtej23 commented 3 years ago

I tried to create a new module using createModule in service this way:

newmUri = service.createModule('Python',service.getDocumentSpaces("Python")[0],'Test Document','testcase','parent',False,'Heading')

but for some reason, I get this error. I followed https://almdemo.polarion.com/polarion/sdk/doc/javadoc/com/polarion/alm/ws/client/tracker/TrackerWebService.html#createModule(java.lang.String,java.lang.String,java.lang.String,com.polarion.alm.ws.client.types.tracker.EnumOptionId[],com.polarion.alm.ws.client.types.tracker.EnumOptionId,boolean,java.lang.String). Do you have any idea?

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  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.NullPointerException

If I try this:

newmUri = service.createModule('Python',service.getDocumentSpaces("Python")[0],'Test Document','testcase','parent',False,client.TextType(content="Heading", type='text/html', contentLossy=False))

I get this:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  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: org.xml.sax.SAXException: Bad types (class com.polarion.core.util.types.Text -> class java.lang.String)
jesper-raemaekers commented 3 years ago

Maybe you have found the issue by now, but I see this:

service.getDocumentSpaces("Python")

But Python is my Polarion project name, so fill the correct name there.

service.getDocumentSpaces("<project name>")
jesper-raemaekers commented 3 years ago

I'm closing this now. Feel free to open when you have new questions.

krishtej23 commented 3 years ago

I didn't get time to work on this again until today. Yes, I used my own project ID but couldn't solve the issue and later figured out that to create a new document I need to use createDocument() rather than createModule(). So here are my changes in _updateServices of polarion.py:

            if service == 'Tracker':
                # allow addComment to be send without title, needed for reply comments
                self.services[service]['client'].service.addComment._proxy._binding.get(
                    'addComment').input.body.type._element[1].nillable = True
                self.services[service]['client'].service.moveWorkItemToDocument._proxy._binding.get(
                    'moveWorkItemToDocument').input.body.type._element[2].nillable = True
                self.services[service]['client'].service.createDocument._proxy._binding.get(
                    'createDocument').input.body.type._element[4].nillable = True  # allowedWITypes
                self.services[service]['client'].service.createDocument._proxy._binding.get(
                    'createDocument').input.body.type._element[6].nillable = True  # homePageContent

This is how I call the service createDocument. structureLinkRole need to be passed as {'id': 'parent'}.

    # createDocument(java.lang.String projectId,
    #               java.lang.String location,
    #               java.lang.String documentName,
    #               java.lang.String documentTitle,
    #               EnumOptionId[] allowedWITypes,
    #               EnumOptionId structureLinkRole,
    #               java.lang.String homePageContent)
documentUri = services.createDocument('Python', 'customSpace', 'documentID', document_title, None, {'id': 'parent'}, None)

Hope this gives a jump start for you while developing a function for creating documents. Thank you for all the support so far. I will create a new issue as needed.