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
9068c7e2
Commit
9068c7e2
authored
Nov 03, 2016
by
Adam Palay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle refund notification message formatting when translated with unicode characters (ECOM-5858)
parent
68bf1c52
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
27 deletions
+45
-27
lms/djangoapps/commerce/signals.py
+5
-3
lms/djangoapps/commerce/tests/test_signals.py
+40
-24
No files found.
lms/djangoapps/commerce/signals.py
View file @
9068c7e2
"""
Signal handling functions for use with external commerce service.
"""
from
__future__
import
unicode_literals
import
json
import
logging
from
urlparse
import
urljoin
import
requests
from
django.conf
import
settings
from
django.contrib.auth.models
import
AnonymousUser
from
django.dispatch
import
receiver
from
django.utils.translation
import
ugettext
as
_
from
edx_rest_api_client.exceptions
import
HttpClientError
import
requests
from
request_cache.middleware
import
RequestCache
from
student.models
import
UNENROLL_DONE
from
openedx.core.djangoapps.commerce.utils
import
ecommerce_api_client
,
is_commerce_service_configured
from
openedx.core.djangoapps.site_configuration
import
helpers
as
configuration_helpers
from
openedx.core.djangoapps.theming
import
helpers
as
theming_helpers
...
...
@@ -182,7 +184,7 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
# Check for HTTP codes other than 201 (Created)
if
response
.
status_code
!=
201
:
log
.
error
(
u
'Failed to create ticket. Status: [
%
d], Body: [
%
s]'
,
response
.
status_code
,
response
.
content
)
log
.
error
(
'Failed to create ticket. Status: [
%
d], Body: [
%
s]'
,
response
.
status_code
,
response
.
content
)
else
:
log
.
debug
(
'Successfully created ticket.'
)
except
Exception
:
# pylint: disable=broad-except
...
...
lms/djangoapps/commerce/tests/test_signals.py
View file @
9068c7e2
# coding=UTF-8
"""
Tests for signal handling in commerce djangoapp.
"""
from
__future__
import
unicode_literals
import
base64
import
json
from
urlparse
import
urljoin
...
...
@@ -41,7 +44,10 @@ class TestRefundSignal(TestCase):
def
setUp
(
self
):
super
(
TestRefundSignal
,
self
)
.
setUp
()
self
.
requester
=
UserFactory
(
username
=
"test-requester"
)
self
.
student
=
UserFactory
(
username
=
"test-student"
,
email
=
"test-student@example.com"
)
self
.
student
=
UserFactory
(
username
=
"test-student"
,
email
=
"test-student@example.com"
,
)
self
.
course_enrollment
=
CourseEnrollmentFactory
(
user
=
self
.
student
,
course_id
=
CourseKey
.
from_string
(
'course-v1:org+course+run'
),
...
...
@@ -207,25 +213,35 @@ class TestRefundSignal(TestCase):
with
self
.
assertRaises
(
NotImplementedError
):
send_refund_notification
(
self
.
course_enrollment
,
[
1
,
2
,
3
])
def
test_send_refund_notification
(
self
):
@ddt.data
(
'email@example.com'
,
'üñîcode.email@example.com'
)
@mock.patch
(
'lms.djangoapps.commerce.signals.create_zendesk_ticket'
)
def
test_send_refund_notification
(
self
,
student_email
,
mock_zendesk
):
""" Verify the support team is notified of the refund request. """
with
mock
.
patch
(
'commerce.signals.create_zendesk_ticket'
)
as
mock_zendesk
:
refund_ids
=
[
1
,
2
,
3
]
send_refund_notification
(
self
.
course_enrollment
,
refund_ids
)
body
=
generate_refund_notification_body
(
self
.
student
,
refund_ids
)
mock_zendesk
.
assert_called_with
(
self
.
student
.
profile
.
name
,
self
.
student
.
email
,
"[Refund] User-Requested Refund"
,
body
,
[
'auto_refund'
])
refund_ids
=
[
1
,
2
,
3
]
# pass a student with unicode and ascii email to ensure that
# generate_refund_notification_body can handle formatting a unicode
# message
self
.
student
.
email
=
student_email
send_refund_notification
(
self
.
course_enrollment
,
refund_ids
)
body
=
generate_refund_notification_body
(
self
.
student
,
refund_ids
)
mock_zendesk
.
assert_called_with
(
self
.
student
.
profile
.
name
,
self
.
student
.
email
,
"[Refund] User-Requested Refund"
,
body
,
[
'auto_refund'
]
)
def
_mock_zendesk_api
(
self
,
status
=
201
):
""" Mock Zendesk's ticket creation API. """
httpretty
.
register_uri
(
httpretty
.
POST
,
urljoin
(
ZENDESK_URL
,
'/api/v2/tickets.json'
),
status
=
status
,
body
=
'{}'
,
content_type
=
JSON
)
def
call_create_zendesk_ticket
(
self
,
name
=
u'Test user'
,
email
=
u'user@example.com'
,
subject
=
u
'Test Ticket'
,
body
=
u
'I want a refund!'
,
tags
=
None
):
def
call_create_zendesk_ticket
(
self
,
name
=
'Test user'
,
email
=
'user@example.com'
,
subject
=
'Test Ticket'
,
body
=
'I want a refund!'
,
tags
=
None
):
""" Call the create_zendesk_ticket function. """
tags
=
tags
or
[
u
'auto_refund'
]
tags
=
tags
or
[
'auto_refund'
]
create_zendesk_ticket
(
name
,
email
,
subject
,
body
,
tags
)
@override_settings
(
ZENDESK_URL
=
ZENDESK_URL
,
ZENDESK_USER
=
None
,
ZENDESK_API_KEY
=
None
)
...
...
@@ -250,11 +266,11 @@ class TestRefundSignal(TestCase):
""" Verify the Zendesk API is called. """
self
.
_mock_zendesk_api
()
name
=
u
'Test user'
email
=
u
'user@example.com'
subject
=
u
'Test Ticket'
body
=
u
'I want a refund!'
tags
=
[
u
'auto_refund'
]
name
=
'Test user'
email
=
'user@example.com'
subject
=
'Test Ticket'
body
=
'I want a refund!'
tags
=
[
'auto_refund'
]
self
.
call_create_zendesk_ticket
(
name
,
email
,
subject
,
body
,
tags
)
last_request
=
httpretty
.
last_request
()
...
...
@@ -268,14 +284,14 @@ class TestRefundSignal(TestCase):
# Verify the content
expected
=
{
u
'ticket'
:
{
u
'requester'
:
{
u
'name'
:
name
,
u
'email'
:
email
'ticket'
:
{
'requester'
:
{
'name'
:
name
,
'email'
:
email
},
u
'subject'
:
subject
,
u'comment'
:
{
u
'body'
:
body
},
u'tags'
:
[
u
'LMS'
]
+
tags
'subject'
:
subject
,
'comment'
:
{
'body'
:
body
},
'tags'
:
[
'LMS'
]
+
tags
}
}
self
.
assertDictEqual
(
json
.
loads
(
last_request
.
body
),
expected
)
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