def test_more_than_max_database_choices(user, client, settings): settings.ADVANCED_FILTERS_MAX_CHOICES = 4 ClientFactory.create_batch(5, assigned_to=user) view_url = reverse(URL_NAME, kwargs=dict(model="customers.Client", field_name="id")) response = client.get(view_url) assert_json(response.content, {"results": []})
def test_distinct_database_choices(user, client, settings): settings.ADVANCED_FILTERS_MAX_CHOICES = 4 ClientFactory.create_batch(5, assigned_to=user, email="*****@*****.**") view_url = reverse( URL_NAME, kwargs=dict(model="customers.Client", field_name="email") ) response = client.get(view_url) assert_json( response.content, {"results": [{"id": "*****@*****.**", "text": "*****@*****.**"}]} )
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="*****@*****.**", 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({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]}, )
def three_clients(user): return ClientFactory.create_batch(3, assigned_to=user)
def clients(user): ClientFactory.create_batch(8, assigned_to=user, language="en") ClientFactory.create_batch(2, assigned_to=user, language="ru")