Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_old_create_job(self):
        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]

        # Execute
        ret_jm = JobManager(mock_app)
        ret_jm.old_create_job(name='test_name',
                              user='******',
                              template_name='template_1')
        mock_template1.create_job.assert_called_with(
            app_workspace='test_app_workspace',
            label='test_label',
            name='test_name',
            user='******',
            user_workspace=mock_user_workspace,
            workspace='test_user_workspace')
Exemplo n.º 4
0
    def test_JobManager_get_job_status_callback_url(self):
        mock_args = mock.MagicMock()
        mock_request = mock.MagicMock()
        mock_job_id = 'foo'

        mgr = JobManager(mock_args)
        mgr.get_job_status_callback_url(mock_request, mock_job_id)
        mock_request.build_absolute_uri.assert_called_once_with(u'/update-job-status/foo/')
Exemplo n.º 5
0
    def test_JobManager_get_job_status_callback_url(self):
        mock_args = mock.MagicMock()
        mock_request = mock.MagicMock()
        mock_job_id = 'foo'

        mgr = JobManager(mock_args)
        mgr.get_job_status_callback_url(mock_request, mock_job_id)
        mock_request.build_absolute_uri.assert_called_once_with(u'/update-job-status/foo/')
Exemplo n.º 6
0
    def test_JobManager_list_job(self, mock_tethys_job):
        mock_args = mock.MagicMock()
        mock_jobs = mock.MagicMock()
        mock_tethys_job.objects.filter().order_by().select_subclasses.return_value = mock_jobs

        mock_user = '******'

        mgr = JobManager(mock_args)
        ret = mgr.list_jobs(user=mock_user)

        self.assertEquals(ret, mock_jobs)
        mock_tethys_job.objects.filter().order_by().select_subclasses.assert_called_once()
Exemplo n.º 7
0
    def test_JobManager_list_job(self, mock_tethys_job):
        mock_args = mock.MagicMock()
        mock_jobs = mock.MagicMock()
        mock_tethys_job.objects.filter().order_by().select_subclasses.return_value = mock_jobs

        mock_user = '******'

        mgr = JobManager(mock_args)
        ret = mgr.list_jobs(user=mock_user)

        self.assertEquals(ret, mock_jobs)
        mock_tethys_job.objects.filter().order_by().select_subclasses.assert_called_once()
Exemplo n.º 8
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')
Exemplo n.º 9
0
    def test_JobManager_get_job(self, mock_tethys_job):
        mock_args = mock.MagicMock()
        mock_app_package = mock.MagicMock()
        mock_args.package = mock_app_package
        mock_jobs = mock.MagicMock()
        mock_tethys_job.objects.get_subclass.return_value = mock_jobs

        mock_job_id = 'fooid'
        mock_user = '******'

        mgr = JobManager(mock_args)
        ret = mgr.get_job(job_id=mock_job_id, user=mock_user)

        self.assertEquals(ret, mock_jobs)
        mock_tethys_job.objects.get_subclass.assert_called_once_with(id='fooid', label=mock_app_package, user='******')
Exemplo n.º 10
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')
Exemplo n.º 11
0
    def test_JobManager_get_job_dne(self, mock_tethys_job):
        mock_args = mock.MagicMock()
        mock_app_package = mock.MagicMock()
        mock_args.package = mock_app_package
        mock_tethys_job.DoesNotExist = TethysJob.DoesNotExist  # Restore original exception
        mock_tethys_job.objects.get_subclass.side_effect = TethysJob.DoesNotExist

        mock_job_id = 'fooid'
        mock_user = '******'

        mgr = JobManager(mock_args)
        ret = mgr.get_job(job_id=mock_job_id, user=mock_user)

        self.assertEquals(ret, None)
        mock_tethys_job.objects.get_subclass.assert_called_once_with(id='fooid', label=mock_app_package, user='******')
