diff --git a/lms/djangoapps/courseware/tests/test_sharing_sites.py b/lms/djangoapps/courseware/tests/test_sharing_sites.py new file mode 100644 index 0000000000..d2fb0b4554 --- /dev/null +++ b/lms/djangoapps/courseware/tests/test_sharing_sites.py @@ -0,0 +1,82 @@ +""" +tests for the sharing sites +""" + +import ddt +from unittest import TestCase +from unittest.mock import patch +from urllib.parse import parse_qsl +from xmodule.video_block.sharing_sites import ( + sharing_url, + sharing_sites_info_for_video, + SharingSiteConfig, +) + +TEST_SHARING_SITE_NAME = "test_site_name" +TEST_SHARING_SITE_ICON = "test-icon-name" +TEST_URL_PARAM_NAME = "this-url" +TEST_BASE_SHARE_URL = "www.mysite.org/videos" + +TEST_SHARING_SITE_CONFIG = SharingSiteConfig( + name=TEST_SHARING_SITE_NAME, + fa_icon_name=TEST_SHARING_SITE_ICON, + url_param_name=TEST_URL_PARAM_NAME, + base_share_url=TEST_BASE_SHARE_URL, +) + +TEST_SHARING_SITE_CONFIG_WITH_ADDITIONAL_PARAMS = SharingSiteConfig( + name=TEST_SHARING_SITE_NAME, + fa_icon_name=TEST_SHARING_SITE_ICON, + url_param_name=TEST_URL_PARAM_NAME, + base_share_url=TEST_BASE_SHARE_URL, + additional_site_params={'state': 'NY', 'color': 'red'} +) + +TEST_PUBLIC_URL = "http://www.openedx.org/videos/some_video_or_other" + + +@ddt.ddt +class TestSharingSites(TestCase): + """ + Tests for the sharing sites + """ + @ddt.data( + TEST_SHARING_SITE_CONFIG, + TEST_SHARING_SITE_CONFIG_WITH_ADDITIONAL_PARAMS + ) + def test_sharing_url(self, config): + """ + Test that the sharing url is built correctly + """ + base_url, params = sharing_url(TEST_PUBLIC_URL, config).split("?") + self.assertEqual(base_url, config.base_share_url) + decoded_params = dict(parse_qsl(params)) + self.assertEqual(decoded_params[config.url_param_name], TEST_PUBLIC_URL) + if getattr(config, 'additional_site_params', False): + # additional_site_params will be the subset of decoded_params + for key, expected_value in config.additional_site_params.items(): + assert decoded_params[key] == expected_value + self.assertNotIn('additional_site_params', decoded_params) + + def test_sharing_sites_info_for_video(self): + """ + Test that the sharing sites info is built correctly + """ + sharing_site_configs = [ + TEST_SHARING_SITE_CONFIG, + TEST_SHARING_SITE_CONFIG_WITH_ADDITIONAL_PARAMS, + ] + with patch('xmodule.video_block.sharing_sites.ALL_SHARING_SITES', new=sharing_site_configs): + sharing_sites_info = sharing_sites_info_for_video(TEST_PUBLIC_URL) + for expected_config, actual_info in zip(sharing_site_configs, sharing_sites_info): + self.assertDictEqual( + actual_info, + { + 'name': expected_config.name, + 'fa_icon_name': expected_config.fa_icon_name, + 'sharing_url': sharing_url( + TEST_PUBLIC_URL, + expected_config + ) + } + ) diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 0e9008a099..719ca3f8c2 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -96,6 +96,8 @@ class TestVideoYouTube(TestVideo): # lint-amnesty, pylint: disable=missing-clas 'branding_info': None, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -179,6 +181,8 @@ class TestVideoNonYouTube(TestVideo): # pylint: disable=test-inherits-tests 'branding_info': None, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -454,6 +458,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): 'branding_info': None, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -503,6 +509,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): track_url if data['expected_track_url'] == 'a_sub_file.srt.sjson' else data['expected_track_url'] ), 'id': self.block.location.html_id(), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'metadata': json.dumps(metadata) }) @@ -574,6 +582,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): 'branding_info': None, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -612,6 +622,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): }) expected_context.update({ 'id': self.block.location.html_id(), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'download_video_link': data['result'].get('download_video_link'), 'metadata': json.dumps(expected_context['metadata']) }) @@ -701,6 +713,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): 'branding_info': None, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -754,6 +768,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): }) expected_context.update({ 'id': self.block.location.html_id(), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'download_video_link': data['result']['download_video_link'], 'metadata': json.dumps(expected_context['metadata']) }) @@ -874,6 +890,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): 'branding_info': None, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -914,6 +932,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): }) expected_context.update({ 'id': self.block.location.html_id(), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'download_video_link': data['result']['download_video_link'], 'metadata': json.dumps(expected_context['metadata']) }) @@ -987,6 +1007,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): }, 'license': None, 'bumper_metadata': 'null', + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -1030,6 +1052,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): }) expected_context.update({ 'id': self.block.location.html_id(), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'download_video_link': data['result'].get('download_video_link'), 'metadata': json.dumps(expected_context['metadata']) }) @@ -1134,6 +1158,8 @@ class TestGetHtmlMethod(BaseTestVideoXBlock): }) expected_context.update({ 'id': self.block.location.html_id(), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'download_video_link': data['result'].get('download_video_link'), 'metadata': json.dumps(expected_context['metadata']) }) @@ -2339,6 +2365,8 @@ class TestVideoWithBumper(TestVideo): # pylint: disable=test-inherits-tests self.get_handler_url('publish_completion', ''), 'is_bumper', 1 ), })), + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': 'A Name', @@ -2414,6 +2442,8 @@ class TestAutoAdvanceVideo(TestVideo): # lint-amnesty, pylint: disable=test-inh context = { 'autoadvance_enabled': autoadvanceenabled_flag, 'branding_info': None, + 'block_id': str(self.block.location), + 'course_id': str(self.block.location.course_key), 'license': None, 'cdn_eval': False, 'cdn_exp_group': None, diff --git a/lms/templates/video.html b/lms/templates/video.html index f4f4ec9a55..5684976d4a 100644 --- a/lms/templates/video.html +++ b/lms/templates/video.html @@ -17,6 +17,8 @@ from openedx.core.djangolib.js_utils import ( data-bumper-metadata='${bumper_metadata}' data-autoadvance-enabled="${autoadvance_enabled}" data-poster='${poster}' + data-block-id='${block_id}' + data-course-id='${course_id}' tabindex="-1" >
@@ -46,44 +48,29 @@ from openedx.core.djangolib.js_utils import ( - % if (download_video_link or track or handout or branding_info or public_video_url) and not hide_downloads: + % if (download_video_link or track or handout or branding_info or public_sharing_enabled) and not hide_downloads: