# Path: django_toolkit/tests/testapp/models.py
# class ModelWithChainedQuerySet(models.Model):
#     foo = models.BooleanField(default=False)
#     bar = models.BooleanField(default=False)
# 
#     objects = QuerySetManager()
# 
#     def __unicode__(self):
#         return u'%s' % self.pk
# 
#     class QuerySet(QuerySet):
# 
#         def is_foo(self):
#             return self.filter(foo=True)
# 
#         def is_bar(self):
#             return self.filter(bar=True)
# 
#         def is_not_foo(self):
#             return self.filter(foo=False)
# 
#         def is_not_bar(self):
#             return self.filter(bar=False)


from django.utils import unittest
from django_toolkit.tests.testapp.models import ModelWithChainedQuerySet


class QuerySetManagerTestCase(unittest.TestCase):

    def test_chaining(self):
        ModelWithChainedQuerySet.objects.bulk_create([
            ModelWithChainedQuerySet(foo=False, bar=False),
            ModelWithChainedQuerySet(foo=True, bar=False),
            ModelWithChainedQuerySet(foo=False, bar=True),
            ModelWithChainedQuerySet(foo=True, bar=True),
            ModelWithChainedQuerySet(foo=True, bar=True),
        ])
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().count(), 3)
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().is_not_foo().count(), 0)
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().is_not_bar().count(), 1)
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().is_bar().count(), 2)

# Path: django_toolkit/tests/testapp/models.py
# class ModelWithChainedQuerySet(models.Model):
#     foo = models.BooleanField(default=False)
#     bar = models.BooleanField(default=False)
# 
#     objects = QuerySetManager()
# 
#     def __unicode__(self):
#         return u'%s' % self.pk
# 
#     class QuerySet(QuerySet):
# 
#         def is_foo(self):
#             return self.filter(foo=True)
# 
#         def is_bar(self):
#             return self.filter(bar=True)
# 
#         def is_not_foo(self):
#             return self.filter(foo=False)
# 
#         def is_not_bar(self):
#             return self.filter(bar=False)


# Path: django_toolkit/tests/db/models.py
from django.utils import unittest
from django_toolkit.tests.testapp.models import ModelWithChainedQuerySet



class QuerySetManagerTestCase(unittest.TestCase):

    def test_chaining(self):
        ModelWithChainedQuerySet.objects.bulk_create([
            ModelWithChainedQuerySet(foo=False, bar=False),
            ModelWithChainedQuerySet(foo=True, bar=False),
            ModelWithChainedQuerySet(foo=False, bar=True),
            ModelWithChainedQuerySet(foo=True, bar=True),
            ModelWithChainedQuerySet(foo=True, bar=True),
        ])
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().count(), 3)
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().is_not_foo().count(), 0)
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().is_not_bar().count(), 1)
        self.assertEqual(ModelWithChainedQuerySet.objects.is_foo().is_bar().count(), 2)

        self.assertEqual(ModelWithChainedQuerySet.objects.is_bar().count(), 3)