def test_html_view_site_configuration_missing(self): test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=2) response = self.client.get(test_url) self.assertContains(response, 'edX') self.assertNotContains(response, 'My Platform Site') self.assertNotContains( response, 'This should not survive being overwritten by static content', )
def test_html_view_for_site(self): test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=2) response = self.client.get(test_url) self.assertContains( response, 'awarded this My Platform Site Honor Code Certificate of Completion', ) self.assertContains( response, 'My Platform Site offers interactive online classes and MOOCs.') self.assertContains(response, 'About My Platform Site')
def test_certificate_render_custom_response(self): """ Test rendering an invalid template after catching RenderCustomResponse exception. Expected result: - CertificateRenderStarted is triggered and executes TestRenderCustomResponse. - The custom response is found in the certificate. """ test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=1, is_active=True) response = self.client.get(test_url) self.assertContains(response, "Here's the text of the web page.")
def _update_social_context(request, context, course, user, user_certificate, platform_name): # lint-amnesty, pylint: disable=unused-argument """ Updates context dictionary with info required for social sharing. """ share_settings = configuration_helpers.get_value( "SOCIAL_SHARING_SETTINGS", settings.SOCIAL_SHARING_SETTINGS) context['facebook_share_enabled'] = share_settings.get( 'CERTIFICATE_FACEBOOK', False) context['facebook_app_id'] = configuration_helpers.get_value( "FACEBOOK_APP_ID", settings.FACEBOOK_APP_ID) context['facebook_share_text'] = share_settings.get( 'CERTIFICATE_FACEBOOK_TEXT', _(u"I completed the {course_title} course on {platform_name}.").format( course_title=context['accomplishment_copy_course_name'], platform_name=platform_name)) context['twitter_share_enabled'] = share_settings.get( 'CERTIFICATE_TWITTER', False) context['twitter_share_text'] = share_settings.get( 'CERTIFICATE_TWITTER_TEXT', _(u"I completed a course at {platform_name}. Take a look at my certificate." ).format(platform_name=platform_name)) share_url = request.build_absolute_uri( get_certificate_url(course_id=course.id, uuid=user_certificate.verify_uuid)) context['share_url'] = share_url twitter_url = '' if context.get('twitter_share_enabled', False): twitter_url = 'https://twitter.com/intent/tweet?text={twitter_share_text}&url={share_url}'.format( twitter_share_text=smart_str(context['twitter_share_text']), share_url=six.moves.urllib.parse.quote_plus(smart_str(share_url))) context['twitter_url'] = twitter_url context['linked_in_url'] = None # If enabled, show the LinkedIn "add to profile" button # Clicking this button sends the user to LinkedIn where they # can add the certificate information to their profile. linkedin_config = LinkedInAddToProfileConfiguration.current() if linkedin_config.is_enabled(): context['linked_in_url'] = linkedin_config.add_to_profile_url( course.display_name, user_certificate.mode, smart_str(share_url), certificate=user_certificate)
def test_certificate_redirect(self): """ Test redirecting to a new page after catching RedirectToPage exception. Expected result: - CertificateRenderStarted is triggered and executes TestRedirectToPageStep. - The webview response is a redirection. """ test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=1, is_active=True) response = self.client.get(test_url) self.assertEqual(status.HTTP_302_FOUND, response.status_code) self.assertEqual("https://certificate.pdf", response.url)
def test_certificate_render_without_filter_config(self): """ Test whether the student certificate filter is triggered before the user's certificate rendering without affecting its execution flow. Expected result: - CertificateRenderStarted executes a noop (empty pipeline). - The webview response is HTTP_200_OK. """ test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=1, is_active=True) response = self.client.get(test_url) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertContains(response, "My Platform Site")
def test_certificate_render_invalid(self): """ Test rendering an invalid template after catching RenderAlternativeInvalidCertificate exception. Expected result: - CertificateRenderStarted is triggered and executes TestStopCertificateRenderStep. - The invalid certificate template is rendered. """ test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=1, is_active=True) response = self.client.get(test_url) self.assertContains(response, "Invalid Certificate") self.assertContains(response, "Cannot Find Certificate") self.assertContains( response, "We cannot find a certificate with this URL or ID number.")
def test_certificate_render_filter_executed(self): """ Test whether the student certificate render filter is triggered before the user's certificate rendering process. Expected result: - CertificateRenderStarted is triggered and executes TestCertificateRenderPipelineStep. - The certificate renders using the custom template. """ test_url = get_certificate_url(user_id=self.user.id, course_id=str(self.course.id), uuid=self.cert.verify_uuid) self._add_course_certificates(count=1, signatory_count=1, is_active=True) response = self.client.get(test_url) self.assertContains( response, '<img class="custom-logo" src="test-logo.png" />', )