# Path: webplatformcompat/signals.py
# def post_save_update_cache(sender, instance, created, raw, **kwargs):
#     """Invalidate the cache when an instance is created or updated."""
#     if raw:
#         return
#     name = sender.__name__
#     if name == 'User' and created:
#         return
#     delay_cache = getattr(instance, '_delay_cache', False)
#     if not delay_cache:
#         update_cache_for_instance(name, instance.pk, instance)


import mock
import unittest
from webplatformcompat.models import Browser, Maturity
from webplatformcompat.signals import post_save_update_cache
from .base import TestCase
            'webplatformcompat.signals.update_cache_for_instance')
        self.login_user()
        self.mocked_update_cache = patcher.start()
        self.addCleanup(patcher.stop)
        self.maturity = self.create(Maturity, slug='foo')
        self.mocked_update_cache.reset_mock()

    def test_delete(self):
        pk = self.maturity.pk
        self.maturity.delete()
        self.mocked_update_cache.assert_called_once_with(
            'Maturity', pk, self.maturity)

    def test_delete_delayed(self):
        self.maturity._delay_cache = True
        self.maturity.delete()
        self.mocked_update_cache.assert_not_called()


class TestSaveSignal(unittest.TestCase):
    def setUp(self):
        self.patcher = mock.patch(
            'webplatformcompat.signals.update_cache_for_instance')
        self.mocked_update_cache = self.patcher.start()
        self.browser = Browser(id=666)

    def tearDown(self):
        self.patcher.stop()

    def test_raw(self):

# Path: webplatformcompat/signals.py
# def post_save_update_cache(sender, instance, created, raw, **kwargs):
#     """Invalidate the cache when an instance is created or updated."""
#     if raw:
#         return
#     name = sender.__name__
#     if name == 'User' and created:
#         return
#     delay_cache = getattr(instance, '_delay_cache', False)
#     if not delay_cache:
#         update_cache_for_instance(name, instance.pk, instance)


# Path: webplatformcompat/tests/test_signals.py
import mock
import unittest
from webplatformcompat.models import Browser, Maturity
from webplatformcompat.signals import post_save_update_cache
from .base import TestCase

            'webplatformcompat.signals.update_cache_for_instance')
        self.login_user()
        self.mocked_update_cache = patcher.start()
        self.addCleanup(patcher.stop)
        self.maturity = self.create(Maturity, slug='foo')
        self.mocked_update_cache.reset_mock()

    def test_delete(self):
        pk = self.maturity.pk
        self.maturity.delete()
        self.mocked_update_cache.assert_called_once_with(
            'Maturity', pk, self.maturity)

    def test_delete_delayed(self):
        self.maturity._delay_cache = True
        self.maturity.delete()
        self.mocked_update_cache.assert_not_called()


class TestSaveSignal(unittest.TestCase):
    def setUp(self):
        self.patcher = mock.patch(
            'webplatformcompat.signals.update_cache_for_instance')
        self.mocked_update_cache = self.patcher.start()
        self.browser = Browser(id=666)

    def tearDown(self):
        self.patcher.stop()

    def test_raw(self):

        post_save_update_cache(Browser, self.browser, created=True, raw=True)