Skip to content

Commit

Permalink
Use dict.get() in get_issue or missing field will raise KeyError (#76)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mjuuti authored and lukas-bednar committed Jul 18, 2017
1 parent 477ee55 commit 77fbdfd
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pytest_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))
Expand Down Expand Up @@ -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(),
}

Expand Down

0 comments on commit 77fbdfd

Please sign in to comment.