Пример #1
0
    def test_equal_str_case_sensitive(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        f = Filter("name", c.name, True)
        queryset = f.apply(queryset)

        self.assertEqual([c], list(queryset))
Пример #2
0
    def test_different_int(self):
        queryset = Country.objects.all()
        expected = queryset.exclude(population=600000)
        f = Filter("population", f"!600000", False)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #3
0
    def test_lte_float(self):
        queryset = Country.objects.all()
        expected = queryset.filter(population__lte=600000.0)
        f = Filter("population", f"]600000.0", False)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #4
0
    def test_equal_int(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        f = Filter("population", str(c.population), False)
        queryset = f.apply(queryset)

        self.assertEqual([c], list(queryset))
Пример #5
0
    def test_gt_int(self):
        queryset = Country.objects.all()
        expected = queryset.filter(population__gt=600000)
        f = Filter("population", f">600000", False)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #6
0
    def test_different_datetime(self):
        queryset = Disaster.objects.all()
        d = queryset[random.randint(0, queryset.count() - 1)]
        expected = queryset.exclude(date=d.date)
        f = Filter("date", f"!{d.date.isoformat()}", False)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #7
0
    def test_different_str_case_sensitive(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        expected = queryset.exclude(name__exact=c.name)
        f = Filter("name", f"!{c.name}", True)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #8
0
    def test_equal_datetime(self):
        queryset = Disaster.objects.all()
        d = queryset[random.randint(0, queryset.count() - 1)]
        f = Filter("date", d.date.isoformat(), False)
        queryset = f.apply(queryset)

        self.assertEqual(list(Disaster.objects.filter(date=d.date)),
                         list(queryset))
Пример #9
0
    def test_doesnt_contains_str_case_sensitive(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        expected = queryset.exclude(name__contains=c.name[-1])
        f = Filter("name", f"~{c.name[-1]}", True)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #10
0
    def test_contains_str_case_insensitive(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        expected = queryset.filter(name__icontains=c.name[-1])
        f = Filter("name", f"*{c.name[-1].lower()}", False)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #11
0
    def test_endswith_str_case_sensitive(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        expected = queryset.filter(name__endswith=c.name[-1])
        f = Filter("name", f"${c.name[-1]}", True)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #12
0
    def test_lte_str(self):
        queryset = Country.objects.all()
        c = queryset[random.randint(0, queryset.count() - 1)]
        expected = queryset.filter(name__lte=c.name)
        f = Filter("name", f"]{c.name}", False)
        queryset = f.apply(queryset)

        self.assertEqual(list(expected), list(queryset))
Пример #13
0
    def test_different_float(self):
        queryset = Country.objects.all()
        f = Filter("population", f"!{str(float())}", True)

        with self.assertRaises(SearchModifierError):
            f.apply(queryset)
Пример #14
0
 def test_equal_none(self):
     queryset = River.objects.all()
     expected = queryset.filter(discharge=None)
     f = Filter("discharge", "", False)
     queryset = f.apply(queryset)
     self.assertEqual(list(expected), list(queryset))
Пример #15
0
    def test_lte_none(self):
        queryset = River.objects.all()
        f = Filter("discharge", "]", True)

        with self.assertRaises(SearchModifierError):
            f.apply(queryset)
Пример #16
0
 def test_different_none(self):
     queryset = River.objects.all()
     expected = queryset.exclude(discharge=None)
     f = Filter("discharge", "!", False)
     queryset = f.apply(queryset)
     self.assertEqual(list(expected), list(queryset))