mercredi 3 février 2016

How should I write unit testing for signal in Python

I have following 3 files:

  • handlers/article.py

  • signals.py

  • triggers.py

My signals.py as follow:

from blinker import signal
notify_publish = signal('notify_publish')

I have a method in my article.py which is as follow:

import signals
def func1(id):
    notify_signal = None
    if article.status == statuses.draft.value:
        notify_signal = signals.notify_publish
    if notify_signal:
        notify_signal.send(id)

Here is the triggers.py:

@signals.notify_publish.connect
def notify_publish(id):
    ...
    ...
    ...

So what's happening here. I am checking some status in article.py and if its ok, then I am setting the variable notify_signal and sending the value. I have all my signals at a particular file signals.py. Now after that in triggers.py that method is getting called when its getting that signal.

Now I want to write Unit testing for the above. How should I start. I tried their document for testing but its not that helpful.

Aucun commentaire:

Enregistrer un commentaire