Esempio n. 1
0
    def test_assign_same_function_to_signal(self):
        state = []

        @signals.post_save(sender=B)
        def post_save_one(sender, instance, created):
            state.append(instance)

        signals.post_save(sender=B)(post_save_one)

        b = SubB.create()
        assert b in state
Esempio n. 2
0
    def test_assign_same_function_another_sender(self):
        state = []

        @signals.post_save(sender=B)
        def post_save_one(sender, instance, created):
            state.append(instance)

        with self.assertRaises(ValueError):
            signals.post_save(sender=A)(post_save_one)

        b = SubB.create()
        assert b in state
Esempio n. 3
0
    def test_function_reuse(self):
        state = []

        @signals.post_save(sender=A)
        def post_save(sender, instance, created):
            state.append(instance)

        # Connect function for sender=B as well.
        signals.post_save(sender=B)(post_save)

        a = A.create()
        b = B.create()
        self.assertEqual(state, [a, b])