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
42c2cc4d
Commit
42c2cc4d
authored
Nov 19, 2015
by
Matt Drayer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10618 from edx/ziafazal/SOL-1386
SOL-1386: refactored cert web view code
parents
943fbdd4
c5912ea3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
38 deletions
+132
-38
lms/djangoapps/certificates/tests/factories.py
+14
-1
lms/djangoapps/certificates/tests/test_views.py
+16
-26
lms/djangoapps/certificates/tests/test_webview_views.py
+102
-11
lms/djangoapps/certificates/views/webview.py
+0
-0
No files found.
lms/djangoapps/certificates/tests/factories.py
View file @
42c2cc4d
...
...
@@ -38,6 +38,11 @@ class BadgeAssertionFactory(DjangoModelFactory):
model
=
BadgeAssertion
mode
=
'honor'
data
=
{
'image'
:
'http://www.example.com/image.png'
,
'json'
:
{
'id'
:
'http://www.example.com/assertion.json'
},
'issuer'
:
'http://www.example.com/issuer.json'
,
}
class
BadgeImageConfigurationFactory
(
DjangoModelFactory
):
...
...
@@ -75,7 +80,8 @@ class CertificateHtmlViewConfigurationFactory(DjangoModelFactory):
},
"honor": {
"certificate_type": "Honor Code",
"certificate_title": "Certificate of Achievement"
"certificate_title": "Certificate of Achievement",
"logo_url": "http://www.edx.org/honor_logo.png"
},
"verified": {
"certificate_type": "Verified",
...
...
@@ -84,6 +90,13 @@ class CertificateHtmlViewConfigurationFactory(DjangoModelFactory):
"xseries": {
"certificate_title": "XSeries Certificate of Achievement",
"certificate_type": "XSeries"
},
"microsites": {
"testmicrosite": {
"company_about_url": "http://www.testmicrosite.org/about-us",
"company_privacy_url": "http://www.testmicrosite.org/edx-privacy-policy",
"company_tos_url": "http://www.testmicrosite.org/edx-terms-service"
}
}
}"""
...
...
lms/djangoapps/certificates/tests/test_views.py
View file @
42c2cc4d
...
...
@@ -187,16 +187,6 @@ class UpdateExampleCertificateViewTest(TestCase):
self
.
assertEqual
(
content
[
'return_code'
],
0
)
def
fakemicrosite
(
name
,
default
=
None
):
"""
This is a test mocking function to return a microsite configuration
"""
if
name
==
'microsite_config_key'
:
return
'test_microsite'
else
:
return
default
@attr
(
'shard_1'
)
class
MicrositeCertificatesViewsTests
(
ModuleStoreTestCase
):
"""
...
...
@@ -270,7 +260,6 @@ class MicrositeCertificatesViewsTests(ModuleStoreTestCase):
self
.
course
.
save
()
self
.
store
.
update_item
(
self
.
course
,
self
.
user
.
id
)
@patch
(
"microsite_configuration.microsite.get_value"
,
fakemicrosite
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_html_view_for_microsite
(
self
):
test_configuration_string
=
"""{
...
...
@@ -285,18 +274,20 @@ class MicrositeCertificatesViewsTests(ModuleStoreTestCase):
"logo_src": "/static/certificates/images/logo-edx.svg",
"logo_url": "http://www.edx.org"
},
"test_microsite": {
"accomplishment_class_append": "accomplishment-certificate",
"platform_name": "platform_microsite",
"company_about_url": "http://www.microsite.org/about-us",
"company_privacy_url": "http://www.microsite.org/edx-privacy-policy",
"company_tos_url": "http://www.microsite.org/microsite-terms-service",
"company_verified_certificate_url": "http://www.microsite.org/verified-certificate",
"document_stylesheet_url_application": "/static/certificates/sass/main-ltr.css",
"logo_src": "/static/certificates/images/logo-microsite.svg",
"logo_url": "http://www.microsite.org",
"company_about_description": "This is special microsite aware company_about_description content",
"company_about_title": "Microsite title"
"microsites": {
"testmicrosite": {
"accomplishment_class_append": "accomplishment-certificate",
"platform_name": "platform_microsite",
"company_about_url": "http://www.microsite.org/about-us",
"company_privacy_url": "http://www.microsite.org/edx-privacy-policy",
"company_tos_url": "http://www.microsite.org/microsite-terms-service",
"company_verified_certificate_url": "http://www.microsite.org/verified-certificate",
"document_stylesheet_url_application": "/static/certificates/sass/main-ltr.css",
"logo_src": "/static/certificates/images/logo-microsite.svg",
"logo_url": "http://www.microsite.org",
"company_about_description": "This is special microsite aware company_about_description content",
"company_about_title": "Microsite title"
}
},
"honor": {
"certificate_type": "Honor Code"
...
...
@@ -310,13 +301,12 @@ class MicrositeCertificatesViewsTests(ModuleStoreTestCase):
course_id
=
unicode
(
self
.
course
.
id
)
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
response
=
self
.
client
.
get
(
test_url
)
response
=
self
.
client
.
get
(
test_url
,
HTTP_HOST
=
settings
.
MICROSITE_TEST_HOSTNAME
)
self
.
assertIn
(
'platform_microsite'
,
response
.
content
)
self
.
assertIn
(
'http://www.microsite.org'
,
response
.
content
)
self
.
assertIn
(
'This is special microsite aware company_about_description content'
,
response
.
content
)
self
.
assertIn
(
'Microsite title'
,
response
.
content
)
@patch
(
"microsite_configuration.microsite.get_value"
,
fakemicrosite
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_html_view_microsite_configuration_missing
(
self
):
test_configuration_string
=
"""{
...
...
@@ -343,7 +333,7 @@ class MicrositeCertificatesViewsTests(ModuleStoreTestCase):
course_id
=
unicode
(
self
.
course
.
id
)
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
response
=
self
.
client
.
get
(
test_url
)
response
=
self
.
client
.
get
(
test_url
,
HTTP_HOST
=
settings
.
MICROSITE_TEST_HOSTNAME
)
self
.
assertIn
(
'edX'
,
response
.
content
)
self
.
assertNotIn
(
'platform_microsite'
,
response
.
content
)
self
.
assertNotIn
(
'http://www.microsite.org'
,
response
.
content
)
...
...
lms/djangoapps/certificates/tests/test_webview_views.py
View file @
42c2cc4d
...
...
@@ -23,7 +23,6 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from
certificates.api
import
get_certificate_url
from
certificates.models
import
(
GeneratedCertificate
,
BadgeAssertion
,
CertificateStatuses
,
CertificateSocialNetworks
,
CertificateTemplate
,
...
...
@@ -33,6 +32,7 @@ from certificates.models import (
from
certificates.tests.factories
import
(
CertificateHtmlViewConfigurationFactory
,
LinkedInAddToProfileConfigurationFactory
,
BadgeAssertionFactory
,
)
from
util
import
organizations_helpers
as
organizations_api
from
django.test.client
import
RequestFactory
...
...
@@ -222,6 +222,104 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
self
.
assertIn
(
'logo_test1.png'
,
response
.
content
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
@patch.dict
(
"django.conf.settings.SOCIAL_SHARING_SETTINGS"
,
{
"CERTIFICATE_TWITTER"
:
True
,
"CERTIFICATE_FACEBOOK"
:
True
,
})
def
test_rendering_maximum_data
(
self
):
"""
Tests at least one data item from different context update methods to
make sure every context update method is invoked while rendering certificate template.
"""
long_org_name
=
'Long org name'
short_org_name
=
'short_org_name'
test_organization_data
=
{
'name'
:
long_org_name
,
'short_name'
:
short_org_name
,
'description'
:
'Test Organization Description'
,
'active'
:
True
,
'logo'
:
'/logo_test1.png'
}
test_org
=
organizations_api
.
add_organization
(
organization_data
=
test_organization_data
)
organizations_api
.
add_organization_course
(
organization_data
=
test_org
,
course_id
=
unicode
(
self
.
course
.
id
))
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
1
,
is_active
=
True
)
BadgeAssertionFactory
.
create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
)
self
.
course
.
cert_html_view_overrides
=
{
"logo_src"
:
"/static/certificates/images/course_override_logo.png"
}
self
.
course
.
save
()
self
.
store
.
update_item
(
self
.
course
,
self
.
user
.
id
)
test_url
=
get_certificate_url
(
user_id
=
self
.
user
.
id
,
course_id
=
unicode
(
self
.
course
.
id
)
)
response
=
self
.
client
.
get
(
test_url
,
HTTP_HOST
=
settings
.
MICROSITE_TEST_HOSTNAME
)
# Test an item from basic info
self
.
assertIn
(
'Terms of Service & Honor Code'
,
response
.
content
)
self
.
assertIn
(
'Certificate ID Number'
,
response
.
content
)
# Test an item from html cert configuration
self
.
assertIn
(
'<a class="logo" href="http://www.edx.org/honor_logo.png">'
,
response
.
content
)
# Test an item from course info
self
.
assertIn
(
'course_title_0'
,
response
.
content
)
# Test an item from user info
self
.
assertIn
(
"{fullname}, you've earned a certificate!"
.
format
(
fullname
=
self
.
user
.
profile
.
name
),
response
.
content
)
# Test an item from social info
self
.
assertIn
(
"Post on Facebook"
,
response
.
content
)
self
.
assertIn
(
"Share on Twitter"
,
response
.
content
)
# Test an item from certificate/org info
self
.
assertIn
(
"a course of study offered by {partner_short_name}, "
"an online learning initiative of {partner_long_name} "
"through {platform_name}."
.
format
(
partner_short_name
=
short_org_name
,
partner_long_name
=
long_org_name
,
platform_name
=
'Test Microsite'
),
response
.
content
)
# Test item from badge info
self
.
assertIn
(
"Add to Mozilla Backpack"
,
response
.
content
)
# Test item from microsite info
self
.
assertIn
(
"http://www.testmicrosite.org/about-us"
,
response
.
content
)
# Test course overrides
self
.
assertIn
(
"/static/certificates/images/course_override_logo.png"
,
response
.
content
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_render_html_view_valid_certificate
(
self
):
test_url
=
get_certificate_url
(
user_id
=
self
.
user
.
id
,
...
...
@@ -398,7 +496,7 @@ 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
#
accessing certificate web view in preview mode without
# staff or instructor access should show invalid certificate
self
.
assertIn
(
'Cannot Find Certificate'
,
response
.
content
)
...
...
@@ -495,16 +593,9 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
test_url
=
'{}?evidence_visit=1'
.
format
(
cert_url
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
recreate_tracker
()
assertion
=
BadgeAssertion
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
mode
=
'honor'
,
data
=
{
'image'
:
'http://www.example.com/image.png'
,
'json'
:
{
'id'
:
'http://www.example.com/assertion.json'
},
'issuer'
:
'http://www.example.com/issuer.json'
,
}
assertion
=
BadgeAssertionFactory
.
create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
)
assertion
.
save
()
response
=
self
.
client
.
get
(
test_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
assert_event_matches
(
...
...
lms/djangoapps/certificates/views/webview.py
View file @
42c2cc4d
This diff is collapsed.
Click to expand it.
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