Enable sharing icons for future courses

This commit is contained in:
Qubad786
2017-04-26 20:51:08 +05:00
parent 401eac8fa8
commit 4b73bac9b2
3 changed files with 133 additions and 53 deletions

View File

@@ -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)