コード例 #1
0
ファイル: test_scale_pre_steps.py プロジェクト: wong-j/scale
    def test_scale_pre_steps_nfs_error(self, mock_job_exe, mock_sys_exit):
        """Tests executing scale_pre_steps when an NFS 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 = NfsError()

        # 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_NFS_EXIT_CODE)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
ファイル: test_scale_pre_steps.py プロジェクト: wong-j/scale
    def test_scale_pre_steps_database_operation_error(self, 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)
コード例 #5
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)
コード例 #6
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(ScaleDatabaseError().exit_code)
コード例 #7
0
    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)
コード例 #8
0
ファイル: test_scale_pre_steps.py プロジェクト: wong-j/scale
    def test_scale_pre_steps_successful(self, mock_job_exe, mock_sysexit):
        """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)
コード例 #9
0
    def test_seed_pre_steps_no_workspace(self, mock_env_vars, mock_sysexit):

        # 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

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

        # Make sure we get an exit code of 1
        mock_sysexit.assert_called_with(1)
コード例 #10
0
    def test_scale_pre_steps_successful(self, mock_env_vars, mock_sysexit):
        """Tests successfully executing scale_pre_steps."""

        # 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

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

        # Make sure sys.exit() was never called
        self.assertItemsEqual(mock_sysexit.call_args_list, [])
コード例 #11
0
    def test_scale_pre_steps_database_operation_error(self, mock_env_vars,
                                                      mock_db, mock_sys_exit):
        """Tests executing scale_pre_steps when a database operation 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_db.side_effect = OperationalError()

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

        # Check results
        mock_sys_exit.assert_called_with(ScaleOperationalError().exit_code)
コード例 #12
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.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)
コード例 #13
0
    def test_seed_pre_steps_no_workspace(self, mock_env_vars, mock_sysexit):

        seed_exe = job_utils.create_job_exe(job=self.seed_job,
                                            status='RUNNING',
                                            timeout=60,
                                            queued=now())

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

        mock_env_vars.side_effect = get_env_vars

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

        # Make sure we get an exit code of 1
        mock_sysexit.assert_called_with(1)