forked from modlinltd/django-advanced-filters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request modlinltd#99 from maingoh/fixed_nullable_fields
Fixed sort on None fields
- Loading branch information
Showing
5 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import json | ||
import sys | ||
from datetime import timedelta | ||
from operator import attrgetter | ||
|
||
import django | ||
import factory | ||
import pytest | ||
from django.utils import timezone | ||
from django.utils.encoding import force_str | ||
from tests.factories import ClientFactory | ||
|
||
|
@@ -47,7 +51,7 @@ def assert_view_error(client, error, exception=None, **view_kwargs): | |
else: | ||
ARGUMENT_LENGTH_ERROR = "need more than 1 value to unpack" | ||
|
||
if sys.version_info < (3, ) and django.VERSION < (1, 11): | ||
if sys.version_info < (3,) and django.VERSION < (1, 11): | ||
MISSING_FIELD_ERROR = "SalesRep has no field named u'baz'" | ||
else: | ||
MISSING_FIELD_ERROR = "SalesRep has no field named 'baz'" | ||
|
@@ -135,3 +139,32 @@ def test_distinct_database_choices(user, client, settings): | |
assert_json( | ||
response.content, {"results": [{"id": "[email protected]", "text": "[email protected]"}]} | ||
) | ||
|
||
|
||
def test_choices_no_date_fields_support(user, client, settings): | ||
settings.ADVANCED_FILTERS_MAX_CHOICES = 4 | ||
logins = [timezone.now(), timezone.now() - timedelta(days=1), None] | ||
ClientFactory.create_batch( | ||
3, assigned_to=user, email="[email protected]", last_login=factory.Iterator(logins) | ||
) | ||
view_url = reverse( | ||
URL_NAME, kwargs=dict(model="customers.Client", field_name="last_login") | ||
) | ||
response = client.get(view_url) | ||
assert_json(response.content, {"results": []}) | ||
|
||
|
||
def test_choices_has_null(user, client, settings): | ||
settings.ADVANCED_FILTERS_MAX_CHOICES = 4 | ||
named_users = ClientFactory.create_batch(2, assigned_to=user) | ||
names = [None] + sorted(set([nu.first_name for nu in named_users])) | ||
assert len(named_users) == 2 | ||
ClientFactory.create_batch(2, assigned_to=user, first_name=None) | ||
view_url = reverse( | ||
URL_NAME, kwargs=dict(model="customers.Client", field_name="first_name") | ||
) | ||
response = client.get(view_url) | ||
assert_json( | ||
response.content, | ||
{"results": [{"id": name, "text": str(name)} for name in names]}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ class ClientFactory(factory.django.DjangoModelFactory): | |
class Meta: | ||
model = 'customers.Client' | ||
|
||
first_name = factory.faker.Faker('first_name') | ||
email = factory.Sequence(lambda n: 'c%[email protected]' % n) |