def test_scale_pre_steps_database_operation_error(self, mock_makedirs, mock_db, mock_sys_exit):
        '''Tests executing scale_pre_steps when a database operation error occurs.'''

        # Set up mocks
        mock_db.side_effect = OperationalError()

        # Call method to test
        cmd = PreCommand()
        cmd.run_from_argv(['manage.py', 'scale_pre_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(PRE_DB_OP_EXIT_CODE)
    def test_scale_pre_steps_io_error(self, mock_file_system, mock_job_exe, mock_sys_exit):
        '''Tests executing scale_pre_steps when an IO error occurs.'''

        # Set up mocks
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_pre_steps.side_effect = IOError()

        # Call method to test
        cmd = PreCommand()
        cmd.run_from_argv(['manage.py', 'scale_pre_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(PRE_IO_EXIT_CODE)
Example #3
0
    def test_scale_pre_steps_database_error(self, mock_db, mock_sys_exit):
        """Tests executing scale_pre_steps when a database error occurs."""

        # Set up mocks
        mock_db.side_effect = DatabaseError()

        # Call method to test
        cmd = PreCommand()
        cmd.run_from_argv(['manage.py', 'scale_pre_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(PRE_DB_EXIT_CODE)
    def test_scale_pre_steps_successful(self, mock_file_system, mock_job_exe, mock_chmod, mock_sysexit, mock_subprocess):
        '''Tests successfully executing scale_pre_steps.'''

        # Set up mocks
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.fully_populate_command_argument.return_value = FILLED_IN_CMD
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_docker_image.return_value = None

        # Call method to test
        cmd = PreCommand()
        cmd.run_from_argv(['manage.py', 'scale_pre_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_job_exe.objects.pre_steps_command_arguments.assert_called_with(self.job_exe.id, FILLED_IN_CMD)
Example #5
0
    def test_scale_pre_steps_io_error(self, mock_env_vars, mock_job_exe,
                                      mock_sys_exit, mock_JobData):
        """Tests executing scale_pre_steps when an IO error occurs."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.seed_job.id) if name == 'SCALE_JOB_ID' else str(
                self.seed_exe.exe_num)

        mock_env_vars.side_effect = get_env_vars
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.needs_input_metadata.return_value = None
        mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_pre_steps.side_effect = IOError(
        )

        # Call method to test
        cmd = PreCommand()
        cmd.run_from_argv(['manage.py', 'scale_pre_steps'])

        # Check results
        mock_sys_exit.assert_called_with(ScaleIOError().exit_code)
Example #6
0
    def test_generate_input_metadata(self, mock_dump, mock_open, mock_mkdir):

        cmd = PreCommand()

        cmd._generate_input_metadata(self.seed_exe_meta)
        mock_dump.assert_called_once()
        args, kwargs = mock_dump.call_args
        metadata_dict = {'JOB': {}}
        metadata_dict['JOB']['input_1'] = 'my_val'
        metadata_dict['JOB']['input_2'] = [
            serialize(
                ScaleFile.objects.get_details(file_id=self.file_1.id)).data
        ]
        metadata_dict['JOB']['input_3'] = [
            serialize(
                ScaleFile.objects.get_details(file_id=self.file_2.id)).data,
            serialize(
                ScaleFile.objects.get_details(file_id=self.file_3.id)).data
        ]
        self.maxDiff = None
        self.assertDictEqual(args[0]['JOB']['input_2'][0],
                             metadata_dict['JOB']['input_2'][0])
        self.assertDictEqual(args[0], metadata_dict)