# Path: tests/cases/resources/tests/async/base.py
# class JobTestCaseMixin(object):
#     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
# 
#     def assert_job_status_equal(self, job, expected_status):
#         response = self.client.get('/api/jobs/{0}/'.format(job.id),
#                                    HTTP_ACCEPT='application/json')
#         self.assertEqual(response.status_code, codes.ok)
#         content = json.loads(response.content)
#         self.assertEqual(content['status'], expected_status)
# 
#     def assert_job_result_equal(self, job, expected_result,
#                                 expected_links=None):
#         response = self.client.get('/api/jobs/{0}/result/'.format(job.id),
#                                    HTTP_ACCEPT='application/json')
#         self.assertEqual(response.status_code, codes.ok)
#         self.assertEqual(response['Content-Type'], 'application/json')
#         self.assertEqual(json.loads(response.content), expected_result)
# 
#         if expected_links:
#             self.assert_links_equal(response['Link'], expected_links)
# 
#     def assert_links_equal(self, link_str, expected_link_str):
#         # Cannot use set comprehension here because it is not supported
#         # in Python 2.6. Set comprehensions were backported from 3.1 to 2.7.
#         links = set(link.strip() for link in link_str.split(','))
#         expected_links = set(
#             link.strip() for link in expected_link_str.split(','))
#         self.assertEqual(links, set(expected_links))
# 
# Path: tests/cases/resources/tests/base.py
# class TransactionBaseTestCase(TransactionTestCase):
#     fixtures = ['tests/fixtures/test_data.json']
# 
#     def setUp(self):
#         management.call_command('avocado', 'init', 'tests', quiet=True,
#                                 publish=False, concepts=False)
#         DataField.objects.filter(
#             model_name__in=['project', 'title']).update(published=True)
# 
#         self.user = User.objects.create_user(username='root',
#                                              password='password')
#         self.user.is_superuser = True
#         self.user.save()


import json
import time
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from django.test import TestCase
from restlib2.http import codes
from avocado.async import utils
from .base import JobTestCaseMixin
from ..base import TransactionBaseTestCase
        # items should match what we expect.
        for job_id in [normal_job_id, invalid_job_id, valid_job_id]:
            self.assert_job_status_equal(
                utils.get_job(job_id), 'finished')

        # When no processor is specified, all rows should be in the job result.
        response = self.client.get(
            '/api/jobs/{0}/result/'.format(normal_job_id),
            HTTP_ACCEPT='application/json')
        content = json.loads(response.content)
        self.assertEqual(len(content['items']), 6)

        # When the manager processor is used, only a single row should be in
        # the result set.
        response = self.client.get(
            '/api/jobs/{0}/result/'.format(valid_job_id),
            HTTP_ACCEPT='application/json')
        content = json.loads(response.content)
        self.assertEqual(len(content['items']), 1)

        # When an invalid processor is specified, the default processor should
        # be used. As we see above, the default processor should return all
        # the rows.
        response = self.client.get(
            '/api/jobs/{0}/result/'.format(invalid_job_id),
            HTTP_ACCEPT='application/json')
        content = json.loads(response.content)
        self.assertEqual(len(content['items']), 6)



# Path: tests/cases/resources/tests/async/base.py
# class JobTestCaseMixin(object):
#     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
# 
#     def assert_job_status_equal(self, job, expected_status):
#         response = self.client.get('/api/jobs/{0}/'.format(job.id),
#                                    HTTP_ACCEPT='application/json')
#         self.assertEqual(response.status_code, codes.ok)
#         content = json.loads(response.content)
#         self.assertEqual(content['status'], expected_status)
# 
#     def assert_job_result_equal(self, job, expected_result,
#                                 expected_links=None):
#         response = self.client.get('/api/jobs/{0}/result/'.format(job.id),
#                                    HTTP_ACCEPT='application/json')
#         self.assertEqual(response.status_code, codes.ok)
#         self.assertEqual(response['Content-Type'], 'application/json')
#         self.assertEqual(json.loads(response.content), expected_result)
# 
#         if expected_links:
#             self.assert_links_equal(response['Link'], expected_links)
# 
#     def assert_links_equal(self, link_str, expected_link_str):
#         # Cannot use set comprehension here because it is not supported
#         # in Python 2.6. Set comprehensions were backported from 3.1 to 2.7.
#         links = set(link.strip() for link in link_str.split(','))
#         expected_links = set(
#             link.strip() for link in expected_link_str.split(','))
#         self.assertEqual(links, set(expected_links))
# 
# Path: tests/cases/resources/tests/base.py
# class TransactionBaseTestCase(TransactionTestCase):
#     fixtures = ['tests/fixtures/test_data.json']
# 
#     def setUp(self):
#         management.call_command('avocado', 'init', 'tests', quiet=True,
#                                 publish=False, concepts=False)
#         DataField.objects.filter(
#             model_name__in=['project', 'title']).update(published=True)
# 
#         self.user = User.objects.create_user(username='root',
#                                              password='password')
#         self.user.is_superuser = True
#         self.user.save()


# Path: tests/cases/resources/tests/async/preview.py
import json
import time
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from django.test import TestCase
from restlib2.http import codes
from avocado.async import utils
from .base import JobTestCaseMixin
from ..base import TransactionBaseTestCase

        # items should match what we expect.
        for job_id in [normal_job_id, invalid_job_id, valid_job_id]:
            self.assert_job_status_equal(
                utils.get_job(job_id), 'finished')

        # When no processor is specified, all rows should be in the job result.
        response = self.client.get(
            '/api/jobs/{0}/result/'.format(normal_job_id),
            HTTP_ACCEPT='application/json')
        content = json.loads(response.content)
        self.assertEqual(len(content['items']), 6)

        # When the manager processor is used, only a single row should be in
        # the result set.
        response = self.client.get(
            '/api/jobs/{0}/result/'.format(valid_job_id),
            HTTP_ACCEPT='application/json')
        content = json.loads(response.content)
        self.assertEqual(len(content['items']), 1)

        # When an invalid processor is specified, the default processor should
        # be used. As we see above, the default processor should return all
        # the rows.
        response = self.client.get(
            '/api/jobs/{0}/result/'.format(invalid_job_id),
            HTTP_ACCEPT='application/json')
        content = json.loads(response.content)
        self.assertEqual(len(content['items']), 6)



class AsyncPreviewResourceTestCase(TestCase, JobTestCaseMixin):