def test_results_for_case_returns_correct_results(self):
     TR1_MODULE1_CASEA = create_test_results(module_name='module1',
                                             case_name='caseA')
     TESTS_RESULTS1 = TestsResults([
         TR1_MODULE1_CASEA,
         create_test_results(module_name='module1', case_name='caseB'),
         create_test_results(module_name='module2', case_name='caseC')
     ])
     TESTS_RESULTS2 = TestsResults(
         [create_test_results(module_name='module2', case_name='caseD')])
     TR3_MODULE1_CASEA = create_test_results(module_name='module1',
                                             case_name='caseA')
     TESTS_RESULTS3 = TestsResults([
         TR3_MODULE1_CASEA,
         create_test_results(module_name='module2', case_name='caseF')
     ])
     COMMIT1 = create_commit()
     COMMIT2 = create_commit()
     COMMIT3 = create_commit()
     commits_results = CommitsResults([
         CommitResults(COMMIT1, TESTS_RESULTS1),
         CommitResults(COMMIT2, TESTS_RESULTS2),
         CommitResults(COMMIT3, TESTS_RESULTS3)
     ])
     rfm1cA = commits_results.results_for_case('module1', 'caseA')
     self.assertEqual(len(rfm1cA), 3)
     self.assertEqual(rfm1cA[0].results, TR1_MODULE1_CASEA)
     self.assertEqual(rfm1cA[0].commit, COMMIT1)
     self.assertIsInstance(rfm1cA[1].results, NoTestResults)
     self.assertEqual(rfm1cA[1].commit, COMMIT2)
     self.assertEqual(rfm1cA[2].results, TR3_MODULE1_CASEA)
     self.assertEqual(rfm1cA[2].commit, COMMIT3)
 def test_insert_commits_inserts_commits(self):
     commit1 = create_commit()
     commit2 = create_commit()
     commit3 = create_commit()
     commits = [commit1, commit2, commit3]
     self.db.insert_commits(commits)
     self.assertEqual(self.db.get_results_for_recent_commits(3).commits, commits)
 def test_module_names_sorts_them_so_external_and_integration_tests_are_put_first(
         self):
     commits_results = CommitsResults([
         CommitResults(
             create_commit(),
             TestsResults([
                 create_test_results(module_name='bugs.1537'),
                 create_test_results(module_name='tools.fileinfo.sample')
             ])),
         CommitResults(
             create_commit(),
             TestsResults([
                 create_test_results(module_name='integration.current.ack'),
                 create_test_results(
                     module_name='integration.2015-03-30.ack')
             ])),
         CommitResults(
             create_commit(),
             TestsResults([
                 create_test_results(module_name='external.unit-tests'),
             ]))
     ])
     self.assertEqual(commits_results.module_names, [
         'external.unit-tests', 'integration.current.ack',
         'integration.2015-03-30.ack', 'bugs.1537', 'tools.fileinfo.sample'
     ])
    def test_get_topmost_commit_returns_topmost_commit_when_there_are_commits(self):
        commit1 = create_commit()
        self.db.insert_commit(commit1)
        commit2 = create_commit()
        self.db.insert_commit(commit2)

        self.assertEqual(self.db.get_topmost_commit(), commit2)
 def test_results_for_module_returns_correct_results(self):
     TR1_MODULE1_A = create_test_results(module_name='module1')
     TR1_MODULE1_B = create_test_results(module_name='module1')
     TESTS_RESULTS1 = TestsResults([
         TR1_MODULE1_A,
         TR1_MODULE1_B,
         create_test_results(module_name='module2'),
     ])
     TESTS_RESULTS2 = TestsResults(
         [create_test_results(module_name='module3')])
     TR3_MODULE1 = create_test_results(module_name='module1')
     TESTS_RESULTS3 = TestsResults([TR3_MODULE1])
     COMMIT1 = create_commit()
     COMMIT2 = create_commit()
     COMMIT3 = create_commit()
     commits_results = CommitsResults([
         CommitResults(COMMIT1, TESTS_RESULTS1),
         CommitResults(COMMIT2, TESTS_RESULTS2),
         CommitResults(COMMIT3, TESTS_RESULTS3)
     ])
     rfm1 = commits_results.results_for_module('module1')
     self.assertEqual(len(rfm1), len(commits_results))
     self.assertEqual(len(rfm1[0].results), 2)
     self.assertEqual(rfm1[0].commit, COMMIT1)
     self.assertEqual(rfm1[0].results[0], TR1_MODULE1_A)
     self.assertEqual(rfm1[0].results[1], TR1_MODULE1_B)
     self.assertEqual(len(rfm1[1].results), 0)
     self.assertEqual(rfm1[1].commit, COMMIT2)
     self.assertEqual(len(rfm1[2].results), 1)
     self.assertEqual(rfm1[2].commit, COMMIT3)
     self.assertEqual(rfm1[2].results[0], TR3_MODULE1)
    def test_get_unprocessed_commits_returns_commits_without_build_info(self):
        commit1 = create_commit()
        self.db.insert_commit(commit1)
        commit2 = create_commit()
        self.db.insert_commit(commit2)

        commits = self.db.get_unprocessed_commits()
        self.assertEqual(commits, [commit1, commit2])
 def test_commits_returns_correct_commits(self):
     COMMIT1 = create_commit()
     COMMIT2 = create_commit()
     commits_results = CommitsResults([
         CommitResults(COMMIT1, TestsResults()),
         CommitResults(COMMIT2, TestsResults())
     ])
     self.assertEqual(commits_results.commits, [COMMIT1, COMMIT2])
 def test_has_test_run_for_commit_returns_false_if_case_has_not_run_commit_does_not_match(self):
     commit1 = create_commit()
     self.db.insert_commit(commit1)
     test_results = create_test_results(module_name='module', case_name='case')
     self.db.insert_test_results(test_results, commit1)
     commit2 = create_commit()
     self.db.insert_commit(commit2)
     self.assertFalse(self.db.has_test_run_for_commit('module', 'case', commit2))
 def test_build_infos_returns_correct_infos(self):
     BUILD_INFO1 = create_build_info()
     BUILD_INFO2 = create_build_info()
     commits_results = CommitsResults([
         CommitResults(create_commit(), TestsResults(), BUILD_INFO1),
         CommitResults(create_commit(), TestsResults(), BUILD_INFO2)
     ])
     self.assertEqual(commits_results.build_infos,
                      [BUILD_INFO1, BUILD_INFO2])
 def test_results_returns_correct_results(self):
     TESTS_RESULTS1 = TestsResults(
         [create_test_results(module_name='module1')])
     TESTS_RESULTS2 = TestsResults(
         [create_test_results(module_name='module2')])
     commits_results = CommitsResults([
         CommitResults(create_commit(), TESTS_RESULTS1),
         CommitResults(create_commit(), TESTS_RESULTS2)
     ])
     self.assertEqual(commits_results.results,
                      [TESTS_RESULTS1, TESTS_RESULTS2])
    def test_get_unprocessed_commits_returns_empty_list_if_all_commits_with_build_info(self):
        commit1 = create_commit()
        self.db.insert_commit(commit1)
        self.db.insert_build_started_info(commit1, datetime.now())

        commit2 = create_commit()
        self.db.insert_commit(commit2)
        self.db.insert_build_started_info(commit2, datetime.now())

        commits = self.db.get_unprocessed_commits()
        self.assertEqual(commits, [])
    def test_get_commit_for_non_critical_tests_returns_none_when_no_commit_in_max_depth(self):
        commit1 = create_commit()
        self.db.insert_commit(commit1)
        test_results1 = create_test_results(critical=True)
        self.db.insert_test_results(test_results1, commit1)

        commit2 = create_commit()
        self.db.insert_commit(commit2)
        test_results2 = create_test_results(critical=False, run_tests=2, failed_tests=0)
        self.db.insert_test_results(test_results2, commit2)

        self.assertIsNone(self.db.get_commit_for_non_critical_tests(1))
    def test_get_commit_for_non_critical_tests_returns_correct_commit_when_topmost_not_passed_non_critical_tests(self):
        commit1 = create_commit()
        self.db.insert_commit(commit1)
        test_results1 = create_test_results(critical=True)
        self.db.insert_test_results(test_results1, commit1)

        commit2 = create_commit()
        self.db.insert_commit(commit2)
        test_results2 = create_test_results(critical=False, run_tests=2, failed_tests=1)
        self.db.insert_test_results(test_results2, commit2)

        self.assertEqual(self.db.get_commit_for_non_critical_tests(), commit1)
    def test_get_results_for_recent_commits_returns_correct_results_when_more_commits(self):
        commit1 = create_commit()
        self.db.insert_commit(commit1)
        commit2 = create_commit()
        self.db.insert_commit(commit2)
        commit3 = create_commit()
        self.db.insert_commit(commit3)

        COUNT = 2
        commits_results = self.db.get_results_for_recent_commits(COUNT)
        self.assertEqual(len(commits_results), COUNT)
        # Also check that the results are properly sorted, starting from the
        # "oldest" commit.
        self.assertEqual(commits_results[0].commit, commit2)
        self.assertEqual(commits_results[1].commit, commit3)
    def test_topmost_commit_has_succeeded_returns_false_if_build_failed(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        build_id = self.db.insert_build_started_info(commit, datetime.now())
        self.db.insert_build_ended_info(build_id, create_build_info(succeeded=False))

        self.assertFalse(self.db.topmost_commit_has_succeeded())
 def test_insert_build_started_info_returns_correct_id(self):
     commit = create_commit()
     self.db.insert_commit(commit)
     build1_id = self.db.insert_build_started_info(commit, datetime.now())
     self.assertEqual(build1_id, 1)
     build2_id = self.db.insert_build_started_info(commit, datetime.now())
     self.assertEqual(build2_id, 2)
    def test_initialize_commit_records_inserts_commit_when_not_exists(self):
        commit = create_commit()

        self.db.initialize_commit_records(commit)

        self.assertEqual(
            len(self.db.get_results_for_recent_commits(2).results), 1)
    def test_get_commit_for_non_critical_tests_skips_commits_that_failed_to_build(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        build_id = self.db.insert_build_started_info(commit, datetime.now())
        self.db.insert_build_ended_info(build_id, create_build_info(succeeded=False))

        self.assertIsNone(self.db.get_commit_for_non_critical_tests(1))
    def test_get_results_for_commit_returns_correct_results_when_there_is_build_info(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        START_DATE = datetime.now()
        build_id = self.db.insert_build_started_info(commit, START_DATE)
        LOG = 'build log'
        END_DATE = datetime.now()
        SUCCEEDED = True
        self.db.insert_build_ended_info(
            build_id,
            create_build_info(
                start_date=START_DATE,
                end_date=END_DATE,
                succeeded=SUCCEEDED,
                log=LOG
            )
        )

        commit_results = self.db.get_results_for_commit(commit)

        self.assertTrue(commit_results.has_build_info())
        self.assertEqual(commit_results.build_info.start_date, START_DATE)
        self.assertEqual(commit_results.build_info.end_date, END_DATE)
        self.assertEqual(commit_results.build_info.succeeded, SUCCEEDED)
        self.assertEqual(commit_results.build_info.log, LOG)
    def test_get_results_for_commit_returns_correct_results_when_there_is_no_build_info(self):
        commit = create_commit()
        self.db.insert_commit(commit)

        commit_results = self.db.get_results_for_commit(commit)

        self.assertFalse(commit_results.has_build_info())
    def test_initialize_commit_records_does_nothing_when_commit_already_exists_and_no_results(self):
        commit = create_commit()
        self.db.insert_commit(commit)

        self.db.initialize_commit_records(commit)

        self.assertEqual(len(self.db.get_results_for_recent_commits(2).results), 1)
    def test_get_commit_for_non_critical_tests_returns_none_when_all_commits_have_run_non_critical_tests(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        test_results = create_test_results(critical=False, run_tests=2, failed_tests=1)
        self.db.insert_test_results(test_results, commit)

        self.assertIsNone(self.db.get_commit_for_non_critical_tests())
    def test_initialize_commit_records_clears_emails_when_email_is_present(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        self.db.insert_email_for_commit(create_email(), commit)

        self.db.initialize_commit_records(commit)

        self.assertFalse(self.db.email_sent_for_commit(commit))
    def test_initialize_commit_records_does_not_clear_emails_when_forced_not_to(self):
        commit = create_commit()
        self.db.insert_commit(commit)
        self.db.insert_email_for_commit(create_email(), commit)

        self.db.initialize_commit_records(commit, remove_emails=False)

        self.assertTrue(self.db.email_sent_for_commit(commit))
 def test_insert_email_for_commit_does_nothing_if_email_already_sent(self):
     commit = create_commit()
     self.db.insert_commit(commit)
     email = create_email()
     self.db.insert_email_for_commit(email, commit)
     # This should do nothing, i.e. not raising an error regarding the
     # UNIQUE constraint of commit_id in the emails table.
     self.db.insert_email_for_commit(email, commit)
 def test_has_test_run_for_commit_returns_true_if_has_run(self):
     commit = create_commit()
     self.db.insert_commit(commit)
     test_results = create_test_results(module_name='module',
                                        case_name='case')
     self.db.insert_test_results(test_results, commit)
     self.assertTrue(
         self.db.has_test_run_for_commit('module', 'case', commit))
 def test_failed_module_names_returns_correct_value(self):
     commit_results = CommitResults(
         create_commit(),
         TestsResults([
             create_test_results(module_name='module',
                                 run_tests=2,
                                 failed_tests=1)
         ]))
     self.assertEqual(commit_results.failed_module_names, ['module'])
 def test_module_names_returns_correct_names(self):
     TESTS_RESULTS = TestsResults([
         create_test_results(module_name='module2'),
         create_test_results(module_name='module1'),
         create_test_results(
             module_name='module2')  # same as the first name
     ])
     commit_results = CommitResults(create_commit(), TESTS_RESULTS)
     self.assertEqual(commit_results.module_names, ['module1', 'module2'])
    def test_get_results_for_commit_returns_correct_results_when_there_are_no_results(self):
        commit = create_commit()
        self.db.insert_commit(commit)

        commit_results = self.db.get_results_for_commit(commit)

        self.assertEqual(commit_results.commit, commit)
        self.assertEqual(commit_results.results.run_tests, 0)
        self.assertEqual(commit_results.results.module_names, [])
 def test_module_names_returns_correct_names(self):
     commits_results = CommitsResults([
         CommitResults(
             create_commit(),
             TestsResults([
                 create_test_results(module_name='module2'),
                 create_test_results(module_name='module1'),
                 create_test_results(
                     module_name='module2')  # same as the first name
             ])),
         CommitResults(
             create_commit(),
             TestsResults([
                 create_test_results(module_name='module3'),
                 create_test_results(module_name='module1')
             ]))
     ])
     self.assertEqual(commits_results.module_names,
                      ['module1', 'module2', 'module3'])