Skip to content

Commit

Permalink
Merge branch 'master' into jenkins/zshkoor/setup-py-updated-12ba586
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar95 authored Dec 10, 2024
2 parents 3ad1b83 + 189ec0a commit 47a9852
Show file tree
Hide file tree
Showing 26 changed files with 774 additions and 500 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-reserved-keywords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
check-reserved-keywords:
name: Check Reserved Keywords
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Checkout code
Expand All @@ -15,7 +15,7 @@ jobs:
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11

- name: Install pip
run: pip install -r requirements/pip.txt
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
python-version: ['3.8']
toxenv: [django32, django42, quality]
os: [ubuntu-latest]
python-version: ['3.11']
toxenv: [django42, quality]

steps:
- uses: actions/checkout@v2
Expand All @@ -36,16 +36,17 @@ jobs:
run: tox

- name: Run Coverage
if: matrix.python-version == '3.8' && matrix.toxenv=='django42'
uses: codecov/codecov-action@v2
if: matrix.python-version == '3.11' && matrix.toxenv=='django42'
uses: codecov/codecov-action@v4
with:
flags: unittests
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}


provider-verification:
name: Pact Provider Verification
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs: run_tests

steps:
Expand All @@ -55,14 +56,14 @@ jobs:
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11

- name: Install pip
run: pip install -r requirements/pip.txt

- name: Install Dependencies
run: |
pip install "Django<4.0"
pip install "Django>=4.2,<4.3"
pip install -r requirements/ci.txt
pip install -r requirements/test.txt
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ on:
jobs:

push:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11

- name: Install pip
run: pip install -r requirements/pip.txt
Expand All @@ -27,7 +27,7 @@ jobs:
run: python setup.py sdist bdist_wheel

- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/upgrade-python-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
call-upgrade-python-requirements-workflow:
with:
branch: ${{ github.event.inputs.branch }}
team_reviewers: "Incident Management"
email_address: [email protected]
team_reviewers: '2u-phoenix'
email_address: '[email protected]'
send_success_notification: false
secrets:
requirements_bot_github_token: ${{ secrets.REQUIREMENTS_BOT_GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify_changed_contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
jobs:
changed-contract-verification:
name: Pact Provider Verification for a changed contract
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Checkout code
Expand All @@ -24,7 +24,7 @@ jobs:
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11

- name: Install pip
run: pip install -r requirements/pip.txt
Expand Down
2 changes: 1 addition & 1 deletion edxval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
init
"""

__version__ = '2.4.2'
__version__ = '2.6.1'
68 changes: 65 additions & 3 deletions edxval/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,64 @@ def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc
)


def get_transcript_details_for_course(course_id):
"""
Get all the transcripts for a course and return details.
Args:
course_id (String)
Returns:
(dict): Returns all the edx_video_id's and related transcript details for a course
{
'edx_video_id': {
'lang_code': {
'provider': 'What the provider is',
'file_format': 'file format',
'url': 'location of the file',
'name': 'name of the file',
'size': size of the file
}
}
"""
course_transcripts_data = {}

course_videos = CourseVideo.objects.filter(course_id=course_id).select_related('video')
for course_video in course_videos:

edx_video_id = course_video.video.edx_video_id
transcript_data = {}

video_transcripts = VideoTranscript.objects.filter(video=course_video.video)
for video_transcript in video_transcripts:
transcript_data[video_transcript.language_code] = {
'provider': video_transcript.provider,
'file_format': video_transcript.file_format,
'url': video_transcript.transcript.url,
'name': video_transcript.transcript.name,
'size': video_transcript.transcript.size,
}

course_transcripts_data[edx_video_id] = transcript_data

return course_transcripts_data


def get_video_ids_for_course(course_id):
"""
Gets video_ids for a course.
Args:
course_id (String)
Returns:
(list): Returns all the edx_video_id's for a course
"""
course_videos = CourseVideo.objects.filter(course_id=course_id).select_related('video')
video_ids = [cv.video.edx_video_id for cv in course_videos]
return video_ids


def remove_video_for_course(course_id, edx_video_id):
"""
Soft deletes video for particular course.
Expand Down Expand Up @@ -1018,7 +1076,7 @@ def create_transcripts_xml(video_id, video_el, resource_fs, static_dir):
continue

SubElement(
transcripts_el,
transcripts_el, # pylint: disable=possibly-used-before-assignment
'transcript',
{
'language_code': language_code,
Expand All @@ -1030,7 +1088,9 @@ def create_transcripts_xml(video_id, video_el, resource_fs, static_dir):
return dict(xml=video_el, transcripts=transcript_files_map)


def import_from_xml(xml, edx_video_id, resource_fs, static_dir, external_transcripts=None, course_id=None):
def import_from_xml(
xml, edx_video_id, resource_fs, static_dir, external_transcripts=None, course_id=None
): # pylint: disable=too-many-positional-arguments
"""
Imports data from a video_asset element about the given video_id.
If the edx_video_id already exists, then no changes are made. If an unknown
Expand Down Expand Up @@ -1147,7 +1207,9 @@ def import_from_xml(xml, edx_video_id, resource_fs, static_dir, external_transcr
return edx_video_id


def import_transcript_from_fs(edx_video_id, language_code, file_name, provider, resource_fs, static_dir):
def import_transcript_from_fs(
edx_video_id, language_code, file_name, provider, resource_fs, static_dir
): # pylint: disable=too-many-positional-arguments
"""
Imports transcript file from file system and creates transcript record in DS.
Expand Down
4 changes: 3 additions & 1 deletion edxval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ def get_or_none(cls, video_id, language_code):
return transcript

@classmethod
def create(cls, video, language_code, file_format, content, provider):
def create(
cls, video, language_code, file_format, content, provider
): # pylint: disable=too-many-positional-arguments
"""
Create a Video Transcript.
Expand Down
3 changes: 1 addition & 2 deletions edxval/pacts/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ class AuthenticationMiddleware(MiddlewareMixin):
"""

def __init__(self, get_response):
super().__init__()
super().__init__(get_response)
self.auth_user = User.objects.get_or_create(username='edx', is_staff=True)[0]
self.auth_user.user_permissions.set(Permission.objects.filter(content_type__app_label='edxval'))
self.get_response = get_response

def process_view(self, request, view_func, view_args, view_kwargs): # pylint: disable=unused-argument
"""
Expand Down
34 changes: 34 additions & 0 deletions edxval/tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@
status="test",
)

VIDEO_DICT_SIMPSONS = dict(
client_video_id="TheSimpsons",
duration=100.00,
edx_video_id="simpson-id",
status="test",
)

TRANSCRIPT_DATA = {
"overwatch": """
1
Expand Down Expand Up @@ -452,3 +459,30 @@
preferred_languages=['ar', 'en'],
video_source_language='en',
)

VIDEO_TRANSCRIPT_SIMPSON_ES = dict(
video_id='simpson-id',
language_code='es',
transcript='edxval/tests/data/The_Flash.srt',
provider=TranscriptProviderType.CIELO24,
file_format=TranscriptFormat.SRT,
file_data=TRANSCRIPT_DATA['flash']
)

VIDEO_TRANSCRIPT_SIMPSON_KO = dict(
video_id='simpson-id',
language_code='ko',
transcript='edxval/tests/data/The_Flash.srt',
provider=TranscriptProviderType.CIELO24,
file_format=TranscriptFormat.SRT,
file_data=TRANSCRIPT_DATA['flash']
)

VIDEO_TRANSCRIPT_SIMPSON_RU = dict(
video_id='simpson-id',
language_code='ru',
transcript='edxval/tests/data/The_Flash.srt',
provider=TranscriptProviderType.CIELO24,
file_format=TranscriptFormat.SRT,
file_data=TRANSCRIPT_DATA['flash']
)
55 changes: 52 additions & 3 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,18 @@ def api_func(_expected_ids, sort_field, sort_direction):
return videos
self.check_sort_params_of_api(api_func)

def test_get_video_ids_for_course(self):

course_transcript = api.get_video_ids_for_course(self.course_id)

self.assertEqual(len(course_transcript), 1)

def test_get_video_ids_for_course_no_course_videos(self):

course_transcript = api.get_video_ids_for_course('this-is-not-a-course-id')

self.assertEqual(len(course_transcript), 0)


@ddt
class GetYouTubeProfileVideosTest(TestCase):
Expand Down Expand Up @@ -2684,6 +2696,12 @@ def setUp(self):
self.v2_transcript1 = video_and_transcripts['transcripts']['de']
self.v2_transcript2 = video_and_transcripts['transcripts']['zh']

# Add the videos to courses
self.course_id1 = 'test-course-1'
self.course_id2 = 'test-course-2'
CourseVideo.objects.create(video=self.video1, course_id=self.course_id1)
CourseVideo.objects.create(video=self.video2, course_id=self.course_id2)

self.temp_dir = mkdtemp()
self.addCleanup(shutil.rmtree, self.temp_dir)

Expand Down Expand Up @@ -2822,7 +2840,9 @@ def test_get_video_transcript_url(self):
},
)
@unpack
def test_create_or_update_video_transcript(self, file_data, file_name, file_format, language_code, provider):
def test_create_or_update_video_transcript(
self, file_data, file_name, file_format, language_code, provider
): # pylint: disable=too-many-positional-arguments
"""
Verify that `create_or_update_video_transcript` api function updates existing transcript as expected.
"""
Expand Down Expand Up @@ -2879,7 +2899,9 @@ def test_create_or_update_video_transcript(self, file_data, file_name, file_form
},
)
@unpack
def test_create_or_update_video_exceptions(self, video_id, file_format, provider, exception, exception_message):
def test_create_or_update_video_exceptions(
self, video_id, file_format, provider, exception, exception_message
): # pylint: disable=too-many-positional-arguments
"""
Verify that `create_or_update_video_transcript` api function raise exceptions on invalid values.
"""
Expand Down Expand Up @@ -2997,7 +3019,9 @@ def test_create_video_transcript(self):
}
)
@unpack
def test_create_video_transcript_exceptions(self, video_id, language_code, file_format, provider, exception_msg):
def test_create_video_transcript_exceptions(
self, video_id, language_code, file_format, provider, exception_msg
): # pylint: disable=too-many-positional-arguments
"""
Verify that `create_video_transcript` api function raise exceptions on invalid values.
"""
Expand Down Expand Up @@ -3133,6 +3157,31 @@ def test_no_create_transcript_file(self, video_id, language_code):
# Verify no file is created.
self.assertEqual(file_system.listdir(constants.EXPORT_IMPORT_STATIC_DIR), [])

def test_get_transcript_details_for_course(self):
"""
Verify that `get_transcript_details_for_course` api function works as expected.
"""

course_transcript = api.get_transcript_details_for_course(self.course_id1)

self.assertEqual(course_transcript['super-soaker']['en']['provider'], TranscriptProviderType.THREE_PLAY_MEDIA)
self.assertEqual(course_transcript['super-soaker']['en']['file_format'], utils.TranscriptFormat.SRT)
self.assertIn('url', course_transcript['super-soaker']['en'])
self.assertIn('name', course_transcript['super-soaker']['en'])
self.assertIn('size', course_transcript['super-soaker']['en'])

self.assertEqual(course_transcript['super-soaker']['fr']['provider'], TranscriptProviderType.CIELO24)
self.assertEqual(course_transcript['super-soaker']['en']['file_format'], utils.TranscriptFormat.SRT)
self.assertIn('url', course_transcript['super-soaker']['fr'])
self.assertIn('name', course_transcript['super-soaker']['fr'])
self.assertIn('size', course_transcript['super-soaker']['fr'])

def test_get_transcript_details_for_course_no_course_videos(self):

course_transcript = api.get_transcript_details_for_course('this-is-not-a-course-id')

self.assertEqual(len(course_transcript), 0)


@ddt
class TranscriptPreferencesTest(TestCase):
Expand Down
Loading

0 comments on commit 47a9852

Please sign in to comment.