def test_nested_endswith(self): q_obj = Q(secret__gem__endswith='uby') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__endswith='rb') self.assertFalse(q_obj.comparator(obj))
def test_nested_endswith(self): q_obj = Q(secret__gem__endswith='uby') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__endswith='rb') self.assertFalse(q_obj.comparator(obj))
def test_exact(self): q_obj = Q(secret__gem__exact='ruby') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__exact='Ruby') self.assertFalse(q_obj.comparator(obj))
def test_exact(self): q_obj = Q(secret__gem__exact='ruby') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__exact='Ruby') self.assertFalse(q_obj.comparator(obj))
def test_nested_contains(self): q_obj = Q(secret__gem__contains='ub') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__contains='rby') self.assertFalse(q_obj.comparator(obj))
def test_iexact(self): q_obj = Q(secret__gem__iexact='Ruby') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj)) obj = SomeModel.objects.create(secret='BUẞE') q_obj = Q(secret__gem__iexact='busse') self.assertTrue(q_obj.comparator(obj))
def test_nested_in(self): obj = SecretModel(secret=NumericSecret()) q_obj = Q(secret__gem__in=[1, 2, 3, 4, 5, 6, 7]) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__in=[1, 2, 3]) self.assertFalse(q_obj.comparator(obj))
def test_nested_gt(self): obj = SecretModel(secret=NumericSecret()) q_obj = Q(secret__gem__gt=6) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__gt=8) self.assertFalse(q_obj.comparator(obj))
def test_iexact(self): q_obj = Q(secret__gem__iexact='Ruby') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj)) obj = SecretModel(secret=StringSecret('BUẞE')) q_obj = Q(secret__gem__iexact='busse') self.assertTrue(q_obj.comparator(obj))
def test_nested_lt(self): obj = SomeModel.objects.create(secret=7) q_obj = Q(secret__gem__lt=8) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__lt=6) self.assertFalse(q_obj.comparator(obj))
def test_isnone(self): obj = SecretModel(question=None) q_obj = Q(question__isnone=True) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__isnone=True) self.assertTrue(q_obj.comparator(obj))
def test_isnull(self): obj = SomeModel.objects.create(question=None) q_obj = Q(question__isnull=True) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__isnull=True) self.assertFalse(q_obj.comparator(obj))
def test_nested_in(self): obj = SomeModel.objects.create(secret=7) q_obj = Q(secret__gem__in=[1, 2, 3, 4, 5, 6, 7]) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__in=[1, 2, 3]) self.assertFalse(q_obj.comparator(obj))
def test_nested_icontains(self): q_obj = Q(secret__gem__icontains='UB') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__icontains='c') obj = SecretModel(secret=IterableSecret()) self.assertTrue(q_obj.comparator(obj))
def test_Q_composition_OR(self): Qa = Q(secret__gem__istartswith='RUB') Qb = Q(secret__gem__iendswith='Y') obj_ok = SecretModel(secret={'gem': 'ruby'}) self.assertTrue((Qa | Qb).comparator(obj_ok)) obj_ok2 = SecretModel(secret={'gem': 'shiny'}) self.assertTrue((Qa | Qb).comparator(obj_ok2))
def test_nested_contains(self): q_obj = Q(secret__gem__contains='ub') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj)) q_obj = Q(secret__gem__contains='rby') self.assertFalse(q_obj.comparator(obj)) q_obj = Q(secret__gem__contains='C') obj = SecretModel(secret=IterableSecret()) self.assertTrue(q_obj.comparator(obj))
def filter(self, **kwargs): q = Q(**kwargs) return QuerySet( filter(q.comparator, self._object_store), model=self.model )
def test_simple(self): q_obj = Q(question='What?') obj = SecretModel(question='What?') self.assertTrue(q_obj.comparator(obj)) obj = SecretModel(question='When?') self.assertFalse(q_obj.comparator(obj))
def test_simple(self): q_obj = Q(question='What?') obj = SomeModel.objects.create(question='What?') self.assertTrue(q_obj.comparator(obj)) obj = SomeModel.objects.create(question='When?') self.assertFalse(q_obj.comparator(obj))
def test_nested_icontains(self): q_obj = Q(secret__gem__icontains='UB') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj))
def test_nested_attrs(self): q_obj = Q(secret__gem='ruby') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj))
def test_nested_iin(self): obj = SecretModel(secret=StringSecret()) q_obj = Q(secret__gem__iin=['RuBy', 'PeaRls', 'DiamOnds']) self.assertTrue(q_obj.comparator(obj))
def test_nested_iin(self): obj = SomeModel.objects.create() q_obj = Q(secret__gem__iin=['RuBy', 'PeaRls', 'DiamOnds']) self.assertTrue(q_obj.comparator(obj))
def test_nested_istartswith(self): q_obj = Q(secret__gem__istartswith='RUB') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj))
def test_nested_istartswith(self): q_obj = Q(secret__gem__istartswith='RUB') obj = SecretModel(secret=StringSecret()) self.assertTrue(q_obj.comparator(obj))
def test_nested_dict_istartswith(self): q_obj = Q(secret__gem__istartswith='RUB') obj = SecretModel(secret={'gem': 'ruby'}) self.assertTrue(q_obj.comparator(obj))
def filter(self, **kwargs): q = Q(**kwargs) return type(self)(filter(q.comparator, self), model=self.model)
def test_nested_attrs(self): q_obj = Q(secret__gem='ruby') obj = SomeModel.objects.create() self.assertTrue(q_obj.comparator(obj))