Jira Python Keyerror on issue links - python-3.x

I have a script which goes to fetch info via Jira API then its doing some comparison but i'm getting the following error :
Error :
"errorMessage": "'outwardIssue'"
"errorType": "KeyError"
JSON format:
"issuelinks": [
{
"id": "1255",
"self": "https://jiraurl/rest/api/2/issueLink/0000",
"type": {
"id": "10030",
"name": "Arises ",
"inward": "gives rise to",
"outward": "arises from",
"self": "https://jiraurl/rest/api/2/issueLinkType/0000"
},
"outwardIssue": {
"id": "1251575",
"key": "temp-511",
"self": "https://jiraurl/rest/api/2/issue/0000",
"fields": {
"summary": "a summary",
"status": {
"self": "https://jiraurl/rest/api/2/status/6",
"description": "test",
"iconUrl": "",
"name": "Closed",
"id": "6",
"statusCategory": {
"self": "https://jiraurl/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
},
"issuetype": {
"self": "https://jiraurl/rest/api/2/issuetype/20",
"id": "20",
"description": "Problem ",
"iconUrl": "https://jiraurl/images/icons/issuetypes/documentation.png",
"name": "Problem",
"subtask": false
}
}
}
}
]
Python Statement where we believe the issue is:
if (problem['fields']['issuelinks'][0]['outwardIssue']) and (problem['fields']['issuelinks'][0]['type']['outward'] == "arises from"):
isitanissue = False
I cant see why its stuck on'outwardIssue' ?

try this:
issue = jira.issue("XX)
if (issue.raw['fields']['issuelinks'][0]['outwardIssue']) and (issue.raw['fields']['issuelinks'][0]['type']['outward'] == "arises from"): isitanissue = False

Related

Unable to update the Knowledge in QnA maker

Unable to update the Knowledge in QnA maker whereas i am able to add the data to my Knowledge Base.Below is my update related REQUEST object
references: https://github.com/Azure-Samples/cognitive-services-qnamaker-java/blob/master/update-knowledge-base.java
{
"update": {
"qnaList": [
{
"id": 0,
"answer": "[92 Newcastle Court Roanoke, VA 24012](https://www.google.com/)",
"questions": [
"Where is Virginia located",
"What is the address of Roanoke",
"Roanoke address",
"Roanoke location"
],
"metadata": [
{
"name": "fragmenttype",
"value": "location"
},
{
"name": "locationname",
"value": "Roanoke"
},
{
"name": "type",
"value": "locationinfo"
}
]
},
{
"id": 1,
"answer": "[880 Oakwood St.Billerica, MA 01821](https://www.google.com/)",
"questions": [
"Where is Billerica located",
"What is the address of Billerica",
"Billerica address",
"Billerica location"
],
"metadata": [
{
"name": "fragmenttype",
"value": "location"
},
{
"name": "locationname",
"value": "Billerica"
},
{
"name": "type",
"value": "locationinfo"
}
]
}
]
}
}
and error response is:
{
"error": {
"code": 12,
"message": "Parameter is null",
"target": null,
"details": null,
"innerError": null
}
}
Your API call should be as below format.
More information can be found here
"update": {
"name": "QnA Maker FAQ Prompts Bot",
"qnaList": [
{
"id": 2,
"answer": "You can use our REST apis to create a KB. See here for details: https://learn.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/knowledgebase/create",
"source": "Custom Editorial",
"questions": {
"add": [],
"delete": []
},
"metadata": {
"add": [],
"delete": []
}
}
]
}

Node.js: Sending Cucumber JSON results to Jira's Xray - jira-client-xray gives HTTP 405 error

I'm struggling 5th day with sending test results to Jira. Our Jira has latest Xray plugin.
I use Node.js for test automation. I went easiest way to try Xray's capability of swallowing test automation results: 'jira-client-xray' dependency + Cucumber test.
In Jira I have Test Execution (id is KELLO-2426), what includes 1 Test (id is KELLO-2427) with Cucumber steps - Jira_Xray_Auto_Test.PNG.
I have 1 feature file - Feature_file.PNG.
After running the test/feature I got JSON-file with results:
[
{
"keyword": "Feature",
"description": "",
"line": 1,
"name": "Sample Snippets test",
"uri": "Can not be determined",
"tags": [],
"elements": [
{
"keyword": "Scenario",
"description": "",
"name": "open URL",
"tags": [
{
"name": "#KELLO:2426",
"location": {
"line": 6,
"column": 5
}
}
],
"id": "sample-snippets-test;open-url",
"steps": [
{
"arguments": [],
"keyword": "Before",
"name": "Hook",
"result": {
"status": "passed",
"duration": 1301000000
},
"line": "",
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "Given",
"name": "the page url is not \"http://webdriverjs.christian-bromann.com/\"",
"result": {
"status": "passed",
"duration": 257000000
},
"line": 8,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "And",
"name": "I open the url \"http://webdriverjs.christian-bromann.com/\"",
"result": {
"status": "passed",
"duration": 1221000000
},
"line": 9,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "Then",
"name": "I expect that the url is \"http://webdriverjs.christian-bromann.com/\"",
"result": {
"status": "passed",
"duration": 244000000
},
"line": 10,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "And",
"name": "I expect that the url is not \"http://google.com\"",
"result": {
"status": "passed",
"duration": 205000000
},
"line": 11,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "After",
"name": "Hook",
"result": {
"status": "passed",
"duration": 186000000
},
"line": "",
"match": {
"location": "can not be determined with webdriver.io"
}
}
]
}
],
"id": "sample-snippets-test",
"metadata": {
"browser": {
"name": "chrome",
"version": "72.0.3626.121"
},
"device": "Device name not known",
"platform": {
"name": "Platform name not known",
"version": "Version not known"
}
}
}
]
Next, I have 'jira.client.xray.js' file, where sending the results is written:
var JiraApiWithXray = require('jira-client-xray');
// Initialize
var jiraXray = new JiraApiWithXray({
strictSSL: false,
protocol: 'https',
username: 'your_username',
password: 'your_password',
host: 'your_host',
apiVersion: '1.0' //Check version from DevTools -> Network tab
});
const testExecResults = './results/sample-snippets-test.1574077621820.json';
try {
jiraXray.importExecResultsFromCucumber(testExecResults).then(function (testExecIssueId) {});
} catch(ex) {
console.log('Error:');
console.log(ex);
}
Initiating delivery of the test results by command node jira.client.xray.js from projects root directory gives me the following error:
UnhandledPromiseRejectionWarning: StatusCodeError: 405 - undefined
What is wrong? Suggest me please.
Yours sincerely,
JS comrade
Here shows the error you are receiving
https://restfulapi.net/http-status-codes/
That would lead me to believe it is a problem with your request being sent. My initial thoughts are testExecResults is in the wrong structure based on the documentation https://www.npmjs.com/package/jira-client-xray
Please post the request being sent.

Need help cleaning up iterating through nested JSON

I'm iterating through JSON content. I'm returning the sensor name + the temperature. There are two value keys under capability. I'm having trouble coming up with the simple logic to ignore the second one. I'm fairly new to python but feel like this is a simple adjustment. I just can't seem to find a good example on how to ignore the second value its pulling.
DATA:
"remoteSensors": [
{
"id": "rs:100",
"name": "Guest Bedroom",
"type": "ecobee3_remote_sensor",
"code": "TPCM",
"inUse": false,
"capability": [
{
"id": "1",
"type": "temperature",
"value": "690"
},
{
"id": "2",
"type": "occupancy",
"value": "false"
}
]
},
{
"id": "rs:101",
"name": "Mudd Room",
"type": "ecobee3_remote_sensor",
"code": "X9YF",
"inUse": false,
"capability": [
{
"id": "1",
"type": "temperature",
"value": "572"
},
{
"id": "2",
"type": "occupancy",
"value": "false"
}
]
},
{
"id": "rs:102",
"name": "Master Bedroom",
"type": "ecobee3_remote_sensor",
"code": "YDNZ",
"inUse": false,
"capability": [
{
"id": "1",
"type": "temperature",
"value": "694"
},
{
"id": "2",
"type": "occupancy",
"value": "true"
}
]
},
{
"id": "ei:0",
"name": "Main Floor",
"type": "thermostat",
"inUse": true,
"capability": [
{
"id": "1",
"type": "temperature",
"value": "725"
},
{
"id": "2",
"type": "humidity",
"value": "37"
},
{
"id": "3",
"type": "occupancy",
"value": "false"
}
]
}
]
CODE:
import requests
import json
url = 'https://api.ecobee.com/1/thermostat'
header = {'Content-Type': 'application/json;charset=UTF-8',
'Authorization': 'Bearer ZkEf7ONibogGpMQibem3SlhXhEOS99zK'}
params = {'json': ('{"selection":{"selectionType":"registered",'
'"includeRuntime":"true",'
'"includeSensors":"true",'
'"includeProgram":"true",'
'"includeEquipmentStatus":"true",'
'"includeEvents":"true",'
'"includeWeather":"true",'
'"includeSettings":"true"}}')}
request = requests.get(url, headers=header, params=params)
#print(request)
thermostats = request.json()['thermostatList']
remote_sensors = thermostats[0]['remoteSensors']
for eachsensor in thermostats[0]['remoteSensors']:
for temp in eachsensor['capability']:
name = eachsensor.get('name')
temp = temp.get('value')
print(name, temp)
Actual Results:
Guest Bedroom 690
Guest Bedroom false
Mudd Room 579
Mudd Room false
Master Bedroom 698
Master Bedroom false
Main Floor 731
Main Floor false
Expected Results:
Guest Bedroom 690
Mudd Room 579
Master Bedroom 698
Main Floor 731
Thanks for the help! #Naveen
Fixed:
for eachsensor in thermostats[0]['remoteSensors']:
for temp in eachsensor['capability']:
name = eachsensor.get('name')
tempr = temp.get('value')
id = temp.get('id')
if id == '1':
print(name, tempr, id)

Adaptive Cards doesn't work in MBF's Emulator running in Ubuntu 16.04

I am trying to implement AdaptiveCard into one of my dialogs using node.js. However once I run the emulator I get the following message instead of rendered AdaptiveCard:
[File of type 'application/vnd.microsoft.card.adaptive'].
Can anyone tell me what can be the problem?
I am running on Ubuntu 16.04, MBF Emulator v.3.5.31-alpha, microsoft-adaptivecards v.0.6.1.
Here is code from inside of one of my dialogs:
var msg = new builder.Message(session)
.addAttachment({
contentType: "application/vnd.microsoft.card.adaptive",
content: {
type: "AdaptiveCard",
body: [
{
"type": "TextBlock",
"text": msg_text,
},
{
"type": "Input.ChoiceSet",
"id": "myColor4",
"isMultiSelect": true,
"value": "1",
"style": "expanded",
"choices": [
{
"title": "Red",
"value": "1",
"isSelected": true
},
{
"title": "Green",
"value": "2"
},
{
"title": "Blue",
"value": "3",
"isSelected": true
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Sent",
"data": {
"myProperty": 12
}
}
],
}
});
session.send(msg);
This is detailed response, it contains all elements of the AdaptiveCard that I declared(but still it does not render):
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "What color do you want?"
},
{
"type": "Input.ChoiceSet",
"id": "myColor4",
"isMultiSelect": true,
"value": "1",
"style": "expanded",
"choices": [
{
"title": "Red",
"value": "1",
"isSelected": true
},
{
"title": "Green",
"value": "2"
},
{
"title": "Blue",
"value": "3",
"isSelected": true
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Sent",
"data": {
"myProperty": 12
}
}
]
}
}
],
"locale": "en-US",
"localTimestamp": "2017-09-17T19:21:17+02:00",
"from": {
"id": "default-bot",
"name": "Bot"
},
"recipient": {
"id": "default-user"
},
"inputHint": "acceptingInput",
"id": "heam84b9dn5b",
"replyToId": "71j1d6mbmk3l",
"channelId": "emulator",
"timestamp": "2017-09-17T17:21:17.379Z",
"conversation": {
"id": "fdikc23llm5"
}
}

