当前位置: 首页>>代码示例>>Python>>正文


Python MagicMock.request方法代码示例

本文整理汇总了Python中unittest.mock.MagicMock.request方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.request方法的具体用法?Python MagicMock.request怎么用?Python MagicMock.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.MagicMock的用法示例。


在下文中一共展示了MagicMock.request方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_201_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_201_run(self):
        rc = MagicMock(spec=RestClient)
        pilots = {'a':{}}
        # try tasks error
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/dataset_summaries'):
                return {'processing':['foo']}
            else:
                raise Exception()
        rc.request = client
        with self.assertRaises(Exception):
            await reset_tasks.run(rc, debug=True)

        # check it normally hides the error
        await reset_tasks.run(rc, debug=False)

        # try dataset level error
        async def client(method, url, args=None):
            raise Exception()
        rc.request = client
        with self.assertRaises(Exception):
            await reset_tasks.run(rc, debug=True)

        # check it normally hides the error
        await reset_tasks.run(rc, debug=False)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:28,代码来源:reset_tasks_test.py

示例2: test_210_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_210_run(self):
        rc = MagicMock(spec=RestClient)
        job_ids = list(range(2))
        task_ids = list(range(4))
        jobs = []
        tasks = []
        async def client(method, url, args=None):
            if url.startswith('/dataset_summaries'):
                return {'processing':['foo']}
            elif url == '/datasets/foo':
                client.called = True
                return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
            elif url.startswith('/datasets/foo/task_counts'):
                return {'waiting':30000}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        await buffer_jobs_tasks.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(jobs)
        self.assertFalse(tasks)

        async def client(method, url, args=None):
            if url.startswith('/dataset_summaries'):
                return {'processing':['foo']}
            elif url == '/datasets/foo':
                client.called = True
                return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
            elif url.startswith('/datasets/foo/task_counts'):
                return {}
            elif url == '/datasets/foo/jobs':
                return {0:{},1:{}}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        await buffer_jobs_tasks.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(jobs)
        self.assertFalse(tasks)

        async def client(method, url, args=None):
            if url.startswith('/dataset_summaries'):
                client.called = True
                return {}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        await buffer_jobs_tasks.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(jobs)
        self.assertFalse(tasks)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:56,代码来源:buffer_jobs_tasks_test.py

示例3: test_200_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_200_run(self):
        rc = MagicMock(spec=RestClient)
        pilots = {}
        jobs = {}
        tasks = defaultdict(dict)
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/dataset_summaries/status'):
                return {'processing':['foo']}
            elif url.startswith('/datasets/foo/job_counts/status'):
                return jobs
            elif url.startswith('/datasets/foo/task_counts/name_status'):
                client.called = True
                return tasks
            if url.startswith('/datasets/foo'):
                return {'dataset':123,'status':'processing'}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        mon = MagicMock(spec=StatsClient)

        await dataset_monitor.run(rc, mon, debug=True)
        self.assertTrue(client.called)
        self.assertTrue(mon.gauge.called)

        jobs['processing'] = 1
        mon.reset_mock()
        await dataset_monitor.run(rc, mon, debug=True)
        self.assertTrue(mon.gauge.called)

        tasks['generate']['queued'] = 1
        mon.reset_mock()
        await dataset_monitor.run(rc, mon, debug=True)
        self.assertTrue(mon.gauge.called)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:37,代码来源:dataset_monitor_test.py

示例4: test_200_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_200_run(self):
        rc = MagicMock(spec=RestClient)
        pilots = {}
        dataset_summaries = {'processing':['foo']}
        tasks = {}
        pilots = {}
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/dataset_summaries'):
                return dataset_summaries
            elif url.startswith('/pilots'):
                return pilots
            elif url.startswith('/datasets/foo/task_summaries'):
                return tasks
            elif url == '/datasets/foo/tasks/bar/status' and method == 'PUT':
                client.called = True
                return {}
            else:
                raise Exception()
        client.called = False
        rc.request = client

        await non_active_tasks.run(rc, debug=True)
        self.assertFalse(client.called)

        tasks['processing'] = ['bar']
        await non_active_tasks.run(rc, debug=True)
        self.assertTrue(client.called)

        client.called = False
        del dataset_summaries['processing']
        dataset_summaries['truncated'] = ['foo']
        pilots['a'] = {'tasks':['bar']}
        await non_active_tasks.run(rc, debug=True)
        self.assertFalse(client.called)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:37,代码来源:non_active_tasks_test.py

示例5: test_200_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_200_run(self, gridftp):
        rc = MagicMock(spec=RestClient)
        jobs = {}
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/datasets?'):
                return {'0':{'dataset_id':'0', 'dataset':0}}
            elif url.startswith('/datasets/0/jobs'):
                client.called = True
                return jobs
            else:
                raise Exception()
        client.called = False
        rc.request = client
        gridftp.list.return_value = []
        
        await job_temp_cleaning.run(rc, {}, self.executor, debug=True)
        self.assertFalse(client.called)

        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertFalse(client.called)

        gridftp.list.side_effect = [[FakeFile('0')], [FakeFile('1')]]
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(gridftp.rmtree.called)

        logger.info('try deleting completed job')
        client.called = False
        jobs['bar'] = {'job_index':1,'status':'complete'}
        gridftp.list.side_effect = [[FakeFile('0')], [FakeFile('1')]]
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertTrue(client.called)
        self.assertTrue(gridftp.rmtree.called)
        self.assertEqual(gridftp.rmtree.call_args[0][0], 'foo/0/1')

        logger.info('skip suspended job')
        client.called = False
        jobs['bar'] = {'job_index':1,'status':'suspended','status_changed':datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')}
        gridftp.list.side_effect = [[FakeFile('0')], [FakeFile('1')]]
        gridftp.rmtree.reset_mock()
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(gridftp.rmtree.called)

        logger.info('try deleting old suspended job')
        client.called = False
        jobs['bar'] = {'job_index':1,'status':'suspended','status_changed':
                       (datetime.utcnow()-timedelta(days=100)).strftime('%Y-%m-%dT%H:%M:%S')}
        gridftp.list.side_effect = [[FakeFile('0')], [FakeFile('1')]]
        gridftp.rmtree.reset_mock()
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertTrue(client.called)
        self.assertTrue(gridftp.rmtree.called)
        self.assertEqual(gridftp.rmtree.call_args[0][0], 'foo/0/1')
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:57,代码来源:job_temp_cleaning_test.py

示例6: test_201_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_201_run(self):
        rc = MagicMock(spec=RestClient)
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            raise Exception()
        rc.request = client
        mon = MagicMock(spec=StatsClient)
        with self.assertRaises(Exception):
            await dataset_monitor.run(rc, mon, debug=True)

        # check it normally hides the error
        await dataset_monitor.run(rc, mon, debug=False)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:14,代码来源:dataset_monitor_test.py

示例7: test_205_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
 async def test_205_run(self):
     rc = MagicMock(spec=RestClient)
     job_ids = list(range(2,4))
     task_ids = list(range(4,8))
     jobs = []
     tasks = []
     async def client(method, url, args=None):
         if url.startswith('/dataset_summaries'):
             return {'processing':['foo']}
         elif url == '/datasets/foo':
             client.called = True
             return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
         elif url == '/datasets/foo/jobs':
             return {}
         elif url.startswith('/datasets/foo/task_counts'):
             return {}
         elif url.startswith('/datasets/bar/tasks'):
             return {
                 0:{'task_id':0,'name':'generate','task_index':0},
                 1:{'task_id':1,'name':'filter','task_index':1},
                 2:{'task_id':2,'name':'generate','task_index':2},
                 3:{'task_id':3,'name':'filter','task_index':3},
             }
         elif url.startswith('/config'):
             return {'steering':{
                 'parameters': {'test':'$eval(3+2.4)'}
             },'options':{},
             'tasks': [
                 {'name':'a','requirements':{'cpu':'$eval(1+1)'},'depends':[]},
                 {'name':'b','requirements':{'memory':'$eval($steering(test)+$(job))'},'depends':['a']},
             ]}
         elif url == '/jobs' and method == 'POST':
             jobs.append(args)
             return {'result': job_ids.pop(0)}
         elif url == '/tasks' and method == 'POST':
             tasks.append(args)
             return {'result': task_ids.pop(0)}
         else:
             raise Exception()
     client.called = False
     rc.request = client
     await buffer_jobs_tasks.run(rc, debug=True)
     self.assertTrue(client.called)
     self.assertTrue(len(jobs) == 2)
     self.assertTrue(len(tasks) == 4)
     self.assertEqual([2,2,3,3], [t['job_id'] for t in tasks])
     self.assertEqual([2,1,2,1], [t['requirements']['cpu'] for t in tasks])
     self.assertEqual([1.0,5.4,1.0,6.4], [t['requirements']['memory'] for t in tasks])
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:50,代码来源:buffer_jobs_tasks_test.py

示例8: test_300_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_300_run(self):
        rc = MagicMock(spec=RestClient)
        job_ids = list(range(2))
        task_ids = list(range(4))
        jobs = []
        tasks = []
        async def client(method, url, args=None):
            if url.startswith('/dataset_summaries'):
                client.called = True
                return {'processing':['foo']}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        with self.assertRaises(Exception):
            await buffer_jobs_tasks.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(jobs)
        self.assertFalse(tasks)

        # internally catch the error
        await buffer_jobs_tasks.run(rc)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:24,代码来源:buffer_jobs_tasks_test.py

示例9: test_201_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_201_run(self, gridftp):
        rc = MagicMock(spec=RestClient)
        jobs = {}
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/datasets?'):
                return {'0':{'dataset_id':'0', 'dataset':0}}
            elif url.startswith('/datasets/0/jobs'):
                client.called = True
                return jobs
            else:
                raise Exception()
        rc.request = client

        gridftp.list.side_effect = [[FakeFile('0')], [FakeFile('foobar')]]
        jobs['bar'] = {'job_index':1,'status':'suspended','status_changed':
                       (datetime.utcnow()-timedelta(days=100)).isoformat()}
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertTrue(client.called)
        self.assertFalse(gridftp.rmtree.called)

        gridftp.list.side_effect = [[FakeFile('0')], [FakeFile('1')]]
        jobs['bar'] = {'job_index':1,'status':'suspended','status_changed':
                       (datetime.utcnow()-timedelta(days=100)).isoformat()}
        gridftp.rmtree.side_effect = Exception()
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)
        self.assertTrue(client.called)
        self.assertTrue(gridftp.rmtree.called)
        self.assertEqual(gridftp.rmtree.call_args[0][0], 'foo/0/1')

        gridftp.list.side_effect = Exception()
        jobs['bar'] = {'job_index':1,'status':'suspended','status_changed':
                       (datetime.utcnow()-timedelta(days=100)).isoformat()}
        with self.assertRaises(Exception):
            await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=True)

        # check it normally hides the error
        await job_temp_cleaning.run(rc, self.cfg, self.executor, debug=False)
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:40,代码来源:job_temp_cleaning_test.py

