Commit 4b73bac9 by Qubad786

Enable sharing icons for future courses

parent 401eac8f
"""
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)
......@@ -147,57 +147,61 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_
<a class="enter-course-blocked" data-course-key="${enrollment.course_id}">${_('View Course')}<span class="sr">&nbsp;${course_overview.display_name_with_default}</span></a>
% 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)
%>
<a
data-tooltip="${_('Share on Facebook')}"
class="action action-facebook"
aria-haspopup="true"
aria-expanded="false"
href="${facebook_url}"
target="_blank"
title="${_('Share on Facebook')}"
data-course-id="${course_overview.id}"
onclick="window.open('${facebook_url}', '${share_window_name}', '${share_window_config}'); return false;">
<span class="sr">${_('Facebook')}</span>
<span class="fa fa-facebook" aria-hidden="true"></span>
</a>
% 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)
%>
<a
data-tooltip="${_('Share on Twitter')}"
class="action action-twitter"
aria-haspopup="true"
aria-expanded="false"
href="${twitter_url}"
target="_blank"
title="${_('Share on Twitter')}"
data-course-id="${course_overview.id}"
onclick="window.open('${twitter_url}', '${share_window_name}', '${share_window_config}'); return false;">
<span class="sr">${_('Twitter')}</span>
<span class="fa fa-twitter" aria-hidden="true"></span>
</a>
% 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)
%>
<a
data-tooltip="${_('Share on Facebook')}"
class="action action-facebook"
aria-haspopup="true"
aria-expanded="false"
href="${facebook_url}"
target="_blank"
title="${_('Share on Facebook')}"
data-course-id="${course_overview.id}"
onclick="window.open('${facebook_url}', '${share_window_name}', '${share_window_config}'); return false;">
<span class="sr">${_('Facebook')}</span>
<span class="fa fa-facebook" aria-hidden="true"></span>
</a>
% 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)
%>
<a
data-tooltip="${_('Share on Twitter')}"
class="action action-twitter"
aria-haspopup="true"
aria-expanded="false"
href="${twitter_url}"
target="_blank"
title="${_('Share on Twitter')}"
data-course-id="${course_overview.id}"
onclick="window.open('${twitter_url}', '${share_window_name}', '${share_window_config}'); return false;">
<span class="sr">${_('Twitter')}</span>
<span class="fa fa-twitter" aria-hidden="true"></span>
</a>
% endif
% endif
% endif
% endif
<div class="wrapper-action-more" data-course-key="${enrollment.course_id}">
<button type="button" class="action action-more" id="actions-dropdown-link-${dashboard_index}" aria-haspopup="true" aria-expanded="false" aria-controls="actions-dropdown-${dashboard_index}" data-course-number="${course_overview.number}" data-course-name="${course_overview.display_name_with_default}" data-dashboard-index="${dashboard_index}">
......
......@@ -5,6 +5,7 @@ import json
import logging
from urlparse import urlparse, urlunparse
from django.conf import settings
from django.db import models, transaction
from django.db.models.fields import BooleanField, DateTimeField, DecimalField, TextField, FloatField, IntegerField
from django.db.utils import IntegrityError
......@@ -380,6 +381,19 @@ class CourseOverview(TimeStampedModel):
"""
return course_metadata_utils.has_course_ended(self.end)
def has_marketing_url(self):
"""
Returns whether the course has marketing url.
"""
return settings.FEATURES.get('ENABLE_MKTG_SITE') and bool(self.marketing_url)
def has_social_sharing_url(self):
"""
Returns whether the course has social sharing url.
"""
is_social_sharing_enabled = getattr(settings, 'SOCIAL_SHARING_SETTINGS', {}).get('CUSTOM_COURSE_URLS')
return is_social_sharing_enabled and bool(self.social_sharing_url)
def starts_within(self, days):
"""
Returns True if the course starts with-in given number of days otherwise returns False.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment