Example #1
0
 def function_result(client, **kwargs):
     # pylint: disable=function-redefined,unused-argument
     error = models.BatchError()
     error.code = 'InvalidHeaderValue'
     error.message = models.ErrorMessage('en-US', 'The value for one of the HTTP '
                                         'headers is not in the correct format')
     error.values = [
         models.BatchErrorDetail('HeaderName', 'Content-Type'),
         models.BatchErrorDetail('HeaderValue', 'application/json')
     ]
     exp = models.BatchErrorException(lambda x, y: error, None)
     raise exp
    def test_submit_job_and_add_task(self):
        tasks = [MagicMock]
        ab = AzureBatch(
            batch_client=MagicMock(),
            config_file=CONFIG_FILE,
            logger=logging.getLogger(__name__),
        )

        ab.batch_client.configure_mock(
            **{
                'pool.exists.return_value':
                False,
                'job.get.side_effect':
                batchmodels.BatchErrorException(MagicMock(), "response"),
            })

        ab.submit_job_and_add_task(POOL_ID, JOB_ID, tasks, VM_SIZE, VM_COUNT,
                                   MAX_TASKS)
        self.assertTrue(ab.batch_client.pool.add.called)
        self.assertTrue(ab.batch_client.job.add.called)
        self.assertTrue(ab.batch_client.task.add_collection.called)
    def test_create_job(self):
        mocked_batch_client = MagicMock()
        mocked_batch_client.configure_mock(
            **{
                'credentials.return_value': MagicMock(),
                'batch_url.return_value': BATCH_SERVICE_URL,
            })
        ab = AzureBatch(
            batch_client=mocked_batch_client,
            config_file=CONFIG_FILE,
            logger=logging.getLogger(__name__),
        )

        ab.batch_client.configure_mock(
            **{
                'job.get.side_effect':
                batchmodels.BatchErrorException(MagicMock(), "response"),
            })

        ab.create_job(POOL_ID, JOB_ID)
        self.assertTrue(ab.batch_client.job.add.called)
        self.assertEqual(ab.config_file, CONFIG_FILE)