Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
bug 1216786 - Drop Feature/Section M2M signal
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitlock committed Feb 25, 2016
1 parent f282111 commit c9397df
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 88 deletions.
9 changes: 1 addition & 8 deletions webplatformcompat/apps.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Application configuration."""
from django.apps import AppConfig
from django.db.models.signals import post_delete, post_save, m2m_changed
from django.db.models.signals import post_delete, post_save


class WebPlatformCompatConfig(AppConfig):
Expand All @@ -20,7 +20,6 @@ def ready(self):
Support, Version)
from webplatformcompat.signals import (
add_user_to_change_resource_group,
feature_sections_changed_update_order,
post_delete_update_cache,
post_save_changeset,
post_save_update_cache)
Expand All @@ -31,12 +30,6 @@ def ready(self):
sender=User,
dispatch_uid='add_user_to_change_resource_group')

# Invalidate instance cache when features-to-sections changes
m2m_changed.connect(
feature_sections_changed_update_order,
sender=Feature.sections.through,
dispatch_uid='m2m_changed_feature_section')

# Invalidate instance cache on model changes
for model in (
Browser, Feature, Maturity, Reference, Section,
Expand Down
32 changes: 0 additions & 32 deletions webplatformcompat/signals.py
Expand Up @@ -5,7 +5,6 @@

from django.contrib.auth.models import Group

from .models import Feature, Section
from .tasks import update_cache_for_instance


Expand All @@ -16,37 +15,6 @@ def add_user_to_change_resource_group(
instance.groups.add(Group.objects.get(name='change-resource'))


def feature_sections_changed_update_order(
sender, instance, action, reverse, model, pk_set, **kwargs):
"""Maintain feature.section_order."""
if action not in ('post_add', 'post_remove', 'post_clear'):
# post_clear is not handled, because clear is called in
# django.db.models.fields.related.ReverseManyRelatedObjects.__set__
# before setting the new order
return
if getattr(instance, '_delay_cache', False):
return

if model == Section:
assert type(instance) == Feature
features = [instance]
if pk_set:
sections = list(Section.objects.filter(pk__in=pk_set))
else:
sections = []
else:
if pk_set:
features = list(Feature.objects.filter(pk__in=pk_set))
else:
features = []
sections = [instance]

for feature in features:
update_cache_for_instance('Feature', feature.pk, feature)
for section in sections:
update_cache_for_instance('Section', section.pk, section)


def post_delete_update_cache(sender, instance, **kwargs):
"""Invalidate the cache when an instance is deleted."""
name = sender.__name__
Expand Down
49 changes: 1 addition & 48 deletions webplatformcompat/tests/test_signals.py
Expand Up @@ -3,8 +3,7 @@
import mock
import unittest

from webplatformcompat.models import (
Browser, Feature, Maturity, Section, Specification)
from webplatformcompat.models import Browser, Maturity
from webplatformcompat.signals import post_save_update_cache
from .base import TestCase

Expand All @@ -31,52 +30,6 @@ def test_delete_delayed(self):
self.mocked_update_cache.assert_not_called()


class TestM2MChangedSignal(TestCase):
def setUp(self):
patcher = mock.patch(
'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.specification = self.create(Specification, maturity=self.maturity)
self.section = self.create(Section, specification=self.specification)
self.feature = self.create(Feature)
self.mocked_update_cache.reset_mock()

def tearDown(self):
self.section.delete()
self.specification.delete()
self.maturity.delete()
self.feature.delete()

def test_add_section_to_feature(self):
self.feature.sections.add(self.section)
self.mocked_update_cache.assert_has_calls([
mock.call('Feature', self.feature.pk, self.feature),
mock.call('Section', self.section.pk, self.section)])
self.assertEqual(self.mocked_update_cache.call_count, 2)

def test_add_section_to_feature_delayed(self):
self.feature._delay_cache = True
self.feature.sections.add(self.section)
self.mocked_update_cache.assert_not_called()

def test_add_feature_to_section(self):
self.section.features.add(self.feature)
self.mocked_update_cache.assert_has_calls([
mock.call('Feature', self.feature.pk, self.feature),
mock.call('Section', self.section.pk, self.section)])
self.assertEqual(self.mocked_update_cache.call_count, 2)

def test_clear_features_from_section(self):
self.section.features.add(self.feature)
self.mocked_update_cache.reset_mock()
self.section.features.clear()
self.mocked_update_cache.assert_called_once_with(
'Section', self.section.pk, self.section)


class TestSaveSignal(unittest.TestCase):
def setUp(self):
self.patcher = mock.patch(
Expand Down

0 comments on commit c9397df

Please sign in to comment.