示例10: test_200_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_200_run(self):
        rc = MagicMock(spec=RestClient)
        job_counts = {}
        dataset_summaries = {'processing':['foo']}
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/dataset_summaries'):
                return dataset_summaries
            elif url == '/datasets/foo':
                return {'jobs_submitted':2, 'tasks_submitted':2}
            elif url.startswith('/datasets/foo/job_counts'):
                return job_counts
            elif url == '/datasets/foo/status' and method == 'PUT':
                client.called = True
                client.status = args['status']
                return {}
            else:
                raise Exception()
        client.called = False
        client.status = None
        rc.request = client

        logger.info('test non-buffered')
        await dataset_completion.run(rc, debug=True)
        self.assertFalse(client.called)

        logger.info('test processing')
        job_counts['processing'] = 2
        await dataset_completion.run(rc, debug=True)
        self.assertFalse(client.called)

        logger.info('test errors')
        job_counts['errors'] = 2
        del job_counts['processing']
        await dataset_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'errors')

        logger.info('test processing and suspended')
        del job_counts['errors']
        job_counts['processing'] = 1
        job_counts['suspended'] = 1
        client.called = False
        client.status = None
        await dataset_completion.run(rc, debug=True)
        self.assertFalse(client.called)

        logger.info('test suspended')
        del job_counts['processing']
        job_counts['suspended'] = 1
        job_counts['complete'] = 1
        await dataset_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'suspended')

        logger.info('test complete')
        del job_counts['suspended']
        job_counts['complete'] = 2
        client.called = False
        client.status = None
        await dataset_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'complete')

        logger.info('test truncated dataset')
        del dataset_summaries['processing']
        dataset_summaries['truncated'] = ['foo']
        client.called = False
        client.status = None
        await dataset_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'complete')
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:74,代码来源:dataset_completion_test.py

