Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4d948672
Commit
4d948672
authored
Dec 06, 2017
by
sandroroux
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Brought SiteConfig checks back.
parent
f52f0914
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
lms/djangoapps/discussion/signals/handlers.py
+10
-0
lms/djangoapps/discussion/tests/test_signals.py
+25
-0
lms/djangoapps/discussion/tests/test_tasks.py
+4
-0
No files found.
lms/djangoapps/discussion/signals/handlers.py
View file @
4d948672
...
@@ -25,6 +25,16 @@ def send_discussion_email_notification(sender, user, post, **kwargs):
...
@@ -25,6 +25,16 @@ def send_discussion_email_notification(sender, user, post, **kwargs):
log
.
info
(
'Discussion: No current site, not sending notification about post:
%
s.'
,
post
.
id
)
log
.
info
(
'Discussion: No current site, not sending notification about post:
%
s.'
,
post
.
id
)
return
return
try
:
if
not
current_site
.
configuration
.
get_value
(
ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
,
False
):
log_message
=
'Discussion: notifications not enabled for site:
%
s. Not sending message about post:
%
s.'
log
.
info
(
log_message
,
current_site
,
post
.
id
)
return
except
SiteConfiguration
.
DoesNotExist
:
log_message
=
'Discussion: No SiteConfiguration for site
%
s. Not sending message about post:
%
s.'
log
.
info
(
log_message
,
current_site
,
post
.
id
)
return
send_message
(
post
,
current_site
)
send_message
(
post
,
current_site
)
...
...
lms/djangoapps/discussion/tests/test_signals.py
View file @
4d948672
...
@@ -2,6 +2,7 @@ from django.test import TestCase
...
@@ -2,6 +2,7 @@ from django.test import TestCase
import
mock
import
mock
from
django_comment_common
import
signals
from
django_comment_common
import
signals
from
lms.djangoapps.discussion.signals.handlers
import
ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
from
openedx.core.djangoapps.site_configuration.tests.factories
import
SiteFactory
,
SiteConfigurationFactory
from
openedx.core.djangoapps.site_configuration.tests.factories
import
SiteFactory
,
SiteConfigurationFactory
from
openedx.core.djangoapps.waffle_utils.testutils
import
override_waffle_flag
from
openedx.core.djangoapps.waffle_utils.testutils
import
override_waffle_flag
...
@@ -18,6 +19,9 @@ class SendMessageHandlerTestCase(TestCase):
...
@@ -18,6 +19,9 @@ class SendMessageHandlerTestCase(TestCase):
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.get_current_site'
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.get_current_site'
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.send_message'
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.send_message'
)
def
test_comment_created_signal_sends_message
(
self
,
mock_send_message
,
mock_get_current_site
):
def
test_comment_created_signal_sends_message
(
self
,
mock_send_message
,
mock_get_current_site
):
site_config
=
SiteConfigurationFactory
.
create
(
site
=
self
.
site
)
site_config
.
values
[
ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
]
=
True
site_config
.
save
()
mock_get_current_site
.
return_value
=
self
.
site
mock_get_current_site
.
return_value
=
self
.
site
signals
.
comment_created
.
send
(
sender
=
self
.
sender
,
user
=
self
.
user
,
post
=
self
.
post
)
signals
.
comment_created
.
send
(
sender
=
self
.
sender
,
user
=
self
.
user
,
post
=
self
.
post
)
...
@@ -41,3 +45,24 @@ class SendMessageHandlerTestCase(TestCase):
...
@@ -41,3 +45,24 @@ class SendMessageHandlerTestCase(TestCase):
signals
.
comment_created
.
send
(
sender
=
self
.
sender
,
user
=
self
.
user
,
post
=
self
.
post
)
signals
.
comment_created
.
send
(
sender
=
self
.
sender
,
user
=
self
.
user
,
post
=
self
.
post
)
self
.
assertFalse
(
mock_send_message
.
called
)
self
.
assertFalse
(
mock_send_message
.
called
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.get_current_site'
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.send_message'
)
def
test_comment_created_signal_msg_not_sent_without_site_config
(
self
,
mock_send_message
,
mock_get_current_site
):
mock_get_current_site
.
return_value
=
self
.
site
signals
.
comment_created
.
send
(
sender
=
self
.
sender
,
user
=
self
.
user
,
post
=
self
.
post
)
self
.
assertFalse
(
mock_send_message
.
called
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.get_current_site'
)
@mock.patch
(
'lms.djangoapps.discussion.signals.handlers.send_message'
)
def
test_comment_created_signal_msg_not_sent_with_site_config_disabled
(
self
,
mock_send_message
,
mock_get_current_site
):
site_config
=
SiteConfigurationFactory
.
create
(
site
=
self
.
site
)
site_config
.
values
[
ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
]
=
False
site_config
.
save
()
mock_get_current_site
.
return_value
=
self
.
site
signals
.
comment_created
.
send
(
sender
=
self
.
sender
,
user
=
self
.
user
,
post
=
self
.
post
)
self
.
assertFalse
(
mock_send_message
.
called
)
lms/djangoapps/discussion/tests/test_tasks.py
View file @
4d948672
...
@@ -17,6 +17,7 @@ from django_comment_common.signals import comment_created
...
@@ -17,6 +17,7 @@ from django_comment_common.signals import comment_created
from
edx_ace.recipient
import
Recipient
from
edx_ace.recipient
import
Recipient
from
edx_ace.renderers
import
EmailRenderer
from
edx_ace.renderers
import
EmailRenderer
from
edx_ace.utils
import
date
from
edx_ace.utils
import
date
from
lms.djangoapps.discussion.signals.handlers
import
ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
from
lms.djangoapps.discussion.tasks
import
_should_send_message
from
lms.djangoapps.discussion.tasks
import
_should_send_message
from
openedx.core.djangoapps.content.course_overviews.tests.factories
import
CourseOverviewFactory
from
openedx.core.djangoapps.content.course_overviews.tests.factories
import
CourseOverviewFactory
from
openedx.core.djangoapps.ace_common.template_context
import
get_base_template_context
from
openedx.core.djangoapps.ace_common.template_context
import
get_base_template_context
...
@@ -182,6 +183,9 @@ class TaskTestCase(ModuleStoreTestCase):
...
@@ -182,6 +183,9 @@ class TaskTestCase(ModuleStoreTestCase):
user
=
mock
.
Mock
()
user
=
mock
.
Mock
()
comment
=
cc
.
Comment
.
find
(
id
=
self
.
comment
[
'id'
])
.
retrieve
()
comment
=
cc
.
Comment
.
find
(
id
=
self
.
comment
[
'id'
])
.
retrieve
()
site
=
Site
.
objects
.
get_current
()
site
=
Site
.
objects
.
get_current
()
site_config
=
SiteConfigurationFactory
.
create
(
site
=
site
)
site_config
.
values
[
ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
]
=
True
site_config
.
save
()
with
mock
.
patch
(
'lms.djangoapps.discussion.signals.handlers.get_current_site'
,
return_value
=
site
):
with
mock
.
patch
(
'lms.djangoapps.discussion.signals.handlers.get_current_site'
,
return_value
=
site
):
comment_created
.
send
(
sender
=
None
,
user
=
user
,
post
=
comment
)
comment_created
.
send
(
sender
=
None
,
user
=
user
,
post
=
comment
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment