示例#1
0
 def __init__(self):
     self.selection_strategy = AutomaticCorrectionSelectionStrategyThroughRestApi(
         SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS)
     self.setup_enviroment = SetupEnviroment()
     self.run_script_command = RunScriptCommand()
     self.publish_result_visitors = (
         PublishResultsVisitorWeb(SERIALIZER_AUTH_USER,
                                  SERIALIZER_AUTH_PASS),
         PublishResultsVisitorMail(SERIALIZER_AUTH_USER,
                                   SERIALIZER_AUTH_PASS),
     )
 def testAutomaticCorrectionSelectionStrategyShouldInvokeRestApiHelperMethod(self):
     user = Mock()
     password = Mock()
     rest_api_helper = Mock()
     return_value = (Mock(),)
     rest_api_helper.get_automatic_corrections.return_value = return_value
     automatic_correction_selection_strategy = AutomaticCorrectionSelectionStrategyThroughRestApi(user, password)
     automatic_correction_selection_strategy.rest_api_helper = rest_api_helper
     
     actual_return_value = automatic_correction_selection_strategy.get_automatic_corrections()
     
     self.assertEqual(actual_return_value, return_value)
     rest_api_helper.get_automatic_corrections.assert_called()
示例#3
0
    def testAutomaticCorrectionSelectionStrategyShouldInvokeRestApiHelperMethod(
            self):
        user = Mock()
        password = Mock()
        rest_api_helper = Mock()
        return_value = (Mock(), )
        rest_api_helper.get_automatic_corrections.return_value = return_value
        automatic_correction_selection_strategy = AutomaticCorrectionSelectionStrategyThroughRestApi(
            user, password)
        automatic_correction_selection_strategy.rest_api_helper = rest_api_helper

        actual_return_value = automatic_correction_selection_strategy.get_automatic_corrections(
        )

        self.assertEqual(actual_return_value, return_value)
        rest_api_helper.get_automatic_corrections.assert_called()
class AutomaticCorrectionRunner():
    """
    
    This class is intended to be in charge of running the automated check on the
    queued deliveries from the seal.model application model. It is thought to be
    called in order to run the automatic correction script file for each delivery which has
    not yet been checked, and for the Practices which has a script.
    
    """
    
    TMP_DIR = managepath.get_instance().get_automatic_correction_tmp_dir()
    SUCCESSFULL_RESULTS_KEY = "successfull"
    FAILED_RESULTS_KEY = "failed"
    
    def __init__(self):
        self.selection_strategy = AutomaticCorrectionSelectionStrategyThroughRestApi(SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS)
        self.setup_enviroment = SetupEnviroment()
        self.run_script_command = RunScriptCommand()
        self.publish_result_visitors = (PublishResultsVisitorWeb(SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS), 
                                        PublishResultsVisitorMail(SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS),)
    
    def clean_up_tmp_dir(self):
        shutil.rmtree(AutomaticCorrectionRunner.TMP_DIR, ignore_errors=True)
    
    def run(self):
        """Runs the corresponding script for every Delivery which has not yet been run."""
        
        results = {AutomaticCorrectionRunner.SUCCESSFULL_RESULTS_KEY : 0, AutomaticCorrectionRunner.FAILED_RESULTS_KEY : 0}
        pending_automatic_corrections = self.selection_strategy.get_automatic_corrections()
        for pending_automatic_correction in pending_automatic_corrections:
            
            try:
                self.setup_enviroment.run(pending_automatic_correction, AutomaticCorrectionRunner.TMP_DIR)
                self.run_script_command.set_script(os.path.join(AutomaticCorrectionRunner.TMP_DIR, os.path.basename(pending_automatic_correction.script)))
                script_result = self.run_script_command.execute()
            except Exception, e:
                script_result = ScriptResult()
                script_result.captured_stdout = "An error has occurred when running the automatic correction process. Error information: " + str(e)
                script_result.exit_value = 2
                
            script_result.automatic_correction = pending_automatic_correction
            for visitor in self.publish_result_visitors:
                script_result.accept(visitor)
            self.clean_up_tmp_dir()
            if(script_result.exit_value == 0):
                results[AutomaticCorrectionRunner.SUCCESSFULL_RESULTS_KEY] += 1
            else :
                results[AutomaticCorrectionRunner.FAILED_RESULTS_KEY] += 1
        return results;
 def __init__(self):
     self.selection_strategy = AutomaticCorrectionSelectionStrategyThroughRestApi(SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS)
     self.setup_enviroment = SetupEnviroment()
     self.run_script_command = RunScriptCommand()
     self.publish_result_visitors = (PublishResultsVisitorWeb(SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS), 
                                     PublishResultsVisitorMail(SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS),)
示例#6
0
class AutomaticCorrectionRunner():
    """
    
    This class is intended to be in charge of running the automated check on the
    queued deliveries from the seal.model application model. It is thought to be
    called in order to run the automatic correction script file for each delivery which has
    not yet been checked, and for the Practices which has a script.
    
    """

    TMP_DIR = managepath.get_instance().get_automatic_correction_tmp_dir()
    SUCCESSFULL_RESULTS_KEY = "successfull"
    FAILED_RESULTS_KEY = "failed"

    def __init__(self):
        self.selection_strategy = AutomaticCorrectionSelectionStrategyThroughRestApi(
            SERIALIZER_AUTH_USER, SERIALIZER_AUTH_PASS)
        self.setup_enviroment = SetupEnviroment()
        self.run_script_command = RunScriptCommand()
        self.publish_result_visitors = (
            PublishResultsVisitorWeb(SERIALIZER_AUTH_USER,
                                     SERIALIZER_AUTH_PASS),
            PublishResultsVisitorMail(SERIALIZER_AUTH_USER,
                                      SERIALIZER_AUTH_PASS),
        )

    def clean_up_tmp_dir(self):
        shutil.rmtree(AutomaticCorrectionRunner.TMP_DIR, ignore_errors=True)

    def run(self):
        """Runs the corresponding script for every Delivery which has not yet been run."""

        results = {
            AutomaticCorrectionRunner.SUCCESSFULL_RESULTS_KEY: 0,
            AutomaticCorrectionRunner.FAILED_RESULTS_KEY: 0
        }
        pending_automatic_corrections = self.selection_strategy.get_automatic_corrections(
        )
        for pending_automatic_correction in pending_automatic_corrections:

            try:
                self.setup_enviroment.run(pending_automatic_correction,
                                          AutomaticCorrectionRunner.TMP_DIR)
                self.run_script_command.set_script(
                    os.path.join(
                        AutomaticCorrectionRunner.TMP_DIR,
                        os.path.basename(pending_automatic_correction.script)))
                script_result = self.run_script_command.execute()
            except Exception, e:
                script_result = ScriptResult()
                script_result.captured_stdout = "An error has occurred when running the automatic correction process. Error information: " + str(
                    e)
                script_result.exit_value = 2

            script_result.automatic_correction = pending_automatic_correction
            for visitor in self.publish_result_visitors:
                script_result.accept(visitor)
            self.clean_up_tmp_dir()
            if (script_result.exit_value == 0):
                results[AutomaticCorrectionRunner.SUCCESSFULL_RESULTS_KEY] += 1
            else:
                results[AutomaticCorrectionRunner.FAILED_RESULTS_KEY] += 1
        return results