Example #1
0
    def test_equality_apply(self):
        eq_cond = EqualityCondition(op='eq')
        neq_cond = EqualityCondition(op='eq', negation=True)

        ExperimentStatusFactory(status=ExperimentLifeCycle.SCHEDULED)

        # eq
        queryset = eq_cond.apply(queryset=Experiment.objects,
                                 name='status__status',
                                 params=ExperimentLifeCycle.SCHEDULED)
        assert queryset.count() == 1

        queryset = eq_cond.apply(queryset=Experiment.objects,
                                 name='status__status',
                                 params=ExperimentLifeCycle.SUCCEEDED)
        assert queryset.count() == 0

        # neq
        queryset = neq_cond.apply(queryset=Experiment.objects,
                                  name='status__status',
                                  params=ExperimentLifeCycle.SCHEDULED)
        assert queryset.count() == 0

        queryset = neq_cond.apply(queryset=Experiment.objects,
                                  name='status__status',
                                  params=ExperimentLifeCycle.SUCCEEDED)
        assert queryset.count() == 1
Example #2
0
 def test_equality_condition_init_with_correct_operator(self):
     eq_cond = EqualityCondition(op='eq')
     assert eq_cond.operator == EqualityCondition._eq_operator
     neq_cond = EqualityCondition(op='eq', negation=True)
     assert neq_cond.operator == EqualityCondition._neq_operator
Example #3
0
 def test_equality_operators(self):
     op = EqualityCondition._eq_operator('field', 'value')
     assert op == Q(field='value')
     op = EqualityCondition._neq_operator('field', 'value')
     assert op == ~Q(field='value')