'Test save signals for proxy models'

def test_proxy_model_signals(self):

    output = []
    def make_handler(model, event):
        def _handler(*args, **kwargs):
            output.append((u'%s    %s    save' % (model, event)))
        return _handler
    h1 = make_handler(u'MyPerson', u'pre')
    h2 = make_handler(u'MyPerson', u'post')
    h3 = make_handler(u'Person', u'pre')
    h4 = make_handler(u'Person', u'post')
    signals.pre_save.connect(h1, sender=MyPerson)
    signals.post_save.connect(h2, sender=MyPerson)
    signals.pre_save.connect(h3, sender=Person)
    signals.post_save.connect(h4, sender=Person)
    dino = MyPerson.objects.create(name=u'dino')
    self.assertEqual(output, [u'MyPerson    pre    save', u'MyPerson    post    save'])
    output = []
    h5 = make_handler(u'MyPersonProxy', u'pre')
    h6 = make_handler(u'MyPersonProxy', u'post')
    signals.pre_save.connect(h5, sender=MyPersonProxy)
    signals.post_save.connect(h6, sender=MyPersonProxy)
    dino = MyPersonProxy.objects.create(name=u'pebbles')
    self.assertEqual(output, [u'MyPersonProxy    pre    save', u'MyPersonProxy    post    save'])
    signals.pre_save.disconnect(h1, sender=MyPerson)
    signals.post_save.disconnect(h2, sender=MyPerson)
    signals.pre_save.disconnect(h3, sender=Person)
    signals.post_save.disconnect(h4, sender=Person)
    signals.pre_save.disconnect(h5, sender=MyPersonProxy)
    signals.post_save.disconnect(h6, sender=MyPersonProxy)