How to flatten JSON with nested structure before passing to #csv filter

I am trying to parse some JSON that is the output of an AWS CLI command to display Snapshots. I want to load this data up into a spreadsheet to be able to filter, group, and audit it.
I've been stumped on how to get the nested Tags array flattened into the parent objects such that the intermediate can then be passed to the #csv filter.
Here is the example:
Initial input JSON:
{
"Snapshots": [
{
"SnapshotId": "snap-fff",
"StartTime": "2014-04-01T06:00:13.000Z",
"VolumeId": "vol-fff",
"VolumeSize": 50,
"Description": "desc1",
"Tags": [
{
"Value": "/dev/sdf",
"Key": "device"
},
{
"Value": "a name",
"Key": "Name"
},
{
"Value": "Internal",
"Key": "Customer"
},
{
"Value": "Demo",
"Key": "Environment"
},
{
"Value": "Brand 1",
"Key": "Branding"
},
{
"Value": "i-fff",
"Key": "instance_id"
}
]
},
{
"SnapshotId": "snap-ccc",
"StartTime": "2014-07-01T05:59:14.000Z",
"VolumeId": "vol-ccc",
"VolumeSize": 8,
"Description": "B Desc",
"Tags": [
{
"Value": "/dev/sda1",
"Key": "device"
},
{
"Value": "External",
"Key": "Customer"
},
{
"Value": "Production",
"Key": "Environment"
},
{
"Value": "i-ccc",
"Key": "instance_id"
},
{
"Value": "B Brand",
"Key": "Branding"
},
{
"Value": "B Name",
"Key": "Name"
},
{
"Value": "AnotherValue",
"Key": "AnotherKey"
}
]
}
]
}
Desired Intermediate:
[
{
"SnapshotId": "snap-fff",
"StartTime": "2014-04-01T06:00:13.000Z",
"VolumeId": "vol-fff",
"VolumeSize": 50,
"Description": "desc1",
"device": "/dev/sdf",
"Name": "a name",
"Customer": "Internal",
"Environment": "Demo",
"Branding": "Brand 1",
"instance_id": "i-fff",
}
{
"SnapshotId": "snap-ccc",
"StartTime": "2014-07-01T05:59:14.000Z",
"VolumeId": "vol-ccc",
"VolumeSize": 8,
"Description": "B Desc",
"device": "/dev/sda1",
"Customer": "External",
"Environment": "Production",
"instance_id": "i-ccc",
"Branding": "B Brand",
"Name": "B Name",
"AnotherKey": "AnotherValue",
}
]
Final Output:
"SnapshotId","StartTime","VolumeId","VolumeSize","Description","device","Name","Customer","Environment","Branding","instance_id","AnotherKey"
"snap-fff","2014-04-01T06:00:13.000Z","vol-fff",50,"desc1","/dev/sdf","a name","Internal","Demo","Brand 1","i-fff",""
"snap-ccc","2014-07-01T05:59:14.000Z","vol-ccc",8,"B Desc","/dev/sda1","External","Production","i-ccc","B Brand","B Name","AnotherValue"
The following jq filter produces the requested intermediate output:
.Snapshots[] | (. + (.Tags|from_entries)) | del(.Tags)
Explanation: from_entries converts the array of key-value objects to an object with the given key-value pairs. This is added to the target object, and finally the "Tags" key is removed.
If the "target" object has a key that also appears in the "Tags" array, then the above filter will favor the value in the "Tags" array. You may accordingly wish to change the order of the operands of "+", or resolve the conflict in some other way.

Resources