-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for #7. implementing a comment_removed signal for other apps to l…
…isten for. comment_removed is sent when a comment is deleted or when a comment's is_removed attribute is flipped from True to False.
- Loading branch information
andy
committed
Jul 10, 2012
1 parent
79a669e
commit eb34f76
Showing
4 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.dispatch import Signal | ||
|
||
comment_removed = Signal(providing_args=['comment']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from django.test import TestCase | ||
|
||
from ella.utils.test_helpers import create_basic_categories, create_and_place_a_publishable | ||
|
||
from test_ella_comments.helpers import create_comment | ||
from ella_comments.signals import comment_removed | ||
|
||
from nose import tools | ||
|
||
SIGNALED_COMMENT = None | ||
def handle_signal(comment, **kwargs): | ||
global SIGNALED_COMMENT | ||
SIGNALED_COMMENT = comment.id | ||
|
||
def reset_signaled_comment(): | ||
global SIGNALED_COMMENT | ||
SIGNALED_COMMENT = None | ||
|
||
class TestSignals(TestCase): | ||
def setUp(self): | ||
super(TestSignals, self).setUp() | ||
reset_signaled_comment() | ||
comment_removed.connect(handle_signal) | ||
create_basic_categories(self) | ||
create_and_place_a_publishable(self) | ||
self.comment = create_comment(self.publishable, self.publishable.content_type) | ||
|
||
def tearDown(self): | ||
comment_removed.disconnect(handle_signal) | ||
reset_signaled_comment() | ||
super(TestSignals, self).tearDown() | ||
|
||
def test_deleted_comment_sends_signal(self): | ||
id = self.comment.id | ||
tools.assert_equals(SIGNALED_COMMENT, None) | ||
self.comment.delete() | ||
tools.assert_equals(SIGNALED_COMMENT, id) | ||
|
||
def test_moderated_comment_sends_signal(self): | ||
id = self.comment.id | ||
tools.assert_equals(SIGNALED_COMMENT, None) | ||
self.comment.is_removed = True | ||
self.comment.save() | ||
tools.assert_equals(SIGNALED_COMMENT, id) | ||
|
||
def test_general_comment_save_doesnt_send_signal(self): | ||
tools.assert_equals(SIGNALED_COMMENT, None) | ||
self.comment.save() | ||
tools.assert_equals(SIGNALED_COMMENT, None) |