Exemplo n.º 12
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')
Exemplo n.º 13
0
    def test_JobManager_get_job_dne(self, mock_tethys_job):
        mock_args = mock.MagicMock()
        mock_app_package = mock.MagicMock()
        mock_args.package = mock_app_package
        mock_tethys_job.DoesNotExist = TethysJob.DoesNotExist  # Restore original exception
        mock_tethys_job.objects.get_subclass.side_effect = TethysJob.DoesNotExist

        mock_job_id = 'fooid'
        mock_user = '******'

        mgr = JobManager(mock_args)
        ret = mgr.get_job(job_id=mock_job_id, user=mock_user)

        self.assertEquals(ret, None)
        mock_tethys_job.objects.get_subclass.assert_called_once_with(id='fooid', label=mock_app_package, user='******')
Exemplo n.º 14
0
    def test_JobManager_get_job(self, mock_tethys_job):
        mock_args = mock.MagicMock()
        mock_app_package = mock.MagicMock()
        mock_args.package = mock_app_package
        mock_jobs = mock.MagicMock()
        mock_tethys_job.objects.get_subclass.return_value = mock_jobs

        mock_job_id = 'fooid'
        mock_user = '******'

        mgr = JobManager(mock_args)
        ret = mgr.get_job(job_id=mock_job_id, user=mock_user)

        self.assertEquals(ret, mock_jobs)
        mock_tethys_job.objects.get_subclass.assert_called_once_with(id='fooid', label=mock_app_package, user='******')
Exemplo n.º 15
0
    def test_JobManager_list_job_value_error(self):

        mgr = JobManager(self.app_model)
        self.assertRaises(ValueError,
                          mgr.list_jobs,
                          user=self.user_model,
                          groups=[self.group_model])
Exemplo n.º 16
0
class TethysJobTestCase(TestCase):
    def setUp(self):
        self.app = TestApp()
        self.job_manager = JobManager(self.app)
        self.user = User.objects.create_user('user', '*****@*****.**',
                                             'pass')

    def test_create_job(self):
        job = self.job_manager.create_empty_job('job', self.user, CondorJob)
        self.assertIsInstance(job, CondorJob,
                              'Empty job is not an instance of CondorJob')
        self.assertIsInstance(job, TethysJob,
                              'Empty job is not an instance of TethysJob')

        self.assertIsInstance(job.extended_properties, dict)

        job.extended_properties['property'] = 'value'

        job.save()

        self.assertDictEqual(job.extended_properties, {'property': 'value'})

        job.process_results = echo

        job.save()

        self.assertEqual(job.process_results('test'), 'test')
        self.assertTrue(hasattr(job.process_results, '__call__'))
Exemplo n.º 17
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')
Exemplo n.º 18
0
class TethysJobTestCase(TestCase):
    def setUp(self):
        self.app = TestApp()
        self.job_manager = JobManager(self.app)
        self.user = User.objects.create_user('user', '*****@*****.**', 'pass')

    def test_create_job(self):
        job = self.job_manager.create_empty_job('job', self.user, CondorJob)
        self.assertIsInstance(job, CondorJob, 'Empty job is not an instance of CondorJob')
        self.assertIsInstance(job, TethysJob, 'Empty job is not an instance of TethysJob')

        self.assertIsInstance(job.extended_properties, dict)

        job.extended_properties['property'] = 'value'


        job.save()

        self.assertDictEqual(job.extended_properties, {'property': 'value'})

        job.process_results = echo

        job.save()

        self.assertEqual(job.process_results('test'), 'test')
        self.assertTrue(hasattr(job.process_results, '__call__'))
Exemplo n.º 19
0
    def test_JobManager_init(self):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'

        ret = JobManager(mock_app)

        # Check Result
        self.assertEqual(mock_app, ret.app)
        self.assertEqual('test_label', ret.label)
Exemplo n.º 20
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')
Exemplo n.º 21
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()
Exemplo n.º 22
0
    def test_old_create_job_key_error(self):
        mock_app = mock.MagicMock()

        mock_name = 'foo'
        mock_user = '******'
        mock_template_name = 'bar'
        mock_app.package = 'test_app_name'

        mgr = JobManager(mock_app)
        self.assertRaises(KeyError, mgr.old_create_job, name=mock_name, user=mock_user,
                          template_name=mock_template_name)
Exemplo n.º 23
0
    def test_old_create_job(self):
        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]

        # Execute
        ret_jm = JobManager(mock_app)
        ret_jm.old_create_job(name='test_name', user='******', template_name='template_1')
        mock_template1.create_job.assert_called_with(app_workspace='test_app_workspace', label='test_label',
                                                     name='test_name', user='******',
                                                     user_workspace=mock_user_workspace,
                                                     workspace='test_user_workspace')
