コード例 #1
0
ファイル: tests.py プロジェクト: vicalloy/lbutils
 def test_do_filter_quick_query_fields(self):
     books = Book.objects.all()
     qdata = {'q_quick_search_kw': ''}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(3, qs.count())
     qdata = {'q_quick_search_kw': 'ook-01'}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(1, qs.count())
     qdata = {'q_quick_search_kw': 'xxxxx'}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(0, qs.count())
     qdata = {'q_quick_search_kw': 'catego'}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(2, qs.count())
コード例 #2
0
 def test_do_filter_quick_query_fields(self):
     books = Book.objects.all()
     qdata = {'q_quick_search_kw': ''}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(3, qs.count())
     qdata = {'q_quick_search_kw': 'ook-01'}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(1, qs.count())
     qdata = {'q_quick_search_kw': 'xxxxx'}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(0, qs.count())
     qdata = {'q_quick_search_kw': 'catego'}
     qs = do_filter(books, qdata, ['name', 'category__name'])
     self.assertEqual(2, qs.count())
コード例 #3
0
 def test_do_filter_int_quick_query_fields(self):
     books = Book.objects.all()
     qdata = {'q_quick_search_kw': '100'}
     qs = do_filter(books,
                    qdata, ['name', 'category__name'],
                    int_quick_query_fields=['price'])
     self.assertEqual(1, qs.count())
コード例 #4
0
 def do_filter(self, queryset, query_data):
     quick_query_fields = self.get_quick_query_fields()
     return do_filter(
         queryset,
         query_data,
         quick_query_fields,
         self.int_quick_query_fields,
     )
コード例 #5
0
ファイル: tests.py プロジェクト: vicalloy/lbutils
 def test_do_filter(self):
     books = Book.objects.all()
     qdata = {'q__price': '100'}
     qs = do_filter(books, qdata)
     self.assertEqual(1, qs.count())
     qdata = {'q__name__icontains': 'book-03'}
     qs = do_filter(books, qdata)
     self.assertEqual(1, qs.count())
     qdata = {'q__name__icontains': 'ook-02,ook-03'}
     qs = do_filter(books, qdata)
     self.assertEqual(2, qs.count())
     qdata = {'q__name__in': 'book-02,book-03'}
     qs = do_filter(books, qdata)
     self.assertEqual(2, qs.count())
     qdata = {'q__category__name__icontains': 'catego'}
     qs = do_filter(books, qdata)
     self.assertEqual(2, qs.count())
     qdata = {'q__is_active': '__False'}
     qs = do_filter(books, qdata)
     self.assertEqual(1, qs.count())
     # sql: select * from table where field1>field2
     qdata = {'q__name__gt': 'F__name'}
     qs = do_filter(books, qdata)
     self.assertEqual(0, qs.count())
コード例 #6
0
 def test_do_filter(self):
     books = Book.objects.all()
     qdata = {'q__price': '100'}
     qs = do_filter(books, qdata)
     self.assertEqual(1, qs.count())
     qdata = {'q__name__icontains': 'book-03'}
     qs = do_filter(books, qdata)
     self.assertEqual(1, qs.count())
     qdata = {'q__name__icontains': 'ook-02,ook-03'}
     qs = do_filter(books, qdata)
     self.assertEqual(2, qs.count())
     qdata = {'q__name__in': 'book-02,book-03'}
     qs = do_filter(books, qdata)
     self.assertEqual(2, qs.count())
     qdata = {'q__category__name__icontains': 'catego'}
     qs = do_filter(books, qdata)
     self.assertEqual(2, qs.count())
     qdata = {'q__is_active': '__False'}
     qs = do_filter(books, qdata)
     self.assertEqual(1, qs.count())
     # sql: select * from table where field1>field2
     qdata = {'q__name__gt': 'F__name'}
     qs = do_filter(books, qdata)
     self.assertEqual(0, qs.count())
コード例 #7
0
ファイル: tests.py プロジェクト: vicalloy/lbutils
 def test_do_filter_int_quick_query_fields(self):
     books = Book.objects.all()
     qdata = {'q_quick_search_kw': '100'}
     qs = do_filter(books, qdata, ['name', 'category__name'], int_quick_query_fields=['price'])
     self.assertEqual(1, qs.count())