Commit 4b73bac9 by Qubad786

Enable sharing icons for future courses

parent 401eac8f
""" """
Test the student dashboard view. Test the student dashboard view.
""" """
import datetime
import itertools
import json import json
import pytz
import unittest import unittest
import ddt import ddt
...@@ -13,6 +16,7 @@ from edx_oauth2_provider.constants import AUTHORIZED_CLIENTS_SESSION_KEY ...@@ -13,6 +16,7 @@ from edx_oauth2_provider.constants import AUTHORIZED_CLIENTS_SESSION_KEY
from edx_oauth2_provider.tests.factories import ClientFactory, TrustedClientFactory from edx_oauth2_provider.tests.factories import ClientFactory, TrustedClientFactory
from mock import patch from mock import patch
from pyquery import PyQuery as pq from pyquery import PyQuery as pq
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
...@@ -214,19 +218,53 @@ class LogoutTests(TestCase): ...@@ -214,19 +218,53 @@ class LogoutTests(TestCase):
self.assertDictContainsSubset(expected, response.context_data) # pylint: disable=no-member self.assertDictContainsSubset(expected, response.context_data) # pylint: disable=no-member
@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class StudentDashboardTests(TestCase): class StudentDashboardTests(SharedModuleStoreTestCase):
""" Tests for the student dashboard. """ """
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): def setUp(self):
""" Create a course and user, then log in. """ """
Create a course and user, then log in.
"""
super(StudentDashboardTests, self).setUp() super(StudentDashboardTests, self).setUp()
self.user = UserFactory() self.user = UserFactory()
self.client.login(username=self.user.username, password=PASSWORD) self.client.login(username=self.user.username, password=PASSWORD)
self.path = reverse('dashboard') 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): 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) self.assertNotIn(settings.EDXMKTG_USER_INFO_COOKIE_NAME, self.client.cookies)
request = RequestFactory().get(self.path) request = RequestFactory().get(self.path)
...@@ -243,3 +281,27 @@ class StudentDashboardTests(TestCase): ...@@ -243,3 +281,27 @@ class StudentDashboardTests(TestCase):
UserProfile.objects.get(user=self.user).delete() UserProfile.objects.get(user=self.user).delete()
response = self.client.get(self.path) response = self.client.get(self.path)
self.assertRedirects(response, reverse('account_settings')) 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_ ...@@ -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> <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 % endif
% endif
% if share_settings: % if show_courseware_link or course_overview.has_social_sharing_url() or course_overview.has_marketing_url():
<%
share_url = get_link_for_about_page(course_overview) % if share_settings:
encoded_utm_parameters = get_encoded_course_sharing_utm_params() <%
share_window_name = 'shareWindow' share_url = get_link_for_about_page(course_overview)
share_window_config = 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480' encoded_utm_parameters = get_encoded_course_sharing_utm_params()
%> share_window_name = 'shareWindow'
% if share_settings.get('DASHBOARD_FACEBOOK', False): share_window_config = 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480'
<% %>
facebook_share_url = "{url}?{utm_params}".format(url=share_url, utm_params=encoded_utm_parameters['facebook']) % if share_settings.get('DASHBOARD_FACEBOOK', False):
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_share_url = "{url}?{utm_params}".format(url=share_url.encode('utf-8'), utm_params=encoded_utm_parameters['facebook'])
facebook_url = 'https://www.facebook.com/sharer/sharer.php?{query}'.format(query=query_params) 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')),))
<a facebook_url = 'https://www.facebook.com/sharer/sharer.php?{query}'.format(query=query_params)
data-tooltip="${_('Share on Facebook')}" %>
class="action action-facebook" <a
aria-haspopup="true" data-tooltip="${_('Share on Facebook')}"
aria-expanded="false" class="action action-facebook"
href="${facebook_url}" aria-haspopup="true"
target="_blank" aria-expanded="false"
title="${_('Share on Facebook')}" href="${facebook_url}"
data-course-id="${course_overview.id}" target="_blank"
onclick="window.open('${facebook_url}', '${share_window_name}', '${share_window_config}'); return false;"> title="${_('Share on Facebook')}"
<span class="sr">${_('Facebook')}</span> data-course-id="${course_overview.id}"
<span class="fa fa-facebook" aria-hidden="true"></span> onclick="window.open('${facebook_url}', '${share_window_name}', '${share_window_config}'); return false;">
</a> <span class="sr">${_('Facebook')}</span>
% endif <span class="fa fa-facebook" aria-hidden="true"></span>
% if share_settings.get('DASHBOARD_TWITTER', False): </a>
<% % endif
twitter_share_url = "{url}?{utm_params}".format(url=share_url, utm_params=encoded_utm_parameters['twitter']) % if share_settings.get('DASHBOARD_TWITTER', False):
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_share_url = "{url}?{utm_params}".format(url=share_url.encode('utf-8'), utm_params=encoded_utm_parameters['twitter'])
twitter_url = 'https://twitter.com/intent/tweet?text=' + share_text + '%20' + urllib.quote_plus(twitter_share_url) 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')))
<a twitter_url = 'https://twitter.com/intent/tweet?text=' + share_text + '%20' + urllib.quote_plus(twitter_share_url)
data-tooltip="${_('Share on Twitter')}" %>
class="action action-twitter" <a
aria-haspopup="true" data-tooltip="${_('Share on Twitter')}"
aria-expanded="false" class="action action-twitter"
href="${twitter_url}" aria-haspopup="true"
target="_blank" aria-expanded="false"
title="${_('Share on Twitter')}" href="${twitter_url}"
data-course-id="${course_overview.id}" target="_blank"
onclick="window.open('${twitter_url}', '${share_window_name}', '${share_window_config}'); return false;"> title="${_('Share on Twitter')}"
<span class="sr">${_('Twitter')}</span> data-course-id="${course_overview.id}"
<span class="fa fa-twitter" aria-hidden="true"></span> onclick="window.open('${twitter_url}', '${share_window_name}', '${share_window_config}'); return false;">
</a> <span class="sr">${_('Twitter')}</span>
<span class="fa fa-twitter" aria-hidden="true"></span>
</a>
% endif
% endif % endif
% endif
% endif % endif
<div class="wrapper-action-more" data-course-key="${enrollment.course_id}"> <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}"> <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 ...@@ -5,6 +5,7 @@ import json
import logging import logging
from urlparse import urlparse, urlunparse from urlparse import urlparse, urlunparse
from django.conf import settings
from django.db import models, transaction from django.db import models, transaction
from django.db.models.fields import BooleanField, DateTimeField, DecimalField, TextField, FloatField, IntegerField from django.db.models.fields import BooleanField, DateTimeField, DecimalField, TextField, FloatField, IntegerField
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
...@@ -380,6 +381,19 @@ class CourseOverview(TimeStampedModel): ...@@ -380,6 +381,19 @@ class CourseOverview(TimeStampedModel):
""" """
return course_metadata_utils.has_course_ended(self.end) 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): def starts_within(self, days):
""" """
Returns True if the course starts with-in given number of days otherwise returns False. 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