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
a9643c67
Commit
a9643c67
authored
Sep 23, 2015
by
Brian Beggs
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9896 from edx/mattdrayer/release/SOL-1230
mattdrayer/release/SOL-1230
parents
969cf766
2bd26fc0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
lms/djangoapps/certificates/tests/test_webview_views.py
+29
-0
lms/djangoapps/certificates/views/webview.py
+19
-7
No files found.
lms/djangoapps/certificates/tests/test_webview_views.py
View file @
a9643c67
...
...
@@ -12,6 +12,7 @@ from django.test.utils import override_settings
from
openedx.core.lib.tests.assertions.events
import
assert_event_matches
from
student.tests.factories
import
UserFactory
,
CourseEnrollmentFactory
from
student.roles
import
CourseStaffRole
from
track.tests
import
EventTrackingTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
@@ -347,6 +348,13 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
course_id
=
unicode
(
self
.
course
.
id
)
)
response
=
self
.
client
.
get
(
test_url
+
'?preview=honor'
)
#accessing certificate web view in preview mode without
# staff or instructor access should show invalid certificate
self
.
assertIn
(
'This is an invalid certificate number'
,
response
.
content
)
CourseStaffRole
(
self
.
course
.
id
)
.
add_users
(
self
.
user
)
response
=
self
.
client
.
get
(
test_url
+
'?preview=honor'
)
self
.
assertNotIn
(
self
.
course
.
display_name
,
response
.
content
)
self
.
assertIn
(
'course_title_0'
,
response
.
content
)
self
.
assertIn
(
'Signatory_Title 0'
,
response
.
content
)
...
...
@@ -359,6 +367,27 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
self
.
assertIn
(
'Signatory_Title 0'
,
response
.
content
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_render_html_view_with_preview_mode_when_user_already_has_cert
(
self
):
"""
test certificate web view should render properly in
preview mode even if user who is previewing already has a certificate
generated with different mode.
"""
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
CourseStaffRole
(
self
.
course
.
id
)
.
add_users
(
self
.
user
)
test_url
=
get_certificate_url
(
user_id
=
self
.
user
.
id
,
course_id
=
unicode
(
self
.
course
.
id
)
)
# user has already has certificate generated for 'honor' mode
# so let's try to preview in 'verified' mode.
response
=
self
.
client
.
get
(
test_url
+
'?preview=verified'
)
self
.
assertNotIn
(
self
.
course
.
display_name
,
response
.
content
)
self
.
assertIn
(
'course_title_0'
,
response
.
content
)
self
.
assertIn
(
'Signatory_Title 0'
,
response
.
content
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_render_html_view_invalid_certificate_configuration
(
self
):
test_url
=
get_certificate_url
(
user_id
=
self
.
user
.
id
,
...
...
lms/djangoapps/certificates/views/webview.py
View file @
a9643c67
...
...
@@ -14,6 +14,7 @@ from django.utils.translation import ugettext as _
from
django.core.urlresolvers
import
reverse
from
courseware.courses
import
course_image_url
from
courseware.access
import
has_access
from
edxmako.shortcuts
import
render_to_response
from
edxmako.template
import
Template
from
eventtracking
import
tracker
...
...
@@ -287,6 +288,7 @@ def render_html_view(request, user_id, course_id):
context
=
{}
context
[
'platform_name'
]
=
microsite
.
get_value
(
"platform_name"
,
settings
.
PLATFORM_NAME
)
context
[
'course_id'
]
=
course_id
preview_mode
=
request
.
GET
.
get
(
'preview'
,
None
)
# Update the view context with the default ConfigurationModel settings
configuration
=
CertificateHtmlViewConfiguration
.
get_config
()
...
...
@@ -334,17 +336,27 @@ def render_html_view(request, user_id, course_id):
raise
CourseDoesNotExist
# Attempt to load the user's generated certificate data
user_certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
user
,
course_id
=
course_key
)
if
preview_mode
:
user_certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
user
,
course_id
=
course_key
,
mode
=
preview_mode
)
else
:
user_certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
user
,
course_id
=
course_key
)
# If there's no generated certificate data for this user, we need to see if we're in 'preview' mode...
# If we are, we'll need to create a mock version of the user_certificate container for previewing
except
GeneratedCertificate
.
DoesNotExist
:
if
request
.
GET
.
get
(
'preview'
,
None
):
if
preview_mode
and
(
has_access
(
request
.
user
,
'instructor'
,
course
)
or
has_access
(
request
.
user
,
'staff'
,
course
)
):
user_certificate
=
GeneratedCertificate
(
mode
=
request
.
GET
.
get
(
'preview'
)
,
mode
=
preview_mode
,
verify_uuid
=
unicode
(
uuid4
()
.
hex
),
modified_date
=
datetime
.
now
()
.
date
()
)
...
...
@@ -383,7 +395,7 @@ def render_html_view(request, user_id, course_id):
# Get the active certificate configuration for this course
# If we do not have an active certificate, we'll need to send the user to the "Invalid" screen
# Passing in the 'preview' parameter, if specified, will return a configuration, if defined
active_configuration
=
get_active_web_certificate
(
course
,
request
.
GET
.
get
(
'preview'
)
)
active_configuration
=
get_active_web_certificate
(
course
,
preview_mode
)
if
active_configuration
is
None
:
return
render_to_response
(
invalid_template_path
,
context
)
else
:
...
...
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