dixudx / rtcclient

RTCClient for Rational Team Concert
https://readthedocs.org/projects/rtcclient/
Apache License 2.0
37 stars 44 forks source link

addAttachment does not link the uploaded attachment to the workitem #144

Open s7eph4n opened 3 years ago

s7eph4n commented 3 years ago

rtcclient 0.7.0 RTC 6.0.6.1

When adding an attachment, the file is successfully uploaded, but when linking to the workitem the server complains about malformed XML.

To get it to work I fixed _add_attachment_link to use JSON:

    def _add_attachment_link(self, attachment_info):
        headers = copy.deepcopy(self.rtc_obj.headers)
        headers["Content-Type"] = self.OSLC_CR_JSON

        payload = {"rdf:resource": attachment_info["url"],
                   "dcterms:title": ": ".join([str(attachment_info["id"]),
                                               attachment_info["name"]])}
        attachment_tag = ("/rtc_cm:com.ibm.team.workitem.linktype."
                          "attachment.attachment")
        attachment_collection_url = self.url + attachment_tag

        resp = self.post(attachment_collection_url,
                         json.dumps(payload),
                         verify=False,
                         headers=headers,
                         proxies=self.rtc_obj.proxies)
        raw_data = xmltodict.parse(resp.content)

        return Attachment(attachment_info["url"],
                          self.rtc_obj,
                          raw_data=raw_data["rtc_cm:Attachment"])
dixudx commented 3 years ago

@s7eph4n Please try to validate your xml file first. Try this online validator.

s7eph4n commented 3 years ago

That's the thing. There is no XML sent by the original code as far as I can tell, instead payload is posted as is. https://github.com/dixudx/rtcclient/blob/6c91ff29/rtcclient/workitem.py#L809