# Path: tests/cases/resources/tests/base.py
# class BaseTestCase(TestCase):
#     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/models.py
# class Title(models.Model):
#     name = models.CharField(max_length=50)
#     salary = models.IntegerField(null=True)
#     boss = models.NullBooleanField(default=False)


import json
from django.test.utils import override_settings
from avocado.models import DataField
from avocado.events.models import Log
from restlib2.http import codes
from .base import BaseTestCase
from tests.models import Title
        # Using a valid query processor should affect the stats.
        response = self.client.get(
            '/api/fields/{0}/stats/?processor=under_twenty_thousand'
            .format(f3.pk),
            HTTP_ACCEPT='application/json')
        stats = json.loads(response.content)
        self.assertEqual(stats['min'], 10000)
        self.assertEqual(stats['max'], 15000)
        self.assertEqual(stats['avg'], 13750)

        # project.due_date
        f11 = DataField.objects.get_by_natural_key('tests',
                                                   'project',
                                                   'due_date')
        response = self.client.get('/api/fields/{0}/stats/'.format(f11.pk),
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)

        stats = json.loads(response.content)

        self.assertTrue(stats)
        self.assertTrue(
            Log.objects.filter(event='stats', object_id=f11.pk).exists())
        self.assertEqual(stats['min'], '2000-01-01')
        self.assertEqual(stats['max'], '2010-01-01')

    def test_empty_stats(self):
        f2 = DataField.objects.get_by_natural_key('tests',
                                                  'title',
                                                  'name')

# Path: tests/cases/resources/tests/base.py
# class BaseTestCase(TestCase):
#     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/models.py
# class Title(models.Model):
#     name = models.CharField(max_length=50)
#     salary = models.IntegerField(null=True)
#     boss = models.NullBooleanField(default=False)


# Path: tests/cases/resources/tests/field.py
import json
from django.test.utils import override_settings
from avocado.models import DataField
from avocado.events.models import Log
from restlib2.http import codes
from .base import BaseTestCase
from tests.models import Title

        # Using a valid query processor should affect the stats.
        response = self.client.get(
            '/api/fields/{0}/stats/?processor=under_twenty_thousand'
            .format(f3.pk),
            HTTP_ACCEPT='application/json')
        stats = json.loads(response.content)
        self.assertEqual(stats['min'], 10000)
        self.assertEqual(stats['max'], 15000)
        self.assertEqual(stats['avg'], 13750)

        # project.due_date
        f11 = DataField.objects.get_by_natural_key('tests',
                                                   'project',
                                                   'due_date')
        response = self.client.get('/api/fields/{0}/stats/'.format(f11.pk),
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)

        stats = json.loads(response.content)

        self.assertTrue(stats)
        self.assertTrue(
            Log.objects.filter(event='stats', object_id=f11.pk).exists())
        self.assertEqual(stats['min'], '2000-01-01')
        self.assertEqual(stats['max'], '2010-01-01')

    def test_empty_stats(self):
        f2 = DataField.objects.get_by_natural_key('tests',
                                                  'title',
                                                  'name')

        Title.objects.all().delete()