Esempio n. 1
0
    def __init__(self, report_id, created, results, file_manager=None):
        """
        TODO: Add dependency injection for the file_manager,
        we are passing it on the constructor for easier testing
        but the object should come from the application context
        
        Parameters:
            report_id   : identifier of the report, needed to find
                          directory to write to if report is recurrent
            created     : date report was created, used to identify a single run of
                          a recurrent report
            results     : data to write to disk
            file_manager: PublicReportFileManager, adding to constructor
                          for easy testing.
        """

        self.report_id = report_id
        self.created_string = format_date_for_public_report_file(created)
        self.results = json_string(results)

        self.file_manager = file_manager or PublicReportFileManager(
            task_logger, get_absolute_path())

        # there should not be a need to call these functions more than once
        self.path = self.file_manager.get_public_report_path(self.report_id,
                                                             recurrent=True,
                                                             create=True)

        # TODO use file manager to get function when function is available
        self.filepath = os.path.join(self.path, self.created_string)
 def __init__(self, report_id, created, results, file_manager=None):
     """
     TODO: Add dependency injection for the file_manager,
     we are passing it on the constructor for easier testing
     but the object should come from the application context
     
     Parameters:
         report_id   : identifier of the report, needed to find
                       directory to write to if report is recurrent
         created     : date report was created, used to identify a single run of
                       a recurrent report
         results     : data to write to disk
         file_manager: PublicReportFileManager, adding to constructor
                       for easy testing.
     """
     
     self.report_id = report_id
     self.created_string = format_date_for_public_report_file(created)
     self.results = json_string(results)
     
     self.file_manager = file_manager or PublicReportFileManager(task_logger,
                                                                 get_absolute_path())
               
     # there should not be a need to call these functions more than once
     self.path = self.file_manager.get_public_report_path(self.report_id,
                                                          recurrent=True,
                                                          create=True)
     
     # TODO use file manager to get function when function is available
     self.filepath = os.path.join(self.path, self.created_string)
 def create_coalesced_report(self):
     """
     Creates coalesced report.
     
     for CR: should we create the report everytime or make sure to create it
     only if coalesced report on disk is more than one day old?.
     """
     data = self.file_manager.coalesce_recurrent_reports(self.report_id)
     
     if data is not None:
         coalesced_report_file_path = os.path.join(self.path, COALESCED_REPORT_FILE)
         self.file_manager.write_data(coalesced_report_file_path, json_string(data))
Esempio n. 4
0
    def create_coalesced_report(self):
        """
        Creates coalesced report.
        
        for CR: should we create the report everytime or make sure to create it
        only if coalesced report on disk is more than one day old?.
        """
        data = self.file_manager.coalesce_recurrent_reports(self.report_id)

        if data is not None:
            coalesced_report_file_path = os.path.join(self.path,
                                                      COALESCED_REPORT_FILE)
            self.file_manager.write_data(coalesced_report_file_path,
                                         json_string(data))
Esempio n. 5
0
 def test_happy_case(self):
     """
     Create a report on disk
     """
     today = date.today()
     concatenated_report_filepath = os.path.join(self.fake_path,
                                                 COALESCED_REPORT_FILE)
     wr = WriteReportTask('123', today, self.results, self.file_manager)
     wr.run()
     assert_equals(self.file_manager.write_data.call_count, 2)
     assert_equals(self.file_manager.get_public_report_path.call_count, 1)
     assert_equals(self.file_manager.coalesce_recurrent_reports.call_count, 1)
     assert_equals(self.file_manager.remove_old_report_files.call_count, 1)
     self.file_manager.write_data.assert_called_with(concatenated_report_filepath,
                                                     json_string(self.results))