예제 #1
0
    def test_pre_and_post_save(self):
        data = []

        def pre_save_handler(signal, sender, instance, **kwargs):
            data.append((instance, True))

        def post_save_handler(signal, sender, instance, created, **kwargs):
            data.append((instance, created))

        cb_pre_save.connect(pre_save_handler, Mock)
        cb_post_save.connect(post_save_handler, Mock)

        m = Mock()
        m.append_channel("foo")
        m.save()

        self.assertEqual(data, [(m, True), (m, True)])
        self.assertEqual(len(data), 2)
예제 #2
0
    def test_pre_and_post_save(self):
        data = []

        def pre_save_handler(signal, sender, instance, **kwargs):
            data.append((instance, True))

        def post_save_handler(signal, sender, instance, created, **kwargs):
            data.append((instance, created))

        cb_pre_save.connect(pre_save_handler, Mock)
        cb_post_save.connect(post_save_handler, Mock)

        m = Mock()
        m.append_channel('foo')
        m.save()

        self.assertEqual(data, [(m, True), (m, True)])
        self.assertEqual(len(data), 2)
예제 #3
0
    def test_cb_post_save(self):
        data = []

        def post_save_handler(signal, sender, instance, created, **kwargs):
            data.append((instance, created))

        cb_post_save.connect(post_save_handler, Mock)

        m = Mock()
        m.append_channel("foo")
        m.save()

        m2 = Mock()
        m2.append_channel("boo")
        m2.save()

        m2_updated = Mock(m2.uid)
        m2_updated.title2 = "updated"
        m2_updated.save()

        self.assertEqual(data, [(m, True), (m2, True), (m2_updated, False)])
        self.assertEqual(len(data), 3)
예제 #4
0
    def test_cb_post_save(self):
        data = []

        def post_save_handler(signal, sender, instance, created, **kwargs):
            data.append((instance, created))

        cb_post_save.connect(post_save_handler, Mock)

        m = Mock()
        m.append_channel('foo')
        m.save()

        m2 = Mock()
        m2.append_channel('boo')
        m2.save()

        m2_updated = Mock(m2.uid)
        m2_updated.title2 = 'updated'
        m2_updated.save()

        self.assertEqual(data, [(m, True), (m2, True), (m2_updated, False)])
        self.assertEqual(len(data), 3)