tests.py
from unittest.mock import patch
from orders.models import Order
class OrderModelTest(CartSetupTestCase):
    def test_string_representation(self):
        # Mocking Order's post_save signal
        with patch('orders.signals.post_save_order', autospec=True) as mocked_handler:
            post_save.connect(
                mocked_handler,
                sender=Order,
                dispatch_uid='test_cache_mocked_handler'
            )
            order = Order.objects.create(
                user=self.user,
                merchant_uid="1475633246629",
                customer_name="asd",
                address="주소",
                address_detail="asdfdsa",
                postal_code="12345",
                phone_number="01095104344",
                possible_date_start="2011-11-24",
                possible_date_end="2011-11-24",
                possible_time_start="11:22 AM",
                possible_time_end="11:22 AM",
                total_price=self.cart.total_price,
            )
signals.py
@receiver(post_save, sender=Order, dispatch_uid="spacegraphy")
def post_save_order(sender, instance, created, **kwargs):
    if created:
        SlackNotification.objects.create(
            receiver="order_web",
            content="asdfasdf"
        )
I followed https://stackoverflow.com/a/13119150/3595632, but it doesn't work, which means, it called signal handler in real! (I checked it out using print())
Anything wrong?
 
     
    