Пример #1
0
    def test_on_success_is_called_after_successful_pass(self):
        numbers_list = []

        with transaction_signals():
            on_success(lambda: add_number(numbers_list, 0))

            assert_equal(len(numbers_list), 0)

        assert_equal(len(numbers_list), 1)
Пример #2
0
    def test_on_success_is_not_called_after_not_successful_pass(self):
        numbers_list = []

        try:
            with transaction_signals():
                on_success(lambda: add_number(numbers_list, 0))

                assert_equal(len(numbers_list), 0)
                raise Exception()
        except Exception:
            pass

        assert_equal(len(numbers_list), 0)
Пример #3
0
    def test_on_success_inheritance(self):
        numbers_list = []

        with transaction_signals():
            with transaction_signals():
                on_success(lambda: add_number(numbers_list, 0))

                assert_equal(len(numbers_list), 0)
            assert_equal(len(numbers_list), 0)
            try:
                with transaction_signals():
                    on_success(lambda: add_number(numbers_list, 1))

                    assert_equal(len(numbers_list), 0)
                    raise Exception()
            except Exception:
                pass
            on_success(lambda: add_number(numbers_list, 2))
            assert_equal(len(numbers_list), 0)

        assert_equal(numbers_list, [0, 2])
Пример #4
0
 def _handle(self, instance, **kwargs):
     on_success(InstanceOneTimeOnSuccessHandlerCallable(self, instance),
                using=self.using)
Пример #5
0
 def _handle(self, instance, **kwargs):
     on_success(lambda: self.handle(instance, **kwargs), using=self.using)