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
6dbfb326
Commit
6dbfb326
authored
Dec 07, 2016
by
Simon Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support the display of downloadable PDF course certs ECOM-5790
parent
ff7c2f8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
11 deletions
+62
-11
lms/djangoapps/certificates/tests/test_api.py
+60
-11
openedx/core/djangoapps/programs/utils.py
+2
-0
No files found.
lms/djangoapps/certificates/tests/test_api.py
View file @
6dbfb326
...
...
@@ -2,10 +2,12 @@
from
contextlib
import
contextmanager
import
ddt
from
functools
import
wraps
import
uuid
from
django.test
import
TestCase
,
RequestFactory
from
django.test.utils
import
override_settings
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
mock
import
patch
from
nose.plugins.attrib
import
attr
from
opaque_keys.edx.locator
import
CourseLocator
...
...
@@ -323,43 +325,48 @@ class CertificateGetTests(SharedModuleStoreTestCase):
super
(
CertificateGetTests
,
cls
)
.
setUpClass
()
cls
.
student
=
UserFactory
()
cls
.
student_no_cert
=
UserFactory
()
cls
.
course_1
=
CourseFactory
.
create
(
cls
.
uuid
=
uuid
.
uuid4
()
.
hex
cls
.
web_cert_course
=
CourseFactory
.
create
(
org
=
'edx'
,
number
=
'verified_1'
,
display_name
=
'Verified Course 1'
display_name
=
'Verified Course 1'
,
cert_html_view_enabled
=
True
)
cls
.
course_2
=
CourseFactory
.
create
(
cls
.
pdf_cert_course
=
CourseFactory
.
create
(
org
=
'edx'
,
number
=
'verified_2'
,
display_name
=
'Verified Course 2'
display_name
=
'Verified Course 2'
,
cert_html_view_enabled
=
False
)
# certificate for the first course
GeneratedCertificateFactory
.
create
(
user
=
cls
.
student
,
course_id
=
cls
.
course_1
.
id
,
course_id
=
cls
.
web_cert_course
.
id
,
status
=
CertificateStatuses
.
downloadable
,
mode
=
'verified'
,
download_url
=
'www.google.com'
,
grade
=
"0.88"
,
verify_uuid
=
cls
.
uuid
,
)
# certificate for the second course
GeneratedCertificateFactory
.
create
(
user
=
cls
.
student
,
course_id
=
cls
.
course_2
.
id
,
course_id
=
cls
.
pdf_cert_course
.
id
,
status
=
CertificateStatuses
.
downloadable
,
mode
=
'honor'
,
download_url
=
'www.gmail.com'
,
grade
=
"0.99"
,
verify_uuid
=
cls
.
uuid
,
)
def
test_get_certificate_for_user
(
self
):
"""
Test to get a certificate for a user for a specific course.
"""
cert
=
certs_api
.
get_certificate_for_user
(
self
.
student
.
username
,
self
.
course_1
.
id
)
cert
=
certs_api
.
get_certificate_for_user
(
self
.
student
.
username
,
self
.
web_cert_course
.
id
)
self
.
assertEqual
(
cert
[
'username'
],
self
.
student
.
username
)
self
.
assertEqual
(
cert
[
'course_key'
],
self
.
course_1
.
id
)
self
.
assertEqual
(
cert
[
'course_key'
],
self
.
web_cert_course
.
id
)
self
.
assertEqual
(
cert
[
'type'
],
CourseMode
.
VERIFIED
)
self
.
assertEqual
(
cert
[
'status'
],
CertificateStatuses
.
downloadable
)
self
.
assertEqual
(
cert
[
'grade'
],
"0.88"
)
...
...
@@ -373,8 +380,8 @@ class CertificateGetTests(SharedModuleStoreTestCase):
self
.
assertEqual
(
len
(
certs
),
2
)
self
.
assertEqual
(
certs
[
0
][
'username'
],
self
.
student
.
username
)
self
.
assertEqual
(
certs
[
1
][
'username'
],
self
.
student
.
username
)
self
.
assertEqual
(
certs
[
0
][
'course_key'
],
self
.
course_1
.
id
)
self
.
assertEqual
(
certs
[
1
][
'course_key'
],
self
.
course_2
.
id
)
self
.
assertEqual
(
certs
[
0
][
'course_key'
],
self
.
web_cert_course
.
id
)
self
.
assertEqual
(
certs
[
1
][
'course_key'
],
self
.
pdf_cert_course
.
id
)
self
.
assertEqual
(
certs
[
0
][
'type'
],
CourseMode
.
VERIFIED
)
self
.
assertEqual
(
certs
[
1
][
'type'
],
CourseMode
.
HONOR
)
self
.
assertEqual
(
certs
[
0
][
'status'
],
CertificateStatuses
.
downloadable
)
...
...
@@ -389,7 +396,7 @@ class CertificateGetTests(SharedModuleStoreTestCase):
Test the case when there is no certificate for a user for a specific course.
"""
self
.
assertIsNone
(
certs_api
.
get_certificate_for_user
(
self
.
student_no_cert
.
username
,
self
.
course_1
.
id
)
certs_api
.
get_certificate_for_user
(
self
.
student_no_cert
.
username
,
self
.
web_cert_course
.
id
)
)
def
test_no_certificates_for_user
(
self
):
...
...
@@ -401,6 +408,48 @@ class CertificateGetTests(SharedModuleStoreTestCase):
[]
)
@patch.dict
(
settings
.
FEATURES
,
{
'CERTIFICATES_HTML_VIEW'
:
True
})
def
test_get_web_certificate_url
(
self
):
"""
Test the get_certificate_url with a web cert course
"""
expected_url
=
reverse
(
'certificates:render_cert_by_uuid'
,
kwargs
=
dict
(
certificate_uuid
=
self
.
uuid
)
)
cert_url
=
certs_api
.
get_certificate_url
(
user_id
=
self
.
student
.
id
,
# pylint: disable=no-member
course_id
=
self
.
web_cert_course
.
id
,
uuid
=
self
.
uuid
)
self
.
assertEqual
(
expected_url
,
cert_url
)
expected_url
=
reverse
(
'certificates:html_view'
,
kwargs
=
{
"user_id"
:
str
(
self
.
student
.
id
),
# pylint: disable=no-member
"course_id"
:
unicode
(
self
.
web_cert_course
.
id
),
}
)
cert_url
=
certs_api
.
get_certificate_url
(
user_id
=
self
.
student
.
id
,
# pylint: disable=no-member
course_id
=
self
.
web_cert_course
.
id
)
self
.
assertEqual
(
expected_url
,
cert_url
)
@patch.dict
(
settings
.
FEATURES
,
{
'CERTIFICATES_HTML_VIEW'
:
True
})
def
test_get_pdf_certificate_url
(
self
):
"""
Test the get_certificate_url with a pdf cert course
"""
cert_url
=
certs_api
.
get_certificate_url
(
user_id
=
self
.
student
.
id
,
# pylint: disable=no-member
course_id
=
self
.
pdf_cert_course
.
id
,
uuid
=
self
.
uuid
)
self
.
assertEqual
(
'www.gmail.com'
,
cert_url
)
@attr
(
shard
=
1
)
@override_settings
(
CERT_QUEUE
=
'certificates'
)
...
...
openedx/core/djangoapps/programs/utils.py
View file @
6dbfb326
...
...
@@ -373,6 +373,8 @@ class ProgramDataExtender(object):
certificate_data
=
certificate_api
.
certificate_downloadable_status
(
self
.
user
,
self
.
course_key
)
certificate_uuid
=
certificate_data
.
get
(
'uuid'
)
run_mode
[
'certificate_url'
]
=
certificate_api
.
get_certificate_url
(
user_id
=
self
.
user
.
id
,
# Providing user_id allows us to fall back to PDF certificates
# if web certificates are not configured for a given course.
course_id
=
self
.
course_key
,
uuid
=
certificate_uuid
,
)
if
certificate_uuid
else
None
...
...
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