def test_modelfiterand_unhandled_exception(self):
        '''This test case ensures unhandled exceptions raised from ModelFilter are gracefully handled by ModelFilterAnd build.'''

        model_filter = ModelFilter(self._model.id, 1, ModelFilter.EQ)
        model_filter.get_expression = Mock(side_effect=Exception("Unhandled exception"))

        model_filter_and = ModelFilterAnd(model_filter, model_filter, model_filter)

        with self.assertRaises(FantasticoError):
            model_filter_and.build(Mock())
Ejemplo n.º 2
0
    def test_modelfiterand_unhandled_exception(self):
        '''This test case ensures unhandled exceptions raised from ModelFilter are gracefully handled by ModelFilterAnd build.'''

        model_filter = ModelFilter(self._model.id, 1, ModelFilter.EQ)
        model_filter.get_expression = Mock(
            side_effect=Exception("Unhandled exception"))

        model_filter_and = ModelFilterAnd(model_filter, model_filter,
                                          model_filter)

        with self.assertRaises(FantasticoError):
            model_filter_and.build(Mock())
    def test_modelfilterand_ok(self):
        '''This test case ensures compound **and** filter correctly transform the filter into sql alchemy and_ statement.'''

        self._or_invoked = False

        model_filter = ModelFilterAnd(ModelFilter(self._model.id, 1, ModelFilter.EQ),
                                      ModelFilter(self._model.id, 1, ModelFilter.EQ),
                                      ModelFilter(self._model.id, 1, ModelFilter.EQ))

        query = Mock()

        def filter_fn(expr):
            self._or_invoked = True

            return Mock()

        self._model.id.table = Mock()
        query._primary_entity = query
        query.selectable = self._model.id.table
        query.filter = filter_fn

        query_new = model_filter.build(query)

        self.assertTrue(self._or_invoked)
        self.assertIsInstance(query_new, Mock)
Ejemplo n.º 4
0
    def test_modelfilterand_ok(self):
        '''This test case ensures compound **and** filter correctly transform the filter into sql alchemy and_ statement.'''

        self._or_invoked = False

        model_filter = ModelFilterAnd(
            ModelFilter(self._model.id, 1, ModelFilter.EQ),
            ModelFilter(self._model.id, 1, ModelFilter.EQ),
            ModelFilter(self._model.id, 1, ModelFilter.EQ))

        query = Mock()

        def filter_fn(expr):
            self._or_invoked = True

            return Mock()

        self._model.id.table = Mock()
        query._primary_entity = query
        query.selectable = self._model.id.table
        query.filter = filter_fn

        query_new = model_filter.build(query)

        self.assertTrue(self._or_invoked)
        self.assertIsInstance(query_new, Mock)