Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions common/djangoapps/student/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
from openedx.core.djangolib.testing.utils import skip_unless_lms
from lms.djangoapps.certificates.api import get_certificate_url
from lms.djangoapps.certificates.data import CertificateStatuses
from lms.djangoapps.certificates.tests.factories import (
GeneratedCertificateFactory,
LinkedInAddToProfileConfigurationFactory
)
from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context

# pylint: disable=no-member

Expand Down Expand Up @@ -155,22 +153,29 @@ def test_unverified_certificate_message(self, enrollment_mode):
'do not have a current verified identity with {platform_name}'
.format(platform_name=settings.PLATFORM_NAME))

def test_post_to_linkedin_visibility(self):
@ddt.data(
(True, True),
(False, False),
)
@ddt.unpack
def test_post_to_linkedin_visibility(self, certificate_linkedin_enabled, linkedin_button_visible):
"""
Verifies that the post certificate to linked button
does not appear by default (when config is not set)
Then Verifies that the post certificate to linked button appears
as expected once a config is set
Verify the LinkedIn "Add to Profile" button visibility based on configuration.

Tests that:
1. When CERTIFICATE_LINKEDIN is False, the LinkedIn button is not visible
2. When CERTIFICATE_LINKEDIN is True, the LinkedIn button appears as expected
"""
self._create_certificate('honor')

# until we set up the configuration, the LinkedIn action
# button should not be visible
self._check_linkedin_visibility(False)

LinkedInAddToProfileConfigurationFactory()
# now we should see it
self._check_linkedin_visibility(True)
# LinkedIn sharing Status True/False
# When CERTIFICATE_LINKEDIN is set to False in site configuration,
# the LinkedIn "Add to Profile" button should not be visible to users
# but if set to True the LinkedIn "Add to Profile" button should be visible
# to users allowing them to share their certificate on LinkedIn
SITE_CONFIGURATION = {"SOCIAL_SHARING_SETTINGS": {"CERTIFICATE_LINKEDIN": certificate_linkedin_enabled}}
with with_site_configuration_context(configuration=SITE_CONFIGURATION):
self._check_linkedin_visibility(linkedin_button_visible)


@ddt.ddt
Expand Down
236 changes: 155 additions & 81 deletions common/djangoapps/student/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context

log = logging.getLogger(__name__)

BETA_TESTER_METHOD = 'common.djangoapps.student.helpers.access.is_beta_tester'
Expand Down Expand Up @@ -90,85 +92,132 @@ def test_cert_info(self):
download_url='http://s3.edx/cert'
)
enrollment = CourseEnrollmentFactory(user=user, course_id=course.id, mode=CourseMode.VERIFIED)
# LinkedIn sharing disabled as we are expecting 'linked_in_url': None in our test case
SITE_CONFIGURATION = {
'SOCIAL_SHARING_SETTINGS': {
'CERTIFICATE_LINKEDIN': False
}
}
with with_site_configuration_context(configuration=SITE_CONFIGURATION):
assert _cert_info(user, enrollment, None) == {
'status': 'processing',
'show_survey_button': False,
'can_unenroll': True,
}

assert _cert_info(user, enrollment, None) ==\
{'status': 'processing', 'show_survey_button': False, 'can_unenroll': True}

cert_status = {'status': 'unavailable', 'mode': 'honor', 'uuid': None}
assert _cert_info(user, enrollment, cert_status) == {'status': 'processing', 'show_survey_button': False,
'mode': 'honor', 'linked_in_url': None,
'can_unenroll': True}
cert_status = {'status': 'unavailable', 'mode': 'honor', 'uuid': None}
assert _cert_info(user, enrollment, cert_status) == {
'status': 'processing',
'show_survey_button': False,
'mode': 'honor',
'linked_in_url': None,
'can_unenroll': True,
}

cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor', 'uuid': None}
with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade:
patch_persisted_grade.return_value = Mock(percent=1.0)
assert _cert_info(user, enrollment, cert_status) == {'status': 'generating', 'show_survey_button': True,
'survey_url': survey_url, 'grade': '1.0',
'mode': 'honor', 'linked_in_url': None,
'can_unenroll': False}
cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor', 'uuid': None}
with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade:
patch_persisted_grade.return_value = Mock(percent=1.0)
assert _cert_info(user, enrollment, cert_status) == {
'status': 'generating',
'show_survey_button': True,
'survey_url': survey_url,
'grade': '1.0',
'mode': 'honor',
'linked_in_url': None,
'can_unenroll': False,
}

cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor', 'uuid': None}
assert _cert_info(user, enrollment, cert_status) == {
'status': 'generating',
'show_survey_button': True,
'survey_url': survey_url,
'grade': '0.67',
'mode': 'honor',
'linked_in_url': None,
'can_unenroll': False,
}

cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor', 'uuid': None}
assert _cert_info(user, enrollment, cert_status) == {'status': 'generating', 'show_survey_button': True,
'survey_url': survey_url, 'grade': '0.67', 'mode': 'honor',
'linked_in_url': None, 'can_unenroll': False}
cert_status = {
'status': 'downloadable',
'grade': '0.67',
'download_url': cert.download_url,
'mode': 'honor',
'uuid': 'fakeuuidbutitsfine',
}
assert _cert_info(user, enrollment, cert_status) == {
'status': 'downloadable',
'download_url': cert.download_url,
'show_survey_button': True,
'survey_url': survey_url,
'grade': '0.67',
'mode': 'honor',
'linked_in_url': None,
'can_unenroll': False,
}

cert_status = {
'status': 'downloadable',
'grade': '0.67',
'download_url': cert.download_url,
'mode': 'honor',
'uuid': 'fakeuuidbutitsfine',
}
assert _cert_info(user, enrollment, cert_status) == {'status': 'downloadable',
'download_url': cert.download_url,
'show_survey_button': True, 'survey_url': survey_url,
'grade': '0.67', 'mode': 'honor', 'linked_in_url': None,
'can_unenroll': False}
cert_status = {
'status': 'notpassing',
'grade': '0.67',
'download_url': cert.download_url,
'mode': 'honor',
'uuid': 'fakeuuidbutitsfine',
}
assert _cert_info(user, enrollment, cert_status) == {
'status': 'notpassing',
'show_survey_button': True,
'survey_url': survey_url,
'grade': '0.67',
'mode': 'honor',
'linked_in_url': None,
'can_unenroll': True,
}

cert_status = {
'status': 'notpassing', 'grade': '0.67',
'download_url': cert.download_url,
'mode': 'honor',
'uuid': 'fakeuuidbutitsfine',
}
assert _cert_info(user, enrollment, cert_status) == {'status': 'notpassing', 'show_survey_button': True,
'survey_url': survey_url, 'grade': '0.67', 'mode': 'honor',
'linked_in_url': None, 'can_unenroll': True}

# Test a course that doesn't have a survey specified
course2 = CourseOverviewFactory.create(
end_of_course_survey_url=None,
certificates_display_behavior='end',
)
enrollment2 = CourseEnrollmentFactory(user=user, course_id=course2.id, mode=CourseMode.VERIFIED)
# Test a course that doesn't have a survey specified
course2 = CourseOverviewFactory.create(
end_of_course_survey_url=None,
certificates_display_behavior='end',
)
enrollment2 = CourseEnrollmentFactory(user=user, course_id=course2.id, mode=CourseMode.VERIFIED)

cert_status = {
'status': 'notpassing', 'grade': '0.67',
'download_url': cert.download_url, 'mode': 'honor', 'uuid': 'fakeuuidbutitsfine'
}
assert _cert_info(user, enrollment2, cert_status) == {'status': 'notpassing', 'show_survey_button': False,
'grade': '0.67', 'mode': 'honor', 'linked_in_url': None,
'can_unenroll': True}
cert_status = {
'status': 'notpassing', 'grade': '0.67',
'download_url': cert.download_url, 'mode': 'honor', 'uuid': 'fakeuuidbutitsfine'
}
assert _cert_info(user, enrollment2, cert_status) == {
'status': 'notpassing',
'show_survey_button': False,
'grade': '0.67',
'mode': 'honor',
'linked_in_url': None,
'can_unenroll': True
}

course3 = CourseOverviewFactory.create(
end_of_course_survey_url=None,
certificates_display_behavior='early_no_info',
)
enrollment3 = CourseEnrollmentFactory(user=user, course_id=course3.id, mode=CourseMode.VERIFIED)
# test when the display is unavailable or notpassing, we get the correct results out
course2.certificates_display_behavior = CertificatesDisplayBehaviors.EARLY_NO_INFO
cert_status = {'status': 'unavailable', 'mode': 'honor', 'uuid': None}
assert _cert_info(user, enrollment3, cert_status) == {'status': 'processing', 'show_survey_button': False,
'can_unenroll': True}
course3 = CourseOverviewFactory.create(
end_of_course_survey_url=None,
certificates_display_behavior='early_no_info',
)
enrollment3 = CourseEnrollmentFactory(user=user, course_id=course3.id, mode=CourseMode.VERIFIED)
# test when the display is unavailable or notpassing, we get the correct results out
course2.certificates_display_behavior = CertificatesDisplayBehaviors.EARLY_NO_INFO
cert_status = {'status': 'unavailable', 'mode': 'honor', 'uuid': None}
assert _cert_info(user, enrollment3, cert_status) == {
'status': 'processing',
'show_survey_button': False,
'can_unenroll': True
}

cert_status = {
'status': 'notpassing', 'grade': '0.67',
'download_url': cert.download_url,
'mode': 'honor',
'uuid': 'fakeuuidbutitsfine'
}
assert _cert_info(user, enrollment3, cert_status) == {'status': 'processing', 'show_survey_button': False,
'can_unenroll': True}
cert_status = {
'status': 'notpassing', 'grade': '0.67',
'download_url': cert.download_url,
'mode': 'honor',
'uuid': 'fakeuuidbutitsfine'
}
assert _cert_info(user, enrollment3, cert_status) == {
'status': 'processing',
'show_survey_button': False,
'can_unenroll': True
}

def test_cert_info_beta_tester(self):
user = UserFactory.create()
Expand All @@ -192,15 +241,22 @@ def test_cert_info_beta_tester(self):
'uuid': 'blah',
}
with patch(BETA_TESTER_METHOD, return_value=False):
assert _cert_info(user, enrollment, cert_status) == {
'status': status,
'download_url': cert.download_url,
'show_survey_button': False,
'grade': grade,
'mode': mode,
'linked_in_url': None,
'can_unenroll': False
# LinkedIn sharing disabled as we are expecting 'linked_in_url': None in our test case
SITE_CONFIGURATION = {
'SOCIAL_SHARING_SETTINGS': {
'CERTIFICATE_LINKEDIN': False
}
}
with with_site_configuration_context(configuration=SITE_CONFIGURATION):
assert _cert_info(user, enrollment, cert_status) == {
'status': status,
'download_url': cert.download_url,
'show_survey_button': False,
'grade': grade,
'mode': mode,
'linked_in_url': None,
'can_unenroll': False
}

with patch(BETA_TESTER_METHOD, return_value=True):
assert _cert_info(user, enrollment, cert_status) == {
Expand Down Expand Up @@ -397,7 +453,16 @@ def test_linked_in_add_to_profile_btn_not_appearing_without_config(self):
grade='67',
download_url=download_url
)
response = self.client.get(reverse('dashboard'))
# LinkedIn sharing disabled
# When CERTIFICATE_LINKEDIN is set to False in site configuration,
# the LinkedIn "Add to Profile" button should not be visible to users
SITE_CONFIGURATION = {
'SOCIAL_SHARING_SETTINGS': {
'CERTIFICATE_LINKEDIN': False
}
}
with with_site_configuration_context(configuration=SITE_CONFIGURATION):
response = self.client.get(reverse('dashboard'))

assert response.status_code == 200
self.assertNotContains(response, 'Add Certificate to LinkedIn')
Expand Down Expand Up @@ -435,7 +500,16 @@ def test_linked_in_add_to_profile_btn_with_certificate(self):
grade='67',
download_url='https://www.edx.org'
)
response = self.client.get(reverse('dashboard'))
# LinkedIn sharing disabled
# When CERTIFICATE_LINKEDIN is set to False in site configuration,
# the LinkedIn "Add to Profile" button should not be visible to users
SITE_CONFIGURATION = {
'SOCIAL_SHARING_SETTINGS': {
'CERTIFICATE_LINKEDIN': True
}
}
with with_site_configuration_context(configuration=SITE_CONFIGURATION):
response = self.client.get(reverse('dashboard'))

assert response.status_code == 200
self.assertContains(response, 'Add Certificate to LinkedIn')
Expand Down
Loading