Example #1
0
    def test_create_and_cancel(self):
        # Create 3 meaningless jobs. We're just testing job setup and
        # cancellation here, not the execution.
        utils.async_get_result_rows(None, None, {})
        job_options = {
            'name': 'Job X',
        }
        job_x_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_options = {
            'name': 'Job Y',
            'query_name': 'job_y_query',
        }
        job_y_id = utils.async_get_result_rows(None, None, {}, job_options)

        self.assertEqual(async_utils.get_job_count(), 3)

        jobs = async_utils.get_jobs()
        self.assertEqual(len(jobs), 3)

        job_x = async_utils.get_job(job_x_id)
        self.assertTrue(job_x in jobs)
        self.assertEqual(job_x.meta['name'], 'Job X')

        self.assertEqual(async_utils.cancel_job(job_x_id), None)
        self.assertEqual(async_utils.get_job_count(), 2)
        async_utils.cancel_job('invalid_id')
        self.assertEqual(async_utils.get_job_count(), 2)

        self.assertTrue('canceled' in async_utils.cancel_job(job_y_id))
        self.assertTrue(async_utils.get_job_count(), 1)

        async_utils.cancel_all_jobs()
        self.assertEqual(async_utils.get_job_count(), 0)
Example #2
0
    def test_create_and_cancel(self):
        # Create 3 meaningless jobs. We're just testing job setup and
        # cancellation here, not the execution.
        utils.async_get_result_rows(None, None, {})
        job_options = {
            'name': 'Job X',
        }
        job_x_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_options = {
            'name': 'Job Y',
            'query_name': 'job_y_query',
        }
        job_y_id = utils.async_get_result_rows(None, None, {}, job_options)

        self.assertEqual(async_utils.get_job_count(), 3)

        jobs = async_utils.get_jobs()
        self.assertEqual(len(jobs), 3)

        job_x = async_utils.get_job(job_x_id)
        self.assertTrue(job_x in jobs)
        self.assertEqual(job_x.meta['name'], 'Job X')

        self.assertEqual(async_utils.cancel_job(job_x_id), None)
        self.assertEqual(async_utils.get_job_count(), 2)
        async_utils.cancel_job('invalid_id')
        self.assertEqual(async_utils.get_job_count(), 2)

        self.assertTrue('canceled' in async_utils.cancel_job(job_y_id))
        self.assertTrue(async_utils.get_job_count(), 1)

        async_utils.cancel_all_jobs()
        self.assertEqual(async_utils.get_job_count(), 0)
Example #3
0
    def test_create_and_cancel(self):
        # Create 3 meaningless jobs. We're just testing job setup and
        # cancellation here, not the execution.
        job_options = {
            'name': 'Job X',
        }
        job_x_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_options = {
            'name': 'Job Y',
            'query_name': 'job_y_query',
        }
        job_y_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_z_id = utils.async_get_result_rows(None, None, {})

        self.assertEqual(async_utils.get_job_count(), 3)

        jobs = async_utils.get_jobs()
        self.assertEqual(len(jobs), 3)

        job_x = async_utils.get_job(job_x_id)
        self.assertTrue(job_x in jobs)
        self.assertEqual(job_x.meta['name'], 'Job X')

        job_y = async_utils.get_job(job_y_id)
        job_z = async_utils.get_job(job_z_id)

        self.assertEqual(async_utils.cancel_job(job_x_id), None)
        # Prove job is gone from Redis
        with self.assertRaises(NoSuchJobError):
            job_x.refresh()
        # Prove job is gone from queue
        self.assertEqual(async_utils.get_job_count(), 2)
        async_utils.cancel_job('invalid_id')
        self.assertEqual(async_utils.get_job_count(), 2)

        self.assertTrue('canceled' in async_utils.cancel_job(job_y_id))
        self.assertTrue(async_utils.get_job_count(), 1)

        async_utils.cancel_all_jobs()
        with self.assertRaises(NoSuchJobError):
            job_y.refresh()
        with self.assertRaises(NoSuchJobError):
            job_z.refresh()
        self.assertEqual(async_utils.get_job_count(), 0)
Example #4
0
    def request_and_assert_job(self, url, accept='application/json'):
        initial_count = utils.get_job_count()

        # We should be told to look for our answers elsewhere. Specifically,
        # we should get a redirect with the location being the resource for
        # the job created by the request.
        response = self.client.get(url, HTTP_ACCEPT=accept)
        self.assertEqual(
            response.status_code, HttpResponseRedirect.status_code)

        # Verify that the job is scheduled and that the URL we received
        # matches the job.
        self.assertEqual(utils.get_job_count(), initial_count + 1)
        job = utils.get_jobs()[initial_count]
        location = response['Location']
        self.assertEqual(
            location, 'http://testserver/api/jobs/{0}/'.format(job.id))

        return job