From ade0987b4cb371102bdf22a7b636d9dcc6430722 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Jul 09 2019 19:06:09 +0000 Subject: Fixed issue where user has no updates array --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index e50ac41..b9b5c77 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -345,7 +345,7 @@ def _create_jira_issue(client, issue, config): custom_fields = issue.downstream.get('custom_fields', {}) default_type = issue.downstream.get('type', "Bug") # Build the description of the JIRA issue - if 'description' in issue.downstream.get('updates'): + if 'description' in issue.downstream.get('updates', {}): description = "Upstream description: {quote}%s{quote}" % issue.content else: description = '' @@ -417,7 +417,7 @@ def _update_jira_issue(existing, issue, client): log.info(" Updating information for upstream issue: %s" % issue.title) # Get a list of what the user wants to update for the upstream issue - updates = issue.downstream.get('updates') + updates = issue.downstream.get('updates', {}) # Update relevant data if needed # If the user has specified nothing @@ -504,10 +504,10 @@ def _update_transition(client, existing, issue): # First get the closed status from the config file try: # For python 3 > - closed_status = list(filter(lambda d: "transition" in d, issue.downstream.get('updates')))[0]['transition'] + closed_status = list(filter(lambda d: "transition" in d, issue.downstream.get('updates', {})))[0]['transition'] except ValueError: # for python 2.7 - closed_status = (filter(lambda d: "transition" in d, issue.downstream.get('updates')))[0]['transition'] + closed_status = (filter(lambda d: "transition" in d, issue.downstream.get('updates', {})))[0]['transition'] if closed_status is not True and issue.status == 'Closed' \ and existing.fields.status.name.upper() != closed_status.upper(): diff --git a/tests/test_downstream.py b/tests/test_downstream.py index c32d054..8bf18b9 100644 --- a/tests/test_downstream.py +++ b/tests/test_downstream.py @@ -360,6 +360,51 @@ class TestDownstream(unittest.TestCase): ) self.assertEqual(response, self.mock_downstream) + @mock.patch(PATH + '_update_jira_issue') + @mock.patch(PATH + '_attach_link') + @mock.patch('jira.client.JIRA') + def test_create_jira_issue_no_updates(self, + mock_client, + mock_attach_link, + mock_update_jira_issue): + """ + Tests '_create_jira_issue' function where we have + no updates + """ + # Set up return values + mock_client.create_issue.return_value = self.mock_downstream + self.mock_issue.downstream['updates'] = [] + + # Call the function + response = d._create_jira_issue( + client=mock_client, + issue=self.mock_issue, + config=self.mock_config + ) + + # Assert everything was called correctly + mock_client.create_issue.assert_called_with( + issuetype={'name': 'Fix'}, + project={'key': 'mock_project'}, + somecustumfield='somecustumvalue', + description='[1234] Upstream Reporter: mock_user \n ', + summary='mock_title' + ) + mock_attach_link.assert_called_with( + mock_client, + self.mock_downstream, + { + 'url': 'mock_url', + 'title': 'Upstream issue' + } + ) + mock_update_jira_issue.assert_called_with( + self.mock_downstream, + self.mock_issue, + mock_client + ) + self.assertEqual(response, self.mock_downstream) + @mock.patch(PATH + '_get_jira_client') @mock.patch(PATH + '_get_existing_jira_issue') @mock.patch(PATH + '_update_jira_issue')