Ejemplo n.º 1
0
    def test_JobManager_create_job_custom_class(self, mock_cj):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        # Execute
        ret_jm = JobManager(mock_app)
        ret_jm.create_job(name='test_name', user='******', job_type=mock_cj)
        mock_cj.assert_called_with(label='test_label', name='test_name', user='******',
                                   workspace='test_user_workspace')
Ejemplo n.º 2
0
    def test_JobManager_create_job_template_none(self, mock_cj):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        with mock.patch.dict('tethys_compute.job_manager.JOB_TYPES', {'CONDOR': mock_cj}):
            # Execute
            ret_jm = JobManager(mock_app)
            ret_jm.create_job(name='test_name', user='******', job_type='CONDOR')
            mock_cj.assert_called_with(label='test_label', name='test_name', user='******',
                                       workspace='test_user_workspace')
Ejemplo n.º 3
0
    def test_JobManager_create_job_template_none(self, mock_cj):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        with mock.patch.dict('tethys_compute.job_manager.JOB_TYPES', {'CONDOR': mock_cj}):
            # Execute
            ret_jm = JobManager(mock_app)
            ret_jm.create_job(name='test_name', user='******', job_type='CONDOR')
            mock_cj.assert_called_with(label='test_label', name='test_name', user='******',
                                       workspace='test_user_workspace')
Ejemplo n.º 4
0
    def test_JobManager_create_job_custom_class(self, mock_cj):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        # Execute
        ret_jm = JobManager(mock_app)
        ret_jm.create_job(name='test_name', user='******', job_type=mock_cj)
        mock_cj.assert_called_with(label='test_label',
                                   name='test_name',
                                   user='******',
                                   workspace='test_user_workspace')
Ejemplo n.º 5
0
    def test_JobManager_create_job_template(self, mock_ocj, mock_warn,
                                            mock_print):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        mock_template1 = mock.MagicMock()
        mock_template1.name = 'template_1'
        mock_template2 = mock.MagicMock()
        mock_template2.name = 'template_2'

        mock_app.job_templates.return_value = [mock_template1, mock_template2]

        mock_ocj.return_value = 'old_create_job_return_value'
        # Execute
        ret_jm = JobManager(mock_app)
        ret_job = ret_jm.create_job(name='test_name',
                                    user='******',
                                    template_name='template_1')

        # Check result
        self.assertEqual('old_create_job_return_value', ret_job)

        mock_ocj.assert_called_with('test_name', 'test_user', 'template_1')

        # Check if warning message is called
        check_msg = 'The job template "{0}" was used in the "{1}" app. Using job templates is now deprecated.'.format(
            'template_1', 'test_label')
        rts_call_args = mock_warn.warn.call_args_list
        self.assertEqual(check_msg, rts_call_args[0][0][0])
        mock_print.assert_called_with(check_msg)
Ejemplo n.º 6
0
    def test_JobManager_create_job_template(self, mock_ocj, mock_warn, mock_print):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        mock_template1 = mock.MagicMock()
        mock_template1.name = 'template_1'
        mock_template2 = mock.MagicMock()
        mock_template2.name = 'template_2'

        mock_app.job_templates.return_value = [mock_template1, mock_template2]

        mock_ocj.return_value = 'old_create_job_return_value'
        # Execute
        ret_jm = JobManager(mock_app)
        ret_job = ret_jm.create_job(name='test_name', user='******', template_name='template_1')

        # Check result
        self.assertEqual('old_create_job_return_value', ret_job)

        mock_ocj.assert_called_with('test_name', 'test_user', 'template_1')

        # Check if warning message is called
        check_msg = 'The job template "{0}" was used in the "{1}" app. Using job templates is now deprecated.'.format(
            'template_1', 'test_label'
        )
        rts_call_args = mock_warn.warn.call_args_list
        self.assertEqual(check_msg, rts_call_args[0][0][0])
        mock_print.assert_called_with(check_msg)
Ejemplo n.º 7
0
    def test_JobManager_create_job_string(self, mock_cj):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_workspace'
        mock_user_workspace = mock.MagicMock()

        mock_app.get_user_workspace.return_value = mock_user_workspace
        mock_app.get_user_workspace().path = 'test_user_workspace'

        # Execute
        ret_jm = JobManager(mock_app)
        with mock.patch.dict(JOB_TYPES, {'CONDOR': mock_cj}):
            ret_jm.create_job(name='test_name',
                              user='******',
                              job_type='CONDOR')
        mock_cj.assert_called_with(label='test_label',
                                   name='test_name',
                                   user='******',
                                   workspace='test_user_workspace')
Ejemplo n.º 8
0
    def test_JobManager_create_job_custom_class(self):
        self.app_model.get_user_workspace = mock.MagicMock()
        self.app_model.get_user_workspace().path = 'test_user_workspace'

        # Execute
        ret_jm = JobManager(self.app_model)
        ret_job = ret_jm.create_job(
            name='test_create_tethys_job',
            user=self.user_model,
            job_type=TethysJob,
            groups=self.group_model,
        )

        self.assertEqual(ret_job.name, 'test_create_tethys_job')
        self.assertEqual(ret_job.user, self.user_model)
        self.assertEqual(ret_job.label, 'test_app_job_manager')
        self.assertIn(self.group_model, ret_job.groups.all())

        ret_job.delete()