Proper way to test Django signals

Viewed 24142

I'm trying to test sent signal and it's providing_args. Signal triggered inside contact_question_create view just after form submission.

My TestCase is something like:

    def test_form_should_post_proper_data_via_signal(self):
        form_data = {'name': 'Jan Nowak'}
        signals.question_posted.send(sender='test', form_data=form_data)
        @receiver(signals.question_posted, sender='test')
        def question_posted_listener(sender, form_data):
            self.name = form_data['name']
        eq_(self.name, 'Jan Nowak')

Is this the proper way to test this signal? Any better ideas?

6 Answers
Related