def test_function_calls(self):
        check_function_calls = {
            'create_new_file_with_release_message_template_gets_called': False,
            'validate_release_message_gets_called': False,
            'prompt_user_to_send_announcement_email_gets_called': False,
            'create_group_for_next_release': False,
        }
        expected_check_function_calls = {
            'create_new_file_with_release_message_template_gets_called': True,
            'validate_release_message_gets_called': True,
            'prompt_user_to_send_announcement_email_gets_called': True,
            'create_group_for_next_release': True,
        }

        def mock_create_new_file_with_release_message_template():
            check_function_calls[
                'create_new_file_with_release_message_template_gets_called'] = True

        def mock_validate_release_message():
            check_function_calls['validate_release_message_gets_called'] = True

        def mock_prompt_user_to_send_announcement_email():
            check_function_calls[
                'prompt_user_to_send_announcement_email_gets_called'] = True

        def mock_create_group_for_next_release():
            check_function_calls['create_group_for_next_release'] = True

        def mock_exists(unused_filepath):
            return True

        def mock_remove(unused_filepath):
            pass

        release_summary_swap = self.swap(release_constants,
                                         'RELEASE_SUMMARY_FILEPATH',
                                         MOCK_RELEASE_SUMMARY_FILEPATH)
        write_swap = self.swap(
            generate_release_updates,
            'create_new_file_with_release_message_template',
            mock_create_new_file_with_release_message_template)
        check_swap = self.swap(generate_release_updates,
                               'validate_release_message',
                               mock_validate_release_message)
        send_swap = self.swap(generate_release_updates,
                              'prompt_user_to_send_announcement_email',
                              mock_prompt_user_to_send_announcement_email)
        create_group_swap = self.swap(generate_release_updates,
                                      'create_group_for_next_release',
                                      mock_create_group_for_next_release)
        exists_swap = self.swap(os.path, 'exists', mock_exists)
        remove_swap = self.swap(os, 'remove', mock_remove)

        with self.branch_name_swap, release_summary_swap, create_group_swap:
            with write_swap, check_swap, send_swap, exists_swap, remove_swap:
                generate_release_updates.main()

        self.assertEqual(check_function_calls, expected_check_function_calls)
Example #2
0
 def test_missing_release_summary_file(self):
     release_summary_swap = self.swap(
         release_constants, 'RELEASE_SUMMARY_FILEPATH', 'invalid.md')
     with self.branch_name_swap, release_summary_swap:
         with self.assertRaisesRegexp(
             Exception, (
                 'Release summary file invalid.md is missing. Please run '
                 'the release_info.py script and re-run this script.')):
             generate_release_updates.main()
Example #3
0
 def test_invalid_branch_name(self):
     def mock_get_current_branch_name():
         return 'invalid'
     branch_name_swap = self.swap(
         common, 'get_current_branch_name', mock_get_current_branch_name)
     with branch_name_swap, self.assertRaisesRegexp(
         Exception, (
             'This script should only be run from the latest release '
             'branch.')):
         generate_release_updates.main()
Example #4
0
    def test_function_calls(self):
        check_function_calls = {
            'draft_new_release_gets_called': False,
            'prompt_user_to_send_announcement_email_gets_called': False,
            'prepare_for_next_release_gets_called': False,
        }
        expected_check_function_calls = {
            'draft_new_release_gets_called': True,
            'prompt_user_to_send_announcement_email_gets_called': True,
            'prepare_for_next_release_gets_called': True,
        }

        def mock_draft_new_release():
            check_function_calls['draft_new_release_gets_called'] = True

        def mock_prompt_user_to_send_announcement_email():
            check_function_calls[
                'prompt_user_to_send_announcement_email_gets_called'] = True

        def mock_prepare_for_next_release():
            check_function_calls['prepare_for_next_release_gets_called'] = True

        def mock_exists(unused_filepath):
            return True

        def mock_remove(unused_filepath):
            pass

        release_summary_swap = self.swap(release_constants,
                                         'RELEASE_SUMMARY_FILEPATH',
                                         MOCK_RELEASE_SUMMARY_FILEPATH)
        draft_release_swap = self.swap(generate_release_updates,
                                       'draft_new_release',
                                       mock_draft_new_release)
        send_swap = self.swap(generate_release_updates,
                              'prompt_user_to_send_announcement_email',
                              mock_prompt_user_to_send_announcement_email)
        prepare_swap = self.swap(generate_release_updates,
                                 'prepare_for_next_release',
                                 mock_prepare_for_next_release)
        exists_swap = self.swap(os.path, 'exists', mock_exists)
        remove_swap = self.swap(os, 'remove', mock_remove)

        with self.branch_name_swap, release_summary_swap, prepare_swap:
            with send_swap, exists_swap, remove_swap, draft_release_swap:
                generate_release_updates.main()

        self.assertEqual(check_function_calls, expected_check_function_calls)