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
322de960
Commit
322de960
authored
Mar 03, 2017
by
bmedx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address PR feedback
parent
d5eb9c0b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
cms/djangoapps/cms_user_tasks/signals.py
+6
-2
cms/djangoapps/cms_user_tasks/tests.py
+31
-0
No files found.
cms/djangoapps/cms_user_tasks/signals.py
View file @
322de960
"""
Receivers of signals sent from django-user-tasks
"""
from
__future__
import
absolute_import
,
print_function
,
unicode_literals
import
logging
from
url
parse
import
urljoin
from
six.moves.urllib.
parse
import
urljoin
from
django.core.urlresolvers
import
reverse
from
django.dispatch
import
receiver
...
...
@@ -11,6 +13,8 @@ from user_tasks.signals import user_task_stopped
from
.tasks
import
send_task_complete_email
LOGGER
=
logging
.
getLogger
(
__name__
)
@receiver
(
user_task_stopped
,
dispatch_uid
=
"cms_user_task_stopped"
)
def
user_task_stopped_handler
(
sender
,
**
kwargs
):
# pylint: disable=unused-argument
...
...
@@ -47,4 +51,4 @@ def user_task_stopped_handler(sender, **kwargs): # pylint: disable=unused-argum
# Need to str state_text here because it is a proxy object and won't serialize correctly
send_task_complete_email
.
delay
(
status
.
name
.
lower
(),
str
(
status
.
state_text
),
status
.
user
.
email
,
detail_url
)
except
Exception
:
# pylint: disable=broad-except
logging
.
exception
(
"Unable to queue send_task_complete_email"
)
LOGGER
.
exception
(
"Unable to queue send_task_complete_email"
)
cms/djangoapps/cms_user_tasks/tests.py
View file @
322de960
...
...
@@ -4,7 +4,9 @@ Unit tests for integration of the django-user-tasks app and its REST API.
from
__future__
import
absolute_import
,
print_function
,
unicode_literals
import
sys
from
uuid
import
uuid4
import
logging
import
mock
from
boto.exception
import
NoAuthHandlerFound
...
...
@@ -21,6 +23,24 @@ from user_tasks.serializers import ArtifactSerializer, StatusSerializer
from
.signals
import
user_task_stopped
# Mock logging handler to check for expected logs.
class
MockLoggingHandler
(
logging
.
Handler
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
reset
()
logging
.
Handler
.
__init__
(
self
,
*
args
,
**
kwargs
)
def
emit
(
self
,
record
):
self
.
messages
[
record
.
levelname
.
lower
()]
.
append
(
record
.
getMessage
())
def
reset
(
self
):
self
.
messages
=
{
'debug'
:
[],
'info'
:
[],
'warning'
:
[],
'error'
:
[],
'critical'
:
[],
}
# Helper functions for stuff that pylint complains about without disable comments
def
_context
(
response
):
...
...
@@ -199,3 +219,14 @@ class TestUserTaskStopped(APITestCase):
with
mock
.
patch
(
'cms_user_tasks.tasks.send_task_complete_email.retry'
)
as
mock_retry
:
user_task_stopped
.
send
(
sender
=
UserTaskStatus
,
status
=
self
.
status
)
self
.
assertTrue
(
mock_retry
.
called
)
def
test_queue_email_failure
(
self
):
logger
=
logging
.
getLogger
(
"cms_user_tasks.signals"
)
hdlr
=
MockLoggingHandler
(
level
=
"DEBUG"
)
logger
.
addHandler
(
hdlr
)
with
mock
.
patch
(
'cms_user_tasks.tasks.send_task_complete_email.delay'
)
as
mock_delay
:
mock_delay
.
side_effect
=
NoAuthHandlerFound
()
user_task_stopped
.
send
(
sender
=
UserTaskStatus
,
status
=
self
.
status
)
self
.
assertTrue
(
mock_delay
.
called
)
self
.
assertEqual
(
hdlr
.
messages
[
'error'
][
0
],
u'Unable to queue send_task_complete_email'
)
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