From 77fbdfdb0b124eea57f95e5d1b24c26d869cf3ed Mon Sep 17 00:00:00 2001 From: mjuuti Date: Tue, 18 Jul 2017 15:55:59 +0800 Subject: [PATCH] Use dict.get() in get_issue or missing field will raise KeyError (#76) * Use dict.get() in get_issue or missing field will cause raising exception * >80 length lines split to multiple rows * Line splits adjusted for better readability --- pytest_jira.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pytest_jira.py b/pytest_jira.py index 0ef85b9..fa24faf 100644 --- a/pytest_jira.py +++ b/pytest_jira.py @@ -114,8 +114,8 @@ def fixed_in_version(self, issue_id): """ if not self.version: return True - affected = self.issue_cache[issue_id].get('versions', set()) - fixed = self.issue_cache[issue_id].get('fixed_versions', set()) + affected = self.issue_cache[issue_id].get('versions') + fixed = self.issue_cache[issue_id].get('fixed_versions') return self.version not in (affected - fixed) def is_affected(self, issue_id): @@ -131,13 +131,13 @@ def is_affected(self, issue_id): ) def _affected_version(self, issue_id): - affected = self.issue_cache[issue_id].get('versions', set()) + affected = self.issue_cache[issue_id].get('versions') if not self.version or not affected: return True return self.version in affected def _affected_components(self, issue_id): - affected = self.issue_cache[issue_id].get('components', set()) + affected = self.issue_cache[issue_id].get('components') if not self.components or not affected: return True return bool(self.components.intersection(affected)) @@ -203,9 +203,15 @@ def get_issue(self, issue_id): issue = self._jira_request(issue_url).json() field = issue['fields'] return { - 'components': set(c['name'] for c in field['components']), - 'versions': set(v['name'] for v in field['versions']), - 'fixed_versions': set(v['name'] for v in field['fixVersions']), + 'components': set( + c['name'] for c in field.get('components', set()) + ), + 'versions': set( + v['name'] for v in field.get('versions', set()) + ), + 'fixed_versions': set( + v['name'] for v in field.get('fixVersions', set()) + ), 'status': field['status']['name'].lower(), }