示例11: test_200_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
 async def test_200_run(self):
     rc = MagicMock(spec=RestClient)
     job_ids = list(range(2))
     task_ids = list(range(4))
     jobs = []
     tasks = []
     async def client(method, url, args=None):
         if url.startswith('/dataset_summaries'):
             return {'processing':['foo']}
         elif url == '/datasets/foo':
             client.called = True
             return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
         elif url == '/datasets/foo/jobs':
             return {}
         elif url.startswith('/datasets/foo/task_counts'):
             return {}
         elif url.startswith('/config'):
             return {'options':{},'tasks': [
                 {'name':'a','requirements':{},'depends':[]},
                 {'name':'b','requirements':{'memory':4.5},'depends':['a']},
             ]}
         elif url == '/jobs' and method == 'POST':
             jobs.append(args)
             return {'result': job_ids.pop(0)}
         elif url == '/tasks' and method == 'POST':
             tasks.append(args)
             return {'result': task_ids.pop(0)}
         else:
             raise Exception()
     client.called = False
     rc.request = client
     await buffer_jobs_tasks.run(rc, debug=True)
     self.assertTrue(client.called)
     self.assertTrue(len(jobs) == 2)
     self.assertTrue(len(tasks) == 4)
     self.assertEqual([0,0,1,1], [t['job_id'] for t in tasks])
     self.assertEqual([[],[0],[],[2]], [t['depends'] for t in tasks])
     
     job_ids = list(range(2))
     task_ids = list(range(4))
     jobs = []
     tasks = []
     async def client(method, url, args=None):
         if url.startswith('/dataset_summaries'):
             return {'processing':['foo']}
         elif url == '/datasets/foo':
             client.called = True
             return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
         elif url == '/datasets/foo/jobs':
             return {}
         elif url.startswith('/datasets/foo/task_counts'):
             return {}
         elif url.startswith('/config'):
             return {'options':{},'tasks': [
                 {'name':'a','requirements':{},'depends':[]},
                 {'name':'b','requirements':{},'depends':[0]},
             ]}
         elif url == '/jobs' and method == 'POST':
             jobs.append(args)
             return {'result': job_ids.pop(0)}
         elif url == '/tasks' and method == 'POST':
             tasks.append(args)
             return {'result': task_ids.pop(0)}
         else:
             raise Exception()
     client.called = False
     rc.request = client
     await buffer_jobs_tasks.run(rc, debug=True)
     self.assertTrue(client.called)
     self.assertTrue(len(jobs) == 2)
     self.assertTrue(len(tasks) == 4)
     self.assertEqual([0,0,1,1], [t['job_id'] for t in tasks])
     self.assertEqual([[],[0],[],[2]], [t['depends'] for t in tasks])
     
     job_ids = list(range(1,2))
     task_ids = list(range(2,4))
     jobs = []
     tasks = []
     async def client(method, url, args=None):
         if url.startswith('/dataset_summaries'):
             return {'processing':['foo']}
         elif url == '/datasets/foo':
             client.called = True
             return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
         elif url == '/datasets/foo/jobs':
             return {0:{'job_index':0}}
         elif url.startswith('/datasets/foo/task_counts'):
             return {}
         elif url.startswith('/config'):
             return {'options':{},'tasks': [
                 {'name':'a','requirements':{},'depends':[]},
                 {'name':'b','requirements':{},'depends':[0]},
             ]}
         elif url == '/jobs' and method == 'POST':
             jobs.append(args)
             return {'result': job_ids.pop(0)}
         elif url == '/tasks' and method == 'POST':
             tasks.append(args)
             return {'result': task_ids.pop(0)}
         else:
#.........这里部分代码省略.........
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:103,代码来源:buffer_jobs_tasks_test.py

示例12: test_202_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_202_run(self):
        rc = MagicMock(spec=RestClient)
        job_ids = list(range(2))
        task_ids = list(range(4))
        jobs = []
        tasks = []
        async def client(method, url, args=None):
            logger.info('RPC: %s %s', method, url)
            if url.startswith('/dataset_summaries'):
                return {'processing':['foo']}
            elif url == '/datasets/foo':
                client.called = True
                return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
            elif url == '/datasets/foo/jobs':
                return {}
            elif url.startswith('/datasets/foo/task_counts'):
                return {}
            elif url.startswith('/config'):
                return {'options':{},'tasks': [
                    {'name':'a','requirements':{},'depends':['b']},
                    {'name':'b','requirements':{},'depends':['a']},
                ]}
            elif url == '/jobs' and method == 'POST':
                jobs.append(args)
                return {'result': job_ids.pop(0)}
            elif url == '/tasks' and method == 'POST':
                tasks.append(args)
                return {'result': task_ids.pop(0)}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        with self.assertRaises(Exception):
            await buffer_jobs_tasks.run(rc, debug=True)

        job_ids = list(range(2))
        task_ids = list(range(4))
        jobs = []
        tasks = []
        async def client(method, url, args=None):
            logger.info('RPC: %s %s', method, url)
            if url.startswith('/dataset_summaries'):
                return {'processing':['foo']}
            elif url == '/datasets/foo':
                client.called = True
                return {'dataset':1,'jobs_submitted':2, 'tasks_submitted':2,'debug':True}
            elif url == '/datasets/foo/jobs':
                return {}
            elif url.startswith('/datasets/foo/task_counts'):
                return {}
            elif url.startswith('/config'):
                return {'options':{},'tasks': [
                    {'name':'a','requirements':{},'depends':[0]},
                    {'name':'b','requirements':{},'depends':['a']},
                ]}
            elif url == '/jobs' and method == 'POST':
                jobs.append(args)
                return {'result': job_ids.pop(0)}
            elif url == '/tasks' and method == 'POST':
                tasks.append(args)
                return {'result': task_ids.pop(0)}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        with self.assertRaises(Exception):
            await buffer_jobs_tasks.run(rc, debug=True)
        
        job_ids = list(range(2))
        task_ids = list(range(4))
        jobs = []
        tasks = []
        async def client(method, url, args=None):
            logger.info('RPC: %s %s', method, url)
            if url.startswith('/dataset_summaries'):
                return {'processing':['foo']}
            elif url == '/datasets/foo':
                client.called = True
                return {'jobs_submitted':2, 'tasks_submitted':2}
            elif url == '/datasets/foo/jobs':
                return {}
            elif url.startswith('/datasets/foo/task_counts'):
                return {}
            elif url.startswith('/config'):
                return {'options':{},'tasks': [
                    {'name':'a','requirements':{},'depends':['lalala']},
                    {'name':'b','requirements':{},'depends':['a']},
                ]}
            elif url == '/jobs' and method == 'POST':
                jobs.append(args)
                return {'result': job_ids.pop(0)}
            elif url == '/tasks' and method == 'POST':
                tasks.append(args)
                return {'result': task_ids.pop(0)}
            else:
                raise Exception()
        client.called = False
        rc.request = client
        with self.assertRaises(Exception):
            await buffer_jobs_tasks.run(rc, debug=True)
#.........这里部分代码省略.........
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:103,代码来源:buffer_jobs_tasks_test.py

示例13: test_200_run

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import request [as 别名]
    async def test_200_run(self):
        rc = MagicMock(spec=RestClient)
        dataset_summaries = {}
        job_summaries = {}
        tasks = {
            't1':{'task_id':'t1','status':'processing'},
            't2':{'task_id':'t2','status':'waiting'},
        }
        async def client(method, url, args=None):
            logger.info('REST: %s, %s', method, url)
            if url.startswith('/dataset_summaries'):
                return dataset_summaries
            if url.startswith('/datasets/foo/job_summaries'):
                return job_summaries
            elif url.startswith('/datasets/foo/tasks'):
                return tasks
            elif url == '/datasets/foo/jobs/1/status' and method == 'PUT':
                client.called = True
                client.status = args['status']
                return {}
            else:
                raise Exception()
        client.called = False
        client.status = None
        rc.request = client

        await job_completion.run(rc, debug=True)
        self.assertFalse(client.called)
        
        dataset_summaries['processing'] = ['foo']
        await job_completion.run(rc, debug=True)
        self.assertFalse(client.called)
        
        job_summaries['processing'] = ['1']
        await job_completion.run(rc, debug=True)
        self.assertFalse(client.called)

        logger.info('test processing')
        await job_completion.run(rc, debug=True)
        self.assertFalse(client.called)

        logger.info('test errors')
        tasks['t1']['status'] = 'failed'
        tasks['t2']['status'] = 'failed'
        await job_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'errors')

        logger.info('test processing and suspended')
        tasks['t1']['status'] = 'processing'
        tasks['t2']['status'] = 'suspended'
        client.called = False
        client.status = None
        await job_completion.run(rc, debug=True)
        self.assertFalse(client.called)

        logger.info('test suspended')
        tasks['t1']['status'] = 'complete'
        tasks['t2']['status'] = 'suspended'
        await job_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'suspended')

        logger.info('test complete')
        tasks['t1']['status'] = 'complete'
        tasks['t2']['status'] = 'complete'
        client.called = False
        client.status = None
        await job_completion.run(rc, debug=True)
        self.assertTrue(client.called)
        self.assertEqual(client.status, 'complete')
开发者ID:WIPACrepo,项目名称:iceprod,代码行数:73,代码来源:job_completion_test.py


注:本文中的unittest.mock.MagicMock.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。