def test_empty_condition(self):
        qc = OJAIQueryCondition()
        self.assertTrue(qc.is_empty())

        qc.is_('name', QueryOp.EQUAL, 'Doe').close()
        self.assertTrue(qc.is_empty())

        qc.build()
        self.assertFalse(qc.is_empty())
    def test_condition(self):
        query_condition = OJAIQueryCondition() \
            .and_() \
            .is_('age', QueryOp.GREATER_OR_EQUAL, 18) \
            .is_('city', QueryOp.EQUAL, 'London').close().close()

        query_condition.build()
        self.assertEqual(
            query_condition.as_dictionary(),
            {'$and': [{
                '$ge': {
                    'age': 18
                }
            }, {
                '$eq': {
                    'city': 'London'
                }
            }]})
    def test_and_with_separate_is(self):
        qc = OJAIQueryCondition() \
            .and_() \
            .and_() \
            .is_(field_path='age', op=QueryOp.GREATER_OR_EQUAL, value=18) \
            .is_(field_path='city', op=QueryOp.EQUAL, value='London') \
            .close() \
            .and_() \
            .is_(field_path='age', op=QueryOp.GREATER_OR_EQUAL, value=22) \
            .is_(field_path='city', op=QueryOp.EQUAL, value='NY') \
            .close() \
            .is_('card', QueryOp.EQUAL, 'visa') \
            .close()

        qc.build()

        self.assertEqual(
            qc.as_dictionary(), {
                '$and': [{
                    '$and': [{
                        '$ge': {
                            'age': 18
                        }
                    }, {
                        '$eq': {
                            'city': 'London'
                        }
                    }]
                }, {
                    '$and': [{
                        '$ge': {
                            'age': 22
                        }
                    }, {
                        '$eq': {
                            'city': 'NY'
                        }
                    }]
                }, {
                    '$eq': {
                        'card': 'visa'
                    }
                }]
            })