def test_included_metric_source_classes(self): """ Test that the report gives a list of included metric source classes, based on the project's metric source classes. """ project = domain.Project() self.assertEqual( project.metric_source_classes(), report.QualityReport(project).included_metric_source_classes())
def test_get_environment_section(self): """ Test that the environment can be found. """ environment = domain.Environment(short_name='ENV') self.__project.add_environment(environment) quality_report = report.QualityReport(self.__project) section = quality_report.get_section('ENV') self.assertEqual('ENV', section.id_prefix())
def test_vcs_id_when_no_metric_source_id(self): """ Test that the empty VCS id is retrieved when there is no metric source id """ vcs = 'VCS' project = domain.Project('organization', metric_sources={metric_source.VersionControlSystem: vcs}) product = domain.Product(metric_source_ids={}) quality_report = report.QualityReport(project) self.assertEqual((None, ''), quality_report.vcs_id(product))
def test_vcs_id_when_product_is_none(self): """ Test that the empty VCS id is retrieved for None product. """ vcs = 'VCS' project = domain.Project('organization', metric_sources={metric_source.VersionControlSystem: vcs}) product = None quality_report = report.QualityReport(project) self.assertEqual((None, ''), quality_report.vcs_id(product))
def test_vcs_id(self): """ Test that the VCS id can be retrieved. """ vcs = 'VCS' project = domain.Project('organization', metric_sources={metric_source.VersionControlSystem: vcs}) product = domain.Product(metric_source_ids={vcs: 'vcs_id'}) quality_report = report.QualityReport(project) self.assertEqual(('VCS', 'vcs_id'), quality_report.vcs_id(product))
def test_sonar_id_empty(self): """ Test that the Sonar id of a product can be retrieved. """ sonar = 'Sonar' project = domain.Project('organization', metric_sources={metric_source.Sonar: sonar}) product = domain.Product(metric_source_ids={sonar: ''}) quality_report = report.QualityReport(project) self.assertEqual((None, ''), quality_report.sonar_id(product))
def test_direct_action_needed_when_metrics_are_missing(self): """ Test that the report needs direct action when the report has missing metrics. """ project = domain.Project('organization', name='project title', added_requirements={requirement.TrustedProductMaintainability}) quality_report = report.QualityReport(project) quality_report.sections() # Generate the report self.assertTrue(quality_report.direct_action_needed())
def test_product(self): """ Test that the report has two sections when we add a product: one for the product itself, and one for meta metrics. """ project = domain.Project() project.add_product( domain.Product(short_name='FP', requirements=[requirement.CodeQuality])) self.assertEqual(2, len(report.QualityReport(project).sections()))
def create_report(self, report_folder, create_frontend: bool = True): """ Create, format, and write the quality report. """ quality_report = report.QualityReport(self.__project) for history in self.__project.metric_sources(metric_source.History): history = cast(metric_source.History, history) if history.filename(): history.add_report(quality_report) self.__create_report(quality_report, report_folder, create_frontend) return quality_report
def test_last_product_change_date(self): """ Test that the report can retrieve the last changed date of a product. """ class FakeVCS(object): # pylint: disable=too-few-public-methods """ Fake VCS metric source with a fixed changed date. """ @staticmethod def last_changed_date(vcs_id): # pylint: disable=unused-argument """ Return the date the product was last changed. """ return datetime.datetime(2017, 1, 1) vcs = FakeVCS() project = domain.Project('organization', metric_sources={metric_source.VersionControlSystem: vcs}) product = domain.Product(metric_source_ids={vcs: 'vcs_id'}) quality_report = report.QualityReport(project) self.assertEqual(datetime.datetime(2017, 1, 1), quality_report.latest_product_change_date(product))
def report(project_kwargs, team_kwargs, process_kwargs, product_kwargs): """ Create the quality report. """ documents = project_kwargs.pop('documents', []) project = domain.Project('organization', name='project', **project_kwargs) for document in documents: project.add_document(document) if team_kwargs: project.add_team(ReportFactory.__create_team(team_kwargs)) if process_kwargs: project.add_process(ReportFactory.__create_process(process_kwargs)) if product_kwargs: project.add_product(ReportFactory.__create_product(product_kwargs)) quality_report = report.QualityReport(project) quality_report.sections() # Make sure the report is created return quality_report
def test_direct_action_needed_without_metrics(self): """ Test that direct action is needed if the report doesn't contain any metrics. """ quality_report = report.QualityReport(self.__project) self.assertTrue(quality_report.direct_action_needed())
def test_teams(self): """ Test that the report contains the team section. """ team = domain.Team(name='Team') self.__project.add_team(team) quality_report = report.QualityReport(self.__project) self.assertEqual(2, len(quality_report.sections()))
def test_team(self): """ Test that the report has 2 sections when we add a team. """ team = domain.Team(name='Team') self.__project.add_team(team) quality_report = report.QualityReport(self.__project) self.assertEqual(2, len(quality_report.sections()))
def test_products(self): """ Test that the report returns the products. """ product = domain.Product(short_name='FP') self.__project.add_product(product) quality_report = report.QualityReport(self.__project) self.assertEqual([product], quality_report.products())
def setUp(self): self.__project = domain.Project('organization', name='project title') self.__report = report.QualityReport(self.__project)
def test_no_direct_action_needed_when_all_metrics_green(self): """ Test that the report needs no direct action when all metrics are green. """ quality_report = report.QualityReport(self.__project) quality_report.sections() # Generate the report self.assertFalse(quality_report.direct_action_needed())