diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 49d6dd1bf3..54fea87b6b 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -1,7 +1,10 @@ """ Test the student dashboard view. """ +import datetime +import itertools import json +import pytz import unittest import ddt @@ -13,6 +16,7 @@ from edx_oauth2_provider.constants import AUTHORIZED_CLIENTS_SESSION_KEY from edx_oauth2_provider.tests.factories import ClientFactory, TrustedClientFactory from mock import patch from pyquery import PyQuery as pq +from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory @@ -214,19 +218,53 @@ class LogoutTests(TestCase): self.assertDictContainsSubset(expected, response.context_data) # pylint: disable=no-member +@ddt.ddt @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') -class StudentDashboardTests(TestCase): - """ Tests for the student dashboard. """ +class StudentDashboardTests(SharedModuleStoreTestCase): + """ + Tests for the student dashboard. + """ + + ENABLED_SIGNALS = ['course_published'] + TOMORROW = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1) + MOCK_SETTINGS = { + 'FEATURES': { + 'DISABLE_START_DATES': False, + 'ENABLE_MKTG_SITE': True + }, + 'SOCIAL_SHARING_SETTINGS': { + 'CUSTOM_COURSE_URLS': True, + 'DASHBOARD_FACEBOOK': True, + 'DASHBOARD_TWITTER': True, + }, + } def setUp(self): - """ Create a course and user, then log in. """ + """ + Create a course and user, then log in. + """ super(StudentDashboardTests, self).setUp() self.user = UserFactory() self.client.login(username=self.user.username, password=PASSWORD) self.path = reverse('dashboard') + def set_course_sharing_urls(self, set_marketing, set_social_sharing): + """ + Set course sharing urls (i.e. social_sharing_url, marketing_url) + """ + course_overview = self.course_enrollment.course_overview + if set_marketing: + course_overview.marketing_url = 'http://www.testurl.com/marketing/url/' + + if set_social_sharing: + course_overview.social_sharing_url = 'http://www.testurl.com/social/url/' + + course_overview.save() + def test_user_info_cookie(self): - """ Verify visiting the learner dashboard sets the user info cookie. """ + """ + Verify visiting the learner dashboard sets the user info cookie. + """ self.assertNotIn(settings.EDXMKTG_USER_INFO_COOKIE_NAME, self.client.cookies) request = RequestFactory().get(self.path) @@ -243,3 +281,27 @@ class StudentDashboardTests(TestCase): UserProfile.objects.get(user=self.user).delete() response = self.client.get(self.path) self.assertRedirects(response, reverse('account_settings')) + + @patch.multiple('django.conf.settings', **MOCK_SETTINGS) + @ddt.data( + *itertools.product( + [TOMORROW], + [True, False], + [True, False], + [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split], + ) + ) + @ddt.unpack + def test_sharing_icons_for_future_course(self, start_date, set_marketing, set_social_sharing, modulestore_type): + """ + Verify that the course sharing icons show up if course is starting in future and + any of marketing or social sharing urls are set. + """ + self.course = CourseFactory.create(start=start_date, emit_signals=True, default_store=modulestore_type) + self.course_enrollment = CourseEnrollmentFactory(course_id=self.course.id, user=self.user) + self.set_course_sharing_urls(set_marketing, set_social_sharing) + + # Assert course sharing icons + response = self.client.get(reverse('dashboard')) + self.assertEqual('Share on Twitter' in response.content, set_marketing or set_social_sharing) + self.assertEqual('Share on Facebook' in response.content, set_marketing or set_social_sharing) diff --git a/lms/templates/dashboard/_dashboard_course_listing.html b/lms/templates/dashboard/_dashboard_course_listing.html index b127019b10..419d7aff45 100644 --- a/lms/templates/dashboard/_dashboard_course_listing.html +++ b/lms/templates/dashboard/_dashboard_course_listing.html @@ -147,57 +147,61 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_ ${_('View Course')} ${course_overview.display_name_with_default} % endif % endif + % endif - % if share_settings: - <% - share_url = get_link_for_about_page(course_overview) - encoded_utm_parameters = get_encoded_course_sharing_utm_params() - share_window_name = 'shareWindow' - share_window_config = 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480' - %> - % if share_settings.get('DASHBOARD_FACEBOOK', False): - <% - facebook_share_url = "{url}?{utm_params}".format(url=share_url, utm_params=encoded_utm_parameters['facebook']) - share_text = _("I'm taking {course_name} online with edX.org. Check it out!").format(course_name=course_overview.display_name_with_default) - query_params = urllib.urlencode((('u', facebook_share_url), ('quote', share_text.encode('utf-8')),)) - facebook_url = 'https://www.facebook.com/sharer/sharer.php?{query}'.format(query=query_params) - %> - - ${_('Facebook')} - - + % if show_courseware_link or course_overview.has_social_sharing_url() or course_overview.has_marketing_url(): + + % if share_settings: + <% + share_url = get_link_for_about_page(course_overview) + encoded_utm_parameters = get_encoded_course_sharing_utm_params() + share_window_name = 'shareWindow' + share_window_config = 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480' + %> + % if share_settings.get('DASHBOARD_FACEBOOK', False): + <% + facebook_share_url = "{url}?{utm_params}".format(url=share_url.encode('utf-8'), utm_params=encoded_utm_parameters['facebook']) + share_text = _("I'm taking {course_name} online with edX.org. Check it out!").format(course_name=course_overview.display_name_with_default) + query_params = urllib.urlencode((('u', facebook_share_url), ('quote', share_text.encode('utf-8')),)) + facebook_url = 'https://www.facebook.com/sharer/sharer.php?{query}'.format(query=query_params) + %> + + ${_('Facebook')} + + + % endif + % if share_settings.get('DASHBOARD_TWITTER', False): + <% + twitter_share_url = "{url}?{utm_params}".format(url=share_url.encode('utf-8'), utm_params=encoded_utm_parameters['twitter']) + default_share_text = _("I'm taking {course_name} online with @edxonline. Check it out!").format(course_name=course_overview.display_name_with_default) + share_text = urllib.quote_plus(share_settings.get('DASHBOARD_TWITTER_TEXT', default_share_text.encode('utf-8'))) + twitter_url = 'https://twitter.com/intent/tweet?text=' + share_text + '%20' + urllib.quote_plus(twitter_share_url) + %> + + ${_('Twitter')} + + + % endif % endif - % if share_settings.get('DASHBOARD_TWITTER', False): - <% - twitter_share_url = "{url}?{utm_params}".format(url=share_url, utm_params=encoded_utm_parameters['twitter']) - default_share_text = _("I'm taking {course_name} online with @edxonline. Check it out!").format(course_name=course_overview.display_name_with_default) - share_text = urllib.quote_plus(share_settings.get('DASHBOARD_TWITTER_TEXT', default_share_text.encode('utf-8'))) - twitter_url = 'https://twitter.com/intent/tweet?text=' + share_text + '%20' + urllib.quote_plus(twitter_share_url) - %> - - ${_('Twitter')} - - - % endif - % endif + % endif