Re: Testing if a receiver is connected to a signal
Boa. Funciona para resolver esse problema. Atenciosamente, Vinicius Mendes Engenheiro de Computação Globo.com On Thu, May 5, 2011 at 1:33 PM, Bernardo Fontes wrote: > Hello everybody, > > I resolved this problem by looking at Djangos Signal's code and > understanding its structure. The signal has an attribute called receivers > which has stored references to its receivers function that were connect to > it. When the send function is called, the signal just call this function > which are in this receivers list. So, I created a setUpClass and a > tearDownClass that does a monkey patch with my signal. It's like this: > > > class YourTestClass(TestCase): > > > @classmethod > def setUpClass(cls): > cls.signal_receivers = my_signal.receivers > my_signal.receivers = [] > > > @classmethod > def tearDownClass(cls): > my_signal.receivers = cls.signal_receivers > > Hope I could help! > > > -- > Bernardo Fontes > http://www.bernardofontes.net > bernardo...@gmail.com > Skype: bernardoxhc > (21) 9629 1621 > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Testing if a receiver is connected to a signal
Hello everybody, I resolved this problem by looking at Djangos Signal's code and understanding its structure. The signal has an attribute called receivers which has stored references to its receivers function that were connect to it. When the send function is called, the signal just call this function which are in this receivers list. So, I created a setUpClass and a tearDownClass that does a monkey patch with my signal. It's like this: class YourTestClass(TestCase): @classmethod def setUpClass(cls): cls.signal_receivers = my_signal.receivers my_signal.receivers = [] @classmethod def tearDownClass(cls): my_signal.receivers = cls.signal_receivers Hope I could help! -- Bernardo Fontes http://www.bernardofontes.net bernardo...@gmail.com Skype: bernardoxhc (21) 9629 1621 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Testing if a receiver is connected to a signal
Hi, I'm having this problem too. Does anyone knows a good strategy to handle this problem? On 21 fev, 17:50, Vinicius Mendes wrote: > Hi, > > I want to test if a receiver function is connected to a signal in django, > but I don't want other receivers from other apps to be called when my test > runs. > > I thought of verifying if my callback function is in the receivers list of > the signal, but this list stores the receivers in a strange way. > > Any ideas? > > Atenciosamente, > Vinicius Mendes > Engenheiro de Computação > Globo.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.