|
12 | 12 | from unittest.mock import Mock, patch |
13 | 13 |
|
14 | 14 | import dateutil.parser |
| 15 | +from common.djangoapps.student.tests.factories import UserFactory |
15 | 16 | import ddt |
16 | 17 | import pytz |
17 | 18 | from django.test import TestCase |
|
37 | 38 | ENABLE_DEVSTACK_VIDEO_UPLOADS, |
38 | 39 | ) |
39 | 40 | from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel |
| 41 | +from xmodule.modulestore.django import modulestore |
| 42 | +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase |
40 | 43 | from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order |
41 | 44 |
|
42 | 45 | from ..videos import ( |
@@ -1662,3 +1665,82 @@ def test_storage_bucket(self): |
1662 | 1665 |
|
1663 | 1666 | self.assertIn("https://vem_test_bucket.s3.amazonaws.com:443/test_root/", upload_url) |
1664 | 1667 | self.assertIn(edx_video_id, upload_url) |
| 1668 | + |
| 1669 | + |
| 1670 | +class CourseYoutubeEdxVideoIds(ModuleStoreTestCase): |
| 1671 | + """ |
| 1672 | + This test checks youtube videos in a course |
| 1673 | + """ |
| 1674 | + VIEW_NAME = 'youtube_edx_video_ids' |
| 1675 | + |
| 1676 | + def setUp(self): |
| 1677 | + super().setUp() |
| 1678 | + self.course = CourseFactory.create() |
| 1679 | + self.course_with_no_youtube_videos = CourseFactory.create() |
| 1680 | + self.store = modulestore() |
| 1681 | + self.user = UserFactory() |
| 1682 | + self.client.login(username=self.user.username, password='Password1234') |
| 1683 | + |
| 1684 | + def get_url_for_course_key(self, course_key, kwargs=None): |
| 1685 | + """Return video handler URL for the given course""" |
| 1686 | + return reverse_course_url(self.VIEW_NAME, course_key, kwargs) # lint-amnesty, pylint: disable=no-member |
| 1687 | + |
| 1688 | + def test_course_with_youtube_videos(self): |
| 1689 | + course_key = self.course.id |
| 1690 | + |
| 1691 | + with self.store.bulk_operations(course_key): |
| 1692 | + chapter_loc = self.store.create_child( |
| 1693 | + self.user.id, self.course.location, 'chapter', 'test_chapter' |
| 1694 | + ).location |
| 1695 | + seq_loc = self.store.create_child( |
| 1696 | + self.user.id, chapter_loc, 'sequential', 'test_seq' |
| 1697 | + ).location |
| 1698 | + vert_loc = self.store.create_child(self.user.id, seq_loc, 'vertical', 'test_vert').location |
| 1699 | + self.store.create_child( |
| 1700 | + self.user.id, |
| 1701 | + vert_loc, |
| 1702 | + 'problem', |
| 1703 | + 'test_problem', |
| 1704 | + fields={"data": "<problem>Test</problem>"} |
| 1705 | + ) |
| 1706 | + self.store.create_child( |
| 1707 | + self.user.id, vert_loc, 'video', fields={ |
| 1708 | + "youtube_is_available": False, |
| 1709 | + "name": "sample_video", |
| 1710 | + "edx_video_id": "youtube_193_84709099", |
| 1711 | + } |
| 1712 | + ) |
| 1713 | + |
| 1714 | + response = self.client.get(self.get_url_for_course_key(course_key)) |
| 1715 | + self.assertEqual(response.status_code, 200) |
| 1716 | + |
| 1717 | + edx_video_ids = json.loads(response.content.decode('utf-8'))['edx_video_ids'] |
| 1718 | + self.assertEqual(len(edx_video_ids), 1) |
| 1719 | + |
| 1720 | + def test_course_with_no_youtube_videos(self): |
| 1721 | + course_key = self.course_with_no_youtube_videos.id |
| 1722 | + |
| 1723 | + with self.store.bulk_operations(course_key): |
| 1724 | + chapter_loc = self.store.create_child( |
| 1725 | + self.user.id, self.course_with_no_youtube_videos.location, 'chapter', 'test_chapter' |
| 1726 | + ).location |
| 1727 | + seq_loc = self.store.create_child( |
| 1728 | + self.user.id, chapter_loc, 'sequential', 'test_seq' |
| 1729 | + ).location |
| 1730 | + vert_loc = self.store.create_child(self.user.id, seq_loc, 'vertical', 'test_vert').location |
| 1731 | + self.store.create_child( |
| 1732 | + self.user.id, vert_loc, 'problem', 'test_problem', fields={"data": "<problem>Test</problem>"} |
| 1733 | + ) |
| 1734 | + self.store.create_child( |
| 1735 | + self.user.id, vert_loc, 'video', fields={ |
| 1736 | + "youtube_id_1_0": None, |
| 1737 | + "name": "sample_video", |
| 1738 | + "edx_video_id": "no_youtube_193_84709099", |
| 1739 | + } |
| 1740 | + ) |
| 1741 | + |
| 1742 | + response = self.client.get(self.get_url_for_course_key(course_key)) |
| 1743 | + |
| 1744 | + edx_video_ids = json.loads(response.content.decode('utf-8'))['edx_video_ids'] |
| 1745 | + self.assertEqual(response.status_code, 200) |
| 1746 | + self.assertEqual(len(edx_video_ids), 0) |
0 commit comments