That’s a really cool, thanks for sharing this!
Bruno Alla

Hey Bruno,

First of all thank you for the comments on the code snippets — they are all taken care of :)

About the tests, I focused on testing that a signal was sent — I did not test the handler it self. If you want to test the handler you can test is like you would a regular function — no need for fancy context managers.

Django signals are pretty simple. If you look at the implementation the @receiver function add the handler to a list of functions for a certain signal. When the signal is sent Django will iterate the list and execute the handlers one after the other.

In the example above, you can send the signal and right after test that the total_charges for the user got incremented.

Like what you read? Give Haki Benita a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.