#98 Adding tests to cover new functions added in PR#97
Merged 4 years ago by sidpremkumar. Opened 4 years ago by sidpremkumar.
sidpremkumar/sync-to-jira add-develop-flag-to-tests  into  develop

file modified
+84 -4
@@ -36,7 +36,8 @@ 

                  },

                  'testing': {},

                  'legacy_matching': False,

-                 'admins': [{'mock_admin': 'mock_email'}]

+                 'admins': [{'mock_admin': 'mock_email'}],

+                 'develop': False

              },

          }

  
@@ -409,13 +410,16 @@ 

          )

          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')

      @mock.patch(PATH + '_create_jira_issue')

      @mock.patch('jira.client.JIRA')

      @mock.patch(PATH + '_get_existing_jira_issue_legacy')

+     @mock.patch(PATH + 'check_jira_status')

      def test_sync_with_jira_matching(self,

+                                      mock_check_jira_status,

                                       mock_existing_jira_issue_legacy,

                                       mock_client,

                                       mock_create_jira_issue,
@@ -429,6 +433,7 @@ 

          # Set up return values

          mock_get_jira_client.return_value = mock_client

          mock_existing_jira_issue.return_value = self.mock_downstream

+         mock_check_jira_status.return_value = True

  

          # Call the function

          d.sync_with_jira(
@@ -448,7 +453,45 @@ 

      @mock.patch(PATH + '_create_jira_issue')

      @mock.patch('jira.client.JIRA')

      @mock.patch(PATH + '_get_existing_jira_issue_legacy')

+     @mock.patch(PATH + 'check_jira_status')

+     def test_sync_with_jira_down(self,

+                                  mock_check_jira_status,

+                                  mock_existing_jira_issue_legacy,

+                                  mock_client,

+                                  mock_create_jira_issue,

+                                  mock_update_jira_issue,

+                                  mock_existing_jira_issue,

+                                  mock_get_jira_client):

+         """

+         Tests 'sync_with_jira' function where the JIRA scriptrunner is down

+         """

+         # Set up return values

+         mock_get_jira_client.return_value = mock_client

+         mock_existing_jira_issue.return_value = self.mock_downstream

+         mock_check_jira_status.return_value = False

+ 

+         # Call the function

+         with self.assertRaises(JIRAError):

+             d.sync_with_jira(

+                 issue=self.mock_issue,

+                 config=self.mock_config

+             )

+ 

+         # Assert all calls were made correctly

+         mock_get_jira_client.assert_called_with(self.mock_issue, self.mock_config)

+         mock_update_jira_issue.assert_not_called()

+         mock_create_jira_issue.assert_not_called()

+         mock_existing_jira_issue_legacy.assert_not_called()

+ 

+     @mock.patch(PATH + '_get_jira_client')

+     @mock.patch(PATH + '_get_existing_jira_issue')

+     @mock.patch(PATH + '_update_jira_issue')

+     @mock.patch(PATH + '_create_jira_issue')

+     @mock.patch('jira.client.JIRA')

+     @mock.patch(PATH + '_get_existing_jira_issue_legacy')

+     @mock.patch(PATH + 'check_jira_status')

      def test_sync_with_jira_no_matching(self,

+                                         mock_check_jira_status,

                                          mock_existing_jira_issue_legacy,

                                          mock_client,

                                          mock_create_jira_issue,
@@ -462,6 +505,7 @@ 

          # Set up return values

          mock_get_jira_client.return_value = mock_client

          mock_existing_jira_issue.return_value = None

+         mock_check_jira_status.return_value = True

  

          # Call the function

          d.sync_with_jira(
@@ -945,7 +989,9 @@ 

      @mock.patch(PATH + '_matching_jira_issue_query')

      @mock.patch(PATH + '_close_as_duplicate')

      @mock.patch('jira.client.JIRA')

+     @mock.patch(PATH + 'check_jira_status')

      def test_close_duplicates_no_matching(self,

+                                           mock_check_jira_status,

                                            mock_client,

                                            mock_close_as_duplicate,

                                            mock_matching_jira_issue_query,
@@ -956,6 +1002,7 @@ 

          # Set up return values

          mock_get_jira_client.return_value = mock_client

          mock_matching_jira_issue_query.return_value = ['only_one_response']

+         mock_check_jira_status.return_value = True

  

          # Call the function

          response = d.close_duplicates(
@@ -978,11 +1025,13 @@ 

      @mock.patch(PATH + '_matching_jira_issue_query')

      @mock.patch(PATH + '_close_as_duplicate')

      @mock.patch('jira.client.JIRA')

+     @mock.patch(PATH + 'check_jira_status')

      def test_close_duplicates(self,

+                               mock_check_jira_status,

                                mock_client,

                                mock_close_as_duplicate,

-                                           mock_matching_jira_issue_query,

-                                           mock_get_jira_client):

+                               mock_matching_jira_issue_query,

+                               mock_get_jira_client):

          """

          This tests 'close_duplicates' function where len(results) > 1

          """
@@ -991,6 +1040,7 @@ 

          mock_item = MagicMock()

          mock_item.fields.created = 1

          mock_matching_jira_issue_query.return_value = [mock_item, mock_item, mock_item]

+         mock_check_jira_status.return_value = True

  

          # Call the function

          response = d.close_duplicates(
@@ -1388,4 +1438,34 @@ 

          # Assert everything was called correctly

          mock_comment_format_legacy.assert_called_with(mock_comment)

          mock_comment_format.assert_called_with(mock_comment)

-         self.assertEqual(response, None) 

\ No newline at end of file

+         self.assertEqual(response, None)

+ 

+     def test_check_jira_status_false(self):

+         """

+         This function tests 'check_jira_status' where we return false

+         """

+         # Set up return values

+         mock_jira_client = MagicMock()

+         mock_jira_client.search_issues.return_value = []

+ 

+         # Call the function

+         response = d.check_jira_status(mock_jira_client)

+ 

+         # Assert everything was called correctly

+         self.assertEqual(response, False)

+         mock_jira_client.search_issues.assert_called_with("issueFunction in linkedIssuesOfRemote('*')")

+ 

+     def test_check_jira_status_true(self):

+         """

+         This function tests 'check_jira_status' where we return false

+         """

+         # Set up return values

+         mock_jira_client = MagicMock()

+         mock_jira_client.search_issues.return_value = ['some', 'values']

+ 

+         # Call the function

+         response = d.check_jira_status(mock_jira_client)

+ 

+         # Assert everything was called correctly

+         self.assertEqual(response, True)

+         mock_jira_client.search_issues.assert_called_with("issueFunction in linkedIssuesOfRemote('*')")

no initial comment

Pull-Request has been merged by sidpremkumar

4 years ago
Metadata