Skip to content

Commit

Permalink
Merge pull request mdn#1035 from lmorchard/863692-delete-exception-wa…
Browse files Browse the repository at this point in the history
…ffle

bug 863692: Waffle switch "wiki_error_on_delete"
  • Loading branch information
groovecoder committed Apr 22, 2013
2 parents 1716ae7 + eefb6f6 commit f2f5ab1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/wiki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
from taggit.managers import TaggableManager
from taggit.utils import parse_tags, edit_string_for_tags

import waffle

from wiki import TEMPLATE_TITLE_PREFIX
import wiki.content

Expand Down Expand Up @@ -1034,8 +1036,11 @@ def save(self, *args, **kwargs):
del self.old_title

def delete(self, *args, **kwargs):
# Temporary while we investigate disappearing pages.
raise Exception("Attempt to delete document %s: %s" % (self.id, self.title))
if waffle.switch_is_active('wiki_error_on_delete'):
# bug 863692: Temporary while we investigate disappearing pages.
raise Exception("Attempt to delete document %s: %s" % (self.id, self.title))
else:
super(Document, self).delete(*args, **kwargs)

def move(self, new_slug=None, user=None):
"""
Expand Down
22 changes: 22 additions & 0 deletions apps/wiki/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import constance.config

from waffle.models import Flag, Switch

from sumo import ProgrammingError
from sumo.tests import TestCase

Expand Down Expand Up @@ -135,6 +137,26 @@ def test_document_is_template(self):

assert not d.is_template

def test_error_on_delete(self):
"""Ensure error-on-delete is only thrown when waffle switch active"""
switch = Switch.objects.create(name='wiki_error_on_delete')

for active in (True, False):

switch.active = active
switch.save()

d = document()
d.save()

try:
d.delete()
if active:
ok_(False, 'Exception on delete when active')
except Exception, e:
if not active:
ok_(False, 'No exception on delete when not active')

def test_delete_tagged_document(self):
"""Make sure deleting a tagged doc deletes its tag relationships."""
# TODO: Move to wherever the tests for TaggableMixin are.
Expand Down

0 comments on commit f2f5ab1

Please sign in to comment.