Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
28b633f9
Commit
28b633f9
authored
10 years ago
by
Awais
Committed by
Awais Qureshi
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ECOM-1086 adding tracking event for cert generation.
parent
6f7a0665
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/courseware/tests/test_views.py
+22
-2
22 additions, 2 deletions
lms/djangoapps/courseware/tests/test_views.py
lms/djangoapps/courseware/views.py
+32
-0
32 additions, 0 deletions
lms/djangoapps/courseware/views.py
with
54 additions
and
2 deletions
lms/djangoapps/courseware/tests/test_views.py
+
22
−
2
View file @
28b633f9
...
...
@@ -769,11 +769,15 @@ class GenerateUserCertTests(ModuleStoreTestCase):
self
.
assertIn
(
"
Your certificate will be available when you pass the course.
"
,
resp
.
content
)
@patch
(
'
courseware.grades.grade
'
,
Mock
(
return_value
=
{
'
grade
'
:
'
Pass
'
,
'
percent
'
:
0.75
}))
@override_settings
(
CERT_QUEUE
=
'
certificates
'
)
@override_settings
(
CERT_QUEUE
=
'
certificates
'
,
SEGMENT_IO_LMS_KEY
=
"
foobar
"
,
FEATURES
=
{
'
SEGMENT_IO_LMS
'
:
True
}
)
def
test_user_with_passing_grade
(
self
):
# If user has above passing grading then json will return cert generating message and
# status valid code
# mocking xqueue
# mocking xqueue and analytics
analytics_patcher
=
patch
(
'
courseware.views.analytics
'
)
mock_tracker
=
analytics_patcher
.
start
()
self
.
addCleanup
(
analytics_patcher
.
stop
)
with
patch
(
'
capa.xqueue_interface.XQueueInterface.send_to_queue
'
)
as
mock_send_to_queue
:
mock_send_to_queue
.
return_value
=
(
0
,
"
Successfully queued
"
)
...
...
@@ -781,6 +785,22 @@ class GenerateUserCertTests(ModuleStoreTestCase):
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertIn
(
"
Creating certificate
"
,
resp
.
content
)
#Verify Google Analytics event fired after generating certificate
mock_tracker
.
track
.
assert_called_once_with
(
# pylint: disable=no-member
self
.
student
.
id
,
# pylint: disable=no-member
'
edx.bi.user.certificate.generate
'
,
{
'
category
'
:
'
certificates
'
,
'
label
'
:
unicode
(
self
.
course
.
id
)
},
context
=
{
'
Google Analytics
'
:
{
'
clientId
'
:
None
}
}
)
mock_tracker
.
reset_mock
()
@patch
(
'
courseware.grades.grade
'
,
Mock
(
return_value
=
{
'
grade
'
:
'
Pass
'
,
'
percent
'
:
0.75
}))
def
test_user_with_passing_existing_generating_cert
(
self
):
# If user has passing grade but also has existing generating cert
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/courseware/views.py
+
32
−
0
View file @
28b633f9
...
...
@@ -71,6 +71,8 @@ import survey.utils
import
survey.views
from
util.views
import
ensure_valid_course_key
from
eventtracking
import
tracker
import
analytics
log
=
logging
.
getLogger
(
"
edx.courseware
"
)
...
...
@@ -1303,6 +1305,7 @@ def generate_user_cert(request, course_id):
if
not
certificate_status
[
"
is_downloadable
"
]
and
not
certificate_status
[
"
is_generating
"
]:
generate_user_certificates
(
student
,
course
)
_track_successful_certificate_generation
(
student
.
id
,
course
.
id
)
return
HttpResponse
(
_
(
"
Creating certificate
"
))
# if certificate_status is not is_downloadable and is_generating or
...
...
@@ -1311,3 +1314,32 @@ def generate_user_cert(request, course_id):
# at backend debug the issue and re-submit the task.
return
HttpResponseBadRequest
(
_
(
"
Creating certificate
"
))
def
_track_successful_certificate_generation
(
user_id
,
course_id
):
# pylint: disable=invalid-name
"""
Track an successfully certificate generation event.
Arguments:
user_id (str): The ID of the user generting the certificate.
course_id (unicode): id associated with the course
Returns:
None
"""
if
settings
.
FEATURES
.
get
(
'
SEGMENT_IO_LMS
'
)
and
hasattr
(
settings
,
'
SEGMENT_IO_LMS_KEY
'
):
event_name
=
'
edx.bi.user.certificate.generate
'
# pylint: disable=no-member
tracking_context
=
tracker
.
get_tracker
().
resolve_context
()
# pylint: disable=no-member
analytics
.
track
(
user_id
,
event_name
,
{
'
category
'
:
'
certificates
'
,
'
label
'
:
unicode
(
course_id
)
},
context
=
{
'
Google Analytics
'
:
{
'
clientId
'
:
tracking_context
.
get
(
'
client_id
'
)
}
}
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment