-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add Attachment to Test Steps? #155
Comments
Seleha from the TCM team has provided us with this helpful information:
In the python code the methods for step 1 and 2 can be found here:
I hope this helps, |
Thank you for the answer, that will help a bit to understand. Could you tell me actually what is the def create_attachment(self, upload_stream, project=None, file_name=None, upload_type=None, area_path=None):
"""CreateAttachment.
Uploads an attachment.
:param object upload_stream: Stream to upload
...
""" I tried both solutions below but none seems to work: with open('./smiley.png', "rb") as f:
binary_content = bytes(f.read())
attachment = client_wit.create_attachment(binary_content, project, 'smiley.png') attachment = client_wit.create_attachment("Hello my friend", project, 'test6.txt') (this solution creates a text file but it contains the double quotes in the text) Thanks |
I see. Hope it will be resolved soon. The only step I miss is that one (uploading a file correctly). This the code I have used for attaching an uploaded attachment to a Test Step def add_attachment(wit_id: int, project: str, url:str, comment: str, name:str = None):
"""Add attachment already uploaded to a WorkItem"""
# We want to have the possibility to set a comment
attributes = {"comment": comment}
if name is not None:
attributes["name"] = name
patch_document = [
JsonPatchOperation(
op="add",
path="/relations/-",
value={
"rel": "AttachedFile",
"url": url,
"attributes": attributes,
},
)
]
return wit_client.update_work_item(patch_document, wit_id, project)
def add_attachment_to_step(tc_id:int, project:str, url:str, step:int, comment="", name=""):
"""Add an attachment to a given step of a Test Case"""
name = name if name else re.sub(r".*fileName=", "", url)
comment = f"[TestStep={step}]:{comment}"
return add_attachment(tc_id, project, url, comment, name)
attachment = client.wit.create_attachment(my_stream, project, 'my_picture.png')
add_attachment_to_step(my_tc, project, attachment.url, 3, "Expected result") I will close the issue and hope #129 to be solved very soon. Thanks again for the support |
@jfthuong The fix has been released in 0.1.24 Example method to upload a file and link it as a work item attachment:
|
Awesome!!! |
The example method seems to be working for me, except I get the error JsonPatchOperation is not defined. Is there a library or extension I need to use for it? |
hi @bbalfour5 , just come to it now
|
Actually I was importing it like from from azure.devops.v5_1.work_item_tracking.models import JsonPatchOperation Or if you use version 4.1 of the API: from vsts.work_item_tracking.v4_1.models.json_patch_operation import JsonPatchOperation |
I would like to add attachments to some of the steps of my Test Cases like I can do in the Web Interface.
This is how I want my step to look like:
... and when you run it, that would look like this:
However, I have not been able to find where this information is stored.
This is the JSON data for the WorkItem of my Test Case
Any idea on where this information is stored?
And, if possible, could anyone tell me how to add an attachment from a file and link it to the test step?
Thanks a lot
The text was updated successfully, but these errors were encountered: