Exemplo n.º 1
0
    def test_atomic_context_exception(self):

        with suppress(Exception), db.atomic():
            db.add(Owner(first_name="test", last_name="last"))
            raise Exception()

        self.assertEqual(Owner.query.count(), 0)
Exemplo n.º 2
0
    def test_atomic_decorator_exception(self):
        @db.atomic()
        def do_something():
            db.add(Owner(first_name="test", last_name="last"))
            raise Exception()

        with suppress(Exception):
            do_something()

        self.assertEqual(Owner.query.count(), 0)
Exemplo n.º 3
0
    def get_model(cls):
        """Returns the model class."""
        model = None

        with suppress(AttributeError, InvalidRequestError):
            model = cls.queryset._only_full_mapper_zero("get").class_

        if model:
            return model

        with suppress(AttributeError):
            model = cls.serializer_class.Meta.model

        assert model is not None, (
            "Couldn't figure out the model for {viewset} attribute, either provide a"
            "queryset or a serializer with a Meta.model".format(
                viewset=cls.__name__))

        return model
Exemplo n.º 4
0
    def test_suppress(self):

        with utils.suppress(AssertionError):
            assert 1 == 2