# Path: advanced_filters/models.py
# class AdvancedFilter(models.Model):
#     class Meta:
#         verbose_name = _('Advanced Filter')
#         verbose_name_plural = _('Advanced Filters')
# 
#     title = models.CharField(max_length=255, null=False, blank=False, verbose_name=_('Title'))
#     created_by = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='created_advanced_filters',
#         verbose_name=_('Created by'),
#         on_delete=models.CASCADE,
#     )
#     created_at = models.DateTimeField(auto_now_add=True, null=True, verbose_name=_('Created at'))
#     url = models.CharField(max_length=255, null=False, blank=False, verbose_name=_('URL'))
#     users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, verbose_name=_('Users'))
#     groups = models.ManyToManyField('auth.Group', blank=True, verbose_name=_('Groups'))
# 
#     objects = UserLookupManager()
# 
#     b64_query = models.CharField(max_length=2048)
#     model = models.CharField(max_length=64, blank=True, null=True)
# 
#     @property
#     def query(self):
#         """
#         De-serialize, decode and return an ORM query stored in b64_query.
#         """
#         if not self.b64_query:
#             return None
#         s = QSerializer(base64=True)
#         return s.loads(self.b64_query)
# 
#     @query.setter
#     def query(self, value):
#         """
#         Serialize an ORM query, Base-64 encode it and set it to
#         the b64_query field
#         """
#         if not isinstance(value, Q):
#             raise Exception('Must only be passed a Django (Q)uery object')
#         s = QSerializer(base64=True)
#         self.b64_query = s.dumps(value)
# 
#     def list_fields(self):
#         s = QSerializer(base64=True)
#         d = s.loads(self.b64_query, raw=True)
#         return s.get_field_values_list(d)


from django.test import TestCase
from django.db.models import Q
from ..models import AdvancedFilter
        from django.contrib.auth import get_user_model
        from django.contrib.auth.models import Group



class AdvancedFilterPermissions(TestCase):
    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create(email='test1@example.com')

        self.group = Group.objects.create(name='test')

        self.user.set_password('test')
        self.user.groups.add(self.group)
        self.user.save()

        self.advancedfilter = AdvancedFilter.objects.create(
            title='test', url='test', created_by=self.user,
            b64_query='MQ=='
        )

    def test_filter_by_user_empty(self):

# Path: advanced_filters/models.py
# class AdvancedFilter(models.Model):
#     class Meta:
#         verbose_name = _('Advanced Filter')
#         verbose_name_plural = _('Advanced Filters')
# 
#     title = models.CharField(max_length=255, null=False, blank=False, verbose_name=_('Title'))
#     created_by = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='created_advanced_filters',
#         verbose_name=_('Created by'),
#         on_delete=models.CASCADE,
#     )
#     created_at = models.DateTimeField(auto_now_add=True, null=True, verbose_name=_('Created at'))
#     url = models.CharField(max_length=255, null=False, blank=False, verbose_name=_('URL'))
#     users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, verbose_name=_('Users'))
#     groups = models.ManyToManyField('auth.Group', blank=True, verbose_name=_('Groups'))
# 
#     objects = UserLookupManager()
# 
#     b64_query = models.CharField(max_length=2048)
#     model = models.CharField(max_length=64, blank=True, null=True)
# 
#     @property
#     def query(self):
#         """
#         De-serialize, decode and return an ORM query stored in b64_query.
#         """
#         if not self.b64_query:
#             return None
#         s = QSerializer(base64=True)
#         return s.loads(self.b64_query)
# 
#     @query.setter
#     def query(self, value):
#         """
#         Serialize an ORM query, Base-64 encode it and set it to
#         the b64_query field
#         """
#         if not isinstance(value, Q):
#             raise Exception('Must only be passed a Django (Q)uery object')
#         s = QSerializer(base64=True)
#         self.b64_query = s.dumps(value)
# 
#     def list_fields(self):
#         s = QSerializer(base64=True)
#         d = s.loads(self.b64_query, raw=True)
#         return s.get_field_values_list(d)


# Path: advanced_filters/tests/test_models.py
from django.test import TestCase
from django.db.models import Q
from ..models import AdvancedFilter
        from django.contrib.auth import get_user_model
        from django.contrib.auth.models import Group




class AdvancedFilterPermissions(TestCase):
    def setUp(self):
        User = get_user_model()
        self.user = User.objects.create(email='test1@example.com')

        self.group = Group.objects.create(name='test')

        self.user.set_password('test')
        self.user.groups.add(self.group)
        self.user.save()

        self.advancedfilter = AdvancedFilter.objects.create(
            title='test', url='test', created_by=self.user,
            b64_query='MQ=='
        )

    def test_filter_by_user_empty(self):

        qs = AdvancedFilter.objects.filter_by_user(user=self.user)