Exemplo n.º 24
0
    def test_JobManager_init(self):
        mock_app = mock.MagicMock()
        mock_app.package = 'test_label'
        mock_app.get_app_workspace.return_value = 'test_app_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]

        # Execute
        ret = JobManager(mock_app)

        # Check Result
        self.assertEqual(mock_app, ret.app)
        self.assertEqual('test_label', ret.label)
        self.assertEqual('test_app_workspace', ret.app_workspace)
        self.assertEqual(mock_template1, ret.job_templates['template_1'])
        self.assertEqual(mock_template2, ret.job_templates['template_2'])
Exemplo n.º 25
0
    def test_JobManager_replace_workspaces(self):
        mock_app_workspace = mock.MagicMock()
        mock_user_workspace = mock.MagicMock()
        mock_app_workspace.path = 'replace_app'
        mock_user_workspace.path = 'replace_user'

        mock_parameters = {str: '/foo/app/$(APP_WORKSPACE)/foo',
                           dict: {'foo': '/foo/user/$(USER_WORKSPACE)/foo'},
                           list: ['/foo/app/$(APP_WORKSPACE)/foo', '/foo/user/$(USER_WORKSPACE)/foo'],
                           tuple: ('/foo/app/$(APP_WORKSPACE)/foo', '/foo/user/$(USER_WORKSPACE)/foo'),
                           int: 1
                           }

        expected = {str: '/foo/app/replace_app/foo',
                    dict: {'foo': '/foo/user/replace_user/foo'},
                    list: ['/foo/app/replace_app/foo', '/foo/user/replace_user/foo'],
                    tuple: ('/foo/app/replace_app/foo', '/foo/user/replace_user/foo'),
                    int: 1
                    }

        ret = JobManager._replace_workspaces(mock_parameters, mock_app_workspace, mock_user_workspace)
        self.assertEquals(ret, expected)
Exemplo n.º 26
0
    def test_JobManager_replace_workspaces(self):
        mock_app_workspace = mock.MagicMock()
        mock_user_workspace = mock.MagicMock()
        mock_app_workspace.path = 'replace_app'
        mock_user_workspace.path = 'replace_user'

        mock_parameters = {str: '/foo/app/$(APP_WORKSPACE)/foo',
                           dict: {'foo': '/foo/user/$(USER_WORKSPACE)/foo'},
                           list: ['/foo/app/$(APP_WORKSPACE)/foo', '/foo/user/$(USER_WORKSPACE)/foo'],
                           tuple: ('/foo/app/$(APP_WORKSPACE)/foo', '/foo/user/$(USER_WORKSPACE)/foo'),
                           int: 1
                           }

        expected = {str: '/foo/app/replace_app/foo',
                    dict: {'foo': '/foo/user/replace_user/foo'},
                    list: ['/foo/app/replace_app/foo', '/foo/user/replace_user/foo'],
                    tuple: ('/foo/app/replace_app/foo', '/foo/user/replace_user/foo'),
                    int: 1
                    }

        ret = JobManager._replace_workspaces(mock_parameters, mock_app_workspace, mock_user_workspace)
        self.assertEquals(ret, expected)
Exemplo n.º 27
0
    def test_JobManager_list_job_with_user(self):

        mgr = JobManager(self.app_model)
        ret = mgr.list_jobs(user=self.user_model)

        self.assertEqual(ret[0], self.tethysjob)
Exemplo n.º 28
0
 def setUp(self):
     self.app = TestApp()
     self.job_manager = JobManager(self.app)
     self.user = User.objects.create_user('user', '*****@*****.**',
                                          'pass')
Exemplo n.º 29
0
    def test_JobManager_list_job_with_groups(self):

        mgr = JobManager(self.app_model)
        ret = mgr.list_jobs(groups=[self.group_model])

        self.assertEqual(ret[0], self.tethysjob)
Exemplo n.º 30
0
 def setUp(self):
     self.app = TestApp()
     self.job_manager = JobManager(self.app)
     self.user = User.objects.create_user('user', '*****@*****.**', 'pass')