def test_extra_info(self):
        """ Test that correct extra info is returned."""
        subversion = MagicMock()
        subversion.unmerged_branches.return_value = [
            metric_source.Branch("some_branch", 22,
                                 datetime.datetime(2018, 1, 1))
        ]
        subversion.branch_folder_for_branch.return_value = "http://some_branch"

        project = domain.Project(
            metric_sources={metric_source.VersionControlSystem: subversion})
        subject = domain.Product(metric_source_ids={subversion: '_'})

        expected_result = domain.ExtraInfo(
            link="Branch",
            comment="Aantal ongemergde revisies__detail-column-number",
            date_last_change="Datum laatste wijziging__detail-column-number")
        expected_result.data = \
            [{"link": {"href": "http://some_branch", "text": "some_branch"}, "comment": 22,
              "date_last_change": "01-01-2018"}]
        obj = metric.UnmergedBranches(project=project, subject=subject)

        result = obj.extra_info()

        self.assertDictEqual(expected_result.headers, result.headers)
        self.assertEqual(expected_result.data, result.data)
        self.assertEqual('Niet gemergde branches', result.title)
 def test_report_without_metric_source(self):
     """ Test the report without a metric source. """
     self.assertEqual(
         'De hoeveelheid ongemergde branches van <no name> kon niet gemeten worden omdat de bron '
         'VersionControlSystem niet is geconfigureerd.',
         metric.UnmergedBranches(subject=domain.Product(),
                                 project=domain.Project()).report())
 def test_comment_urls_no_ignored_branches(self):
     """ Test the comment urls when there are no ignored branches. """
     product = domain.Product(
         short_name='Product',
         metric_source_ids={self.__subversion: 'http://svn/trunk/foo/'})
     unmerged_branches = metric.UnmergedBranches(subject=product,
                                                 project=self.__project)
     self.assertEqual({}, unmerged_branches.comment_urls())
    def test_format_text_with_no_metric_source(self):
        """ Test that the formatted text is followed by a link in square brackets. """
        project = domain.Project(
            metric_sources={metric_source.VersionControlSystem: [None]})
        obj = metric.UnmergedBranches(project=project, subject={})

        self.assertEqual("Some text...",
                         obj.format_text_with_links('Some text...'))
 def test_comment_urls_without_metric_source(self):
     """ Test the comment urls when the metric source is missing """
     subject = domain.Product(metric_options={
         metric.UnmergedBranches:
         dict(branches_to_ignore=['ignored branch'])
     })
     self.assertEqual(
         {'ignored branch': ''},
         metric.UnmergedBranches(subject=subject,
                                 project=domain.Project()).comment_urls())
 def test_combined_comment(self):
     """ Test that the metric comment is combined with the branch comment. """
     subject = domain.Product(
         metric_options={
             metric.UnmergedBranches:
             dict(comment="Comment.", branches_to_include=['branch'])
         })
     unmerged_branches = metric.UnmergedBranches(subject=subject,
                                                 project=self.__project)
     self.assertEqual(
         "Comment. Alleen deze branches worden bewaakt: branch.",
         unmerged_branches.comment())
 def test_comment_with_re_only(self):
     """ Test that comment for regular expression. """
     subject = domain.Product(
         metric_options={
             metric.UnmergedBranches: dict(
                 branches_to_ignore_re='feature.*')
         })
     unmerged_branches = metric.UnmergedBranches(subject=subject,
                                                 project=self.__project)
     self.assertEqual(
         "Branches die voldoen aan de reguliere expressie feature.* zijn genegeerd.",
         unmerged_branches.comment())
    def test_extra_info_no_unmerged_branches(self):
        """ Test that None is returned as extra info when there are no unmerged branches."""
        subversion = MagicMock()
        subversion.unmerged_branches.return_value = {}
        subversion.branch_folder_for_branch.return_value = "unimportant"

        project = domain.Project(
            metric_sources={metric_source.VersionControlSystem: subversion})
        subject = domain.Product(metric_source_ids={subversion: '_'})

        obj = metric.UnmergedBranches(project=project, subject=subject)

        result = obj.extra_info()

        self.assertIsNone(result)
 def setUp(self):
     self.__subversion = FakeSubversion()
     self.__project = domain.Project(
         metric_sources={
             metric_source.VersionControlSystem: self.__subversion
         })
     self.__subject = domain.Product(
         name='Product',
         short_name='PR',
         metric_source_ids={self.__subversion: 'http://svn/trunk/foo/'},
         metric_options={
             metric.UnmergedBranches:
             dict(branches_to_include=['branch', 'ignored branch'],
                  branches_to_ignore=['ignored branch'],
                  branches_to_ignore_re='feature.*')
         })
     self.__metric = metric.UnmergedBranches(subject=self.__subject,
                                             project=self.__project)
    def test_extra_info(self):
        """ Test that correct extra info is returned."""
        subversion = MagicMock()
        subversion.unmerged_branches.return_value = {"some_branch": 22}
        subversion.branch_folder_for_branch.return_value = "http://some_branch"

        project = domain.Project(
            metric_sources={metric_source.VersionControlSystem: subversion})
        subject = domain.Product(metric_source_ids={subversion: '_'})

        expected_result = domain.ExtraInfo(
            link="Branch", comment="Aantal__detail-column-number")
        expected_result.data = \
            [{"link": {"href": "http://some_branch", "text": "some_branch"}, "comment": "22 ongemergde revisie(s)"}]
        obj = metric.UnmergedBranches(project=project, subject=subject)

        result = obj.extra_info()

        self.assertDictEqual(expected_result.headers, result.headers)
        self.assertEqual(expected_result.data, result.data)
        self.assertEqual('Niet gemergde branches', result.title)
 def test_missing_metric_source(self):
     """ Test that the value is -1 when the metric source is missing. """
     self.assertEqual(
         -1,
         metric.UnmergedBranches(subject=domain.Product(),
                                 project=domain.Project()).value())