简体   繁体   English

无法找到通过 REST API 使用 URL 将附件上传到 ALM 的方法

[英]Unable to find a way to upload attachments using URL to ALM via REST API

I have a way to attach file as binary to ALM using REST API我有办法使用 REST API 将文件作为二进制文件附加到 ALM

URL =  "https://some.almserver.com/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs/<run-id>/attachments"

METHOD = "POST"

HEADERS = {

    'cache-control': "no-cache",

    "Slug": "some.html",

    'Content-Type': "application/octet-stream"

}

 

def attach_to_run_step():

    f = open("/path/to/some.html", "rb")

    response = requests.post(URL, headers=HEADERS, cookies=cookies, data=f.read())

    print(response.content)

I couldn't find any way to upload attachments which are in url format (from X website to ALM directly using REST) But from ALM UI, we have option to upload attachment using URL.我找不到任何方法来上传 url 格式的附件(从 X 网站直接使用 REST 到 ALM)但是从 ALM UI,我们可以选择使用 URL 上传附件。

Expecting METHOD, HEADERS, Request payload to upload url to ALM.期望方法、标头、请求有效负载将 url 上传到 ALM。

You need to authenticate and get the ALM session before trying to do anything else.在尝试执行任何其他操作之前,您需要验证并获取 ALM 会话。
Check out the Documentation for details.查看文档了解详细信息。

Here is a sample code (sorry I'm not a Python guy, but it works):这是一个示例代码(抱歉,我不是 Python 专家,但它可以工作):

import requests
session = requests.session()
response = session.post("http://xxx.xxx.xxx.xxx:8080/qcbin/authentication-point/alm-authenticate", headers={
    'Content-Type': 'application/xml'
}, data="<alm-authentication><user>user</user><password>password</password></alm-authentication>")

response = session.post("http://xxx.xxx.xxx.xxx:8080/qcbin/rest/site-session")

file = open("/path/to/some.html", "rb")

headers = {
    'Content-Type': 'application/octet-stream',
    'Slug': 'some.html'
}
response = session.post("http://xxx.xxx.xxx.xxx:8080/qcbin/rest/domains/DEFAULT/projects/demo/run-steps/1263/attachments", headers=headers, data=file.read())
print(response.text)

Just replace user , password and run-step ID with your own.只需将userpassword和 run-step ID 替换为您自己的即可。

PS We are developing commercial platform for integrating various test frameworks with ALM, which is called Agiletestware Bumblebee , so you might want to have a look at it. PS 我们正在开发用于将各种测试框架与 ALM 集成的商业平台,称为Agiletestware Bumblebee ,因此您可能想看看它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM