def test_non_ascii(self): events = Event.objects.all() assert events.count() == 2 filtering.filter_queryset( events, u"ø :description=ø", search_fields=["title", "description"], condition_fields=["description"] )
def test_fragment_lt_gt_comparison(self): attendees = Attend.objects.all() assert attendees.count() == 1 e = filtering.filter_queryset(attendees, ":price<50", search_fields=[], condition_fields=["price", "paid"]) assert e.count() == 0 e = filtering.filter_queryset(attendees, ":price>50", search_fields=[], condition_fields=["price", "paid"]) assert e.count() == 1
def test_related(self): attendees = Attend.objects.all() assert attendees.count() == 1 e = filtering.filter_queryset(attendees, "has:comment", search_fields=[], related_sets=["comment"]) assert e.count() == 0 AttendeeComment.objects.create(attendee=attendees[0], author="author", comment="comment") e = filtering.filter_queryset(attendees, "has:comment", search_fields=[], related_sets=["comment"]) assert e.count() == 1
def test_fragment_filtering_exclude_bit(self): events = Event.objects.all() assert events.count() == 2 e = filtering.filter_queryset(events, "-Event", search_fields=["title", "description"]) assert e.count() == 0 e = filtering.filter_queryset(events, '-"Event 1"', search_fields=["title", "description"]) assert e.count() == 1 e = filtering.filter_queryset(events, '"Event 1" -"Event 1"', search_fields=["title", "description"]) assert e.count() == 0
def test_fragment_filtering_condition(self): events = Event.objects.all() assert events.count() == 2 e = filtering.filter_queryset( events, ':description="Another event"', search_fields=["title", "description"], condition_fields=["description"], ) assert e.count() == 1 with self.assertRaises(filtering.FilterException): filtering.filter_queryset(events, ':description="Another event"', search_fields=["title", "description"])
def apply_search_query(qs, query, search_fields, condition_fields=None, related_sets=None, search_order=None): if condition_fields is None: condition_fields = [] invalid_fragments = [] return filtering.filter_queryset(qs, query, search_fields, condition_fields, related_sets, invalid_fragments=invalid_fragments, search_order=search_order), invalid_fragments
def test_fragment_filtering(self): events = Event.objects.all() assert events.count() == 2 e = filtering.filter_queryset(events, '"Event 1"', search_fields=["title"]) assert e.count() == 1 e = filtering.filter_queryset(events, "Event 1", search_fields=["title"]) assert e.count() == 1 e = filtering.filter_queryset(events, "Event", search_fields=["title"]) assert e.count() == 2 e = filtering.filter_queryset(events, '"Event 1"', search_fields=["title", "description"]) assert e.count() == 1 # one term matches event 1 and another matches event 2 e = filtering.filter_queryset(events, '"Event 1" Another', search_fields=["title", "description"]) assert e.count() == 0 e = filtering.filter_queryset(events, "Event", search_fields=["title", "description"]) assert e.count() == 2