0

Below curl command works if post to execution evidence in Xray and attaching test.log file to evidence field:

curl -H "Content-Type: application/json" -X POST -u user:pwd --data @test.json https://jira.opentv.com/rest/raven/1.0/api/testrun/{id}/attachment

where test.json has this,

{
"data":"VGhpcyBmaWxlIGlzIHRlc3RpbmcgZm9yIHVwbG9hZCB0byBleGVjdXRpb24gZGV0YWlscy4=",
"filename":"test.log",
"contentType":"application/json"
} 

(in json 'data' is base64 encoded which is only supported in xray)

but when i try the same with below requests.post it fails.

requests.post('https://jira.opentv.com/rest/raven/1.0/api/testrun/{id}/attachment',headers = {'Content-Type':'application/json'},data={"data":"VGhpcyBmaWxlIGlzIHRlc3RpbmcgZm9yIHVwbG9hZCB0byBleGVjdXRpb24gZGV0YWlscy4=","fileName":"test.log","Content-Type":"application/json"},auth=('user', 'pwd'))

Thanks in Advance..

the curl cmd is executed from linux machine and python requests.post from windows. Both are reachable to Xray.

Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34

1 Answers1

0

You need to use a named "json" parameter instead of "data". You also had a typo in the contentType of the paypload.

The correct code would be something like:

import requests    
requests.post('https://sandbox.xpand-it.com/rest/raven/1.0/api/testrun/4448/attachment',headers = {'Content-Type':'application/json'}, json={"data":"VGhpcyBmaWxlIGlzIHRlc3RpbmcgZm9yIHVwbG9hZCB0byBleGVjdXRpb24gZGV0YWlscy4=", "filename":"test.log", "contentType":"application/json"},auth=('user', 'pass'))
Sérgio
  • 1,777
  • 2
  • 10
  • 12