Skip to content

Commit

Permalink
feat(AU-2283): Correct pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodra committed Nov 19, 2024
1 parent 758b74d commit feb77e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 18 additions & 3 deletions edxval/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,18 @@ class TranscriptBulkDeleteSerializer(serializers.Serializer):
"""
Serializer for TranscriptBulkDelete
"""
def validate(self, data):
from edxval.api import get_available_transcript_languages # Local import to avoid circular import issues
def __init__(self, *args, **kwargs):
self.get_available_transcript_languages = kwargs.pop('get_available_transcript_languages')
super().__init__(*args, **kwargs)

def validate(self, data): # pylint: disable=unused-argument
missing_transcripts = []
for video_id, language_codes in self.initial_data.items():
if not isinstance(language_codes, list):
raise serializers.ValidationError(
f'Value for video "{video_id}" needs to be a list of language codes.'
)
available_transcript_languages = get_available_transcript_languages(video_id=video_id)
available_transcript_languages = self.get_available_transcript_languages(video_id=video_id)
for language_code in language_codes:
if language_code not in available_transcript_languages:
missing_transcripts.append(f'Language "{language_code}" is not available for video "{video_id}".')
Expand All @@ -280,3 +283,15 @@ def validate(self, data):
raise serializers.ValidationError('\n'.join(missing_transcripts))

return self.initial_data

def create(self, validated_data):
"""
Create and return a new `TranscriptBulkDelete` instance, given the validated data.
"""
return validated_data

Check warning on line 291 in edxval/serializers.py

View check run for this annotation

Codecov / codecov/patch

edxval/serializers.py#L291

Added line #L291 was not covered by tests

def update(self, instance, validated_data):
"""
Update and return an existing `TranscriptBulkDelete` instance, given the validated data.
"""
# Not needed for this serializer
6 changes: 5 additions & 1 deletion edxval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ def post(self, request):
- A 400 if any of the validation fails
- A 200 if all transcripts delete jobs are triggered successfully
"""
serializer = TranscriptBulkDeleteSerializer(data=request.data)
serializer = TranscriptBulkDeleteSerializer(
data=request.data,
# Dependencty injection to avoid cylcic import
get_available_transcript_languages=get_available_transcript_languages
)
if not serializer.is_valid():
return Response(
status=status.HTTP_400_BAD_REQUEST,
Expand Down

0 comments on commit feb77e8

Please sign in to comment.