Ejemplo n.º 1
0
    def test_creates_correct_body_when_build_failed(self):
        commit_results = CommitResults(self.commit, TestsResults(),
                                       create_build_info(succeeded=False))

        email = prepare_email(commit_results, self.subject_prefix,
                              self.web_url, self.wiki_page_url)

        self.assertRegex(email.body, r'build failed')
Ejemplo n.º 2
0
    def test_creates_correct_email_when_no_test_failed(self):
        commit_results = CommitResults(
            self.commit,
            TestsResults([create_test_results(run_tests=3, failed_tests=0)]),
            create_build_info(succeeded=True))

        email = prepare_email(commit_results, self.subject_prefix,
                              self.web_url, self.wiki_page_url)

        self.assertRegex(email.body, r'unknown failure')
Ejemplo n.º 3
0
    def test_sets_correct_addresses_and_urls(self):
        commit_results = CommitResults(self.commit, TestsResults(),
                                       create_build_info())

        email = prepare_email(commit_results, self.subject_prefix,
                              self.web_url, self.wiki_page_url)

        self.assertEqual(email.to_addr, 'Petr Zemek <*****@*****.**>')
        self.assertRegex(email.subject, r'^{}'.format(self.subject_prefix))
        self.assertIn(self.web_url, email.body)
        self.assertIn(self.wiki_page_url, email.body)
def send_email_for_commit_if_needed(config, db, commit):
    """Sends an email for the given commit, depending on several conditions.
    """
    if not config['email'].getboolean('enabled'):
        # Sending of emails is disabled.
        return

    if db.email_sent_for_commit(commit):
        # The email has already been sent.
        return

    commit_results = db.get_results_for_commit(commit)
    if (not commit_results.build_has_failed() and
            not commit_results.has_failed_tests()):
        # There is nothing to report.
        return

    if db.topmost_commit_has_succeeded():
        # There is no need to send the email if the topmost commit has
        # succeeded.
        return

    email = prepare_email(
        commit_results,
        config['email']['subject_prefix'],
        config['web']['main_page_url'],
        config['web']['wiki_page_url']
    )

    # Set proper addresses.
    def set_addr_if_defined(addr_type):
        addr_name = '{}_addr'.format(addr_type)
        addr = config['email'][addr_name]
        if addr:
            setattr(email, addr_name, addr)
    set_addr_if_defined('from')
    set_addr_if_defined('to')
    set_addr_if_defined('reply_to')
    set_addr_if_defined('cc')

    # Send the email.
    logging.info("sending email to '{}' concerning commit {}".format(
        email.to_addr, commit.short_hash()))
    send_email(
        email,
        config['email']['smtp_server'],
        config['email']['smtp_port'],
        config['email']['smtp_user'],
        config['email']['smtp_pass']
    )
    db.insert_email_for_commit(email, commit)
Ejemplo n.º 5
0
    def test_creates_correct_body_when_one_test_failed_in_one_module(self):
        commit_results = CommitResults(
            self.commit,
            TestsResults([
                create_test_results(module_name='module1',
                                    run_tests=3,
                                    failed_tests=1)
            ]), create_build_info(succeeded=True))

        email = prepare_email(commit_results, self.subject_prefix,
                              self.web_url, self.wiki_page_url)

        self.assertRegex(email.body, r'1 test failed in the following module:')
        self.assertRegex(email.body, r'module1')
Ejemplo n.º 6
0
    def test_creates_correct_email_when_two_tests_failed_in_two_modules(self):
        commit_results = CommitResults(
            self.commit,
            TestsResults([
                create_test_results(module_name='module1',
                                    case_name='Test (input.exe)',
                                    run_tests=3,
                                    failed_tests=1),
                create_test_results(module_name='module2',
                                    case_name='Test (input.exe)',
                                    run_tests=1,
                                    failed_tests=1)
            ]), create_build_info(succeeded=True))

        email = prepare_email(commit_results, self.subject_prefix,
                              self.web_url, self.wiki_page_url)

        self.assertRegex(email.body,
                         r'2 tests failed in the following modules:')
        self.assertRegex(email.body, r'module1')
        self.assertRegex(email.body, r'module2')