Skip to content

Commit

Permalink
Merge pull request #192 from edx/awais786/fixing-tests
Browse files Browse the repository at this point in the history
BOM-1043
  • Loading branch information
Ayub-Khan authored Dec 5, 2019
2 parents f06abac + b9a18f6 commit b0a78b0
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 39 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ matrix:
- python: 2.7
env: TOXENV=django22

allow_failures:
- python: 3.5
env: TOXENV=django20
- python: 3.5
env: TOXENV=django21
- python: 3.5
env: TOXENV=django22


install:
- pip install -r requirements/travis.txt
Expand Down
11 changes: 2 additions & 9 deletions edxval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
TranscriptFormat,
get_video_image_storage,
get_video_transcript_storage,
validate_generated_images,
video_image_path,
video_transcript_path,
)
Expand Down Expand Up @@ -291,15 +292,7 @@ def validate_list(self, value):
Raises:
ValidationError
"""
if len(value) > self.max_items:
raise ValidationError(
u'list must not contain more than {max_items} items.'.format(max_items=self.max_items)
)

if all(isinstance(item, six.string_types) for item in value) is False:
raise ValidationError(u'list must only contain strings.')

return value
return validate_generated_images(value, self.max_items)

def deconstruct(self):
name, path, args, kwargs = super(ListField, self).deconstruct()
Expand Down
27 changes: 27 additions & 0 deletions edxval/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import json

import six
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.files.storage import get_storage_class
from fs.path import combine
from pysrt import SubRipFile
Expand Down Expand Up @@ -220,3 +222,28 @@ def get_transcript_format(transcript_content):
if srt_subs:
return TranscriptFormat.SRT
return TranscriptFormat.SJSON


def validate_generated_images(value, max_items):
"""
Validate data before saving to database.
Arguments:
value(list): list to be validated
max_items (int): maximum number of items in a list
Returns:
list if validation is successful
Raises:
ValidationError
"""
if len(value) > max_items:
raise ValidationError(
u'list must not contain more than {max_items} items.'.format(max_items=max_items)
)

if all(isinstance(item, six.string_types) for item in value) is False:
raise ValidationError(u'list must only contain strings.')

return value
21 changes: 19 additions & 2 deletions edxval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
from rest_framework.views import APIView

from edxval.api import create_or_update_video_transcript
from edxval.models import CourseVideo, EncodedVideo, Profile, TranscriptProviderType, Video, VideoImage, VideoTranscript
from edxval.models import (
LIST_MAX_ITEMS,
CourseVideo,
EncodedVideo,
Profile,
TranscriptProviderType,
Video,
VideoImage,
VideoTranscript,
)
from edxval.serializers import VideoSerializer
from edxval.utils import TranscriptFormat
from edxval.utils import TranscriptFormat, validate_generated_images

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -236,6 +245,14 @@ def post(self, request):
edx_video_id = request.data['edx_video_id']
generated_images = request.data['generated_images']

try:
validate_generated_images(generated_images, LIST_MAX_ITEMS)
except Exception as e: # pylint: disable=broad-except
return Response(
status=status.HTTP_400_BAD_REQUEST,
data={'message': str(e)}
)

try:
course_video = CourseVideo.objects.select_related('video_image').get(
course_id=six.text_type(course_id), video__edx_video_id=edx_video_id
Expand Down
16 changes: 8 additions & 8 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ backports.os==0.1.1 # via fs
bleach==3.1.0 # via readme-renderer
boto==2.49.0
caniusepython3==7.2.0
certifi==2019.9.11 # via requests, urllib3
certifi==2019.11.28 # via requests, urllib3
cffi==1.13.2 # via cryptography
chardet==3.0.4 # via pysrt, requests
click-log==0.3.2 # via edx-lint
click==7.0 # via click-log, edx-lint, pip-tools
configparser==4.0.2 # via importlib-metadata, pydocstyle, pylint
contextlib2==0.6.0.post1 # via importlib-metadata
coverage==4.5.4
coveralls==1.8.2
coveralls==1.9.2
cryptography==2.8 # via pyopenssl, urllib3
ddt==1.2.1
ddt==1.2.2
diff-cover==2.4.1
distlib==0.3.0 # via caniusepython3
django-model-utils==3.2.0
Expand All @@ -47,7 +47,7 @@ funcsigs==1.0.2 # via mock
future==0.18.2 # via backports.os, pyjwkest
futures==3.3.0 ; python_version == "2.7" # via caniusepython3, isort
idna==2.8 # via requests, urllib3
importlib-metadata==0.23 # via inflect, pluggy, tox
importlib-metadata==1.1.0 # via inflect, pluggy, tox
inflect==3.0.2 # via jinja2-pluralize
ipaddress==1.0.23 # via cryptography, urllib3
isort==4.3.21
Expand All @@ -74,7 +74,7 @@ pycodestyle==2.5.0
pycparser==2.19 # via cffi
pycryptodomex==3.9.4 # via pyjwkest
pydocstyle==3.0.0
pygments==2.5.1 # via diff-cover, readme-renderer
pygments==2.5.2 # via diff-cover, readme-renderer
pyjwkest==1.3.2 # via edx-drf-extensions
pyjwt==1.7.1 # via djangorestframework-jwt
pylint-celery==0.3 # via edx-lint
Expand All @@ -100,8 +100,8 @@ snowballstemmer==2.0.0 # via pydocstyle
stevedore==1.31.0 # via edx-opaque-keys
toml==0.10.0 # via tox
tox-battery==0.5.1
tox==3.14.1
tqdm==4.39.0 # via twine
tox==3.14.2
tqdm==4.40.0 # via twine
twine==1.15.0
typing==3.7.4.1 # via fs
urllib3[secure]==1.25.7 # via coveralls, requests
Expand All @@ -111,4 +111,4 @@ wrapt==1.11.2 # via astroid
zipp==0.6.0 # via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools==42.0.1 # via caniusepython3, fs, twine
# setuptools
10 changes: 5 additions & 5 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ backports.os==0.1.1 # via fs
bleach==3.1.0 # via readme-renderer
boto==2.49.0
caniusepython3==7.2.0
certifi==2019.9.11 # via requests
certifi==2019.11.28 # via requests
chardet==3.0.4 # via pysrt, requests
click-log==0.3.2 # via edx-lint
click==7.0 # via click-log, edx-lint
configparser==4.0.2 # via pydocstyle, pylint
coverage==4.5.4
ddt==1.2.1
ddt==1.2.2
distlib==0.3.0 # via caniusepython3
django-model-utils==3.2.0
django-nose==1.4.6
Expand Down Expand Up @@ -55,7 +55,7 @@ psutil==1.2.1 # via edx-django-utils, edx-drf-extensions
pycodestyle==2.5.0
pycryptodomex==3.9.4 # via pyjwkest
pydocstyle==3.0.0
pygments==2.5.1 # via readme-renderer
pygments==2.5.2 # via readme-renderer
pyjwkest==1.3.2 # via edx-drf-extensions
pyjwt==1.7.1 # via djangorestframework-jwt
pylint-celery==0.3 # via edx-lint
Expand All @@ -77,12 +77,12 @@ singledispatch==3.4.0.3 # via astroid, pylint
six==1.13.0 # via astroid, bleach, edx-drf-extensions, edx-lint, edx-opaque-keys, fs, mock, packaging, pydocstyle, pyjwkest, pylint, python-dateutil, readme-renderer, singledispatch, stevedore
snowballstemmer==2.0.0 # via pydocstyle
stevedore==1.31.0 # via edx-opaque-keys
tqdm==4.39.0 # via twine
tqdm==4.40.0 # via twine
twine==1.15.0
typing==3.7.4.1 # via fs
urllib3==1.25.7 # via requests
webencodings==0.5.1 # via bleach
wrapt==1.11.2 # via astroid

# The following packages are considered to be unsafe in a requirements file:
# setuptools==42.0.1 # via caniusepython3, fs, twine
# setuptools
6 changes: 3 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
appdirs==1.4.3 # via fs
backports.os==0.1.1 # via fs
boto==2.49.0
certifi==2019.9.11 # via requests
certifi==2019.11.28 # via requests
chardet==3.0.4 # via pysrt, requests
coverage==4.5.4
ddt==1.2.1
ddt==1.2.2
django-model-utils==3.2.0
django-nose==1.4.6
django-storages==1.8
Expand Down Expand Up @@ -51,4 +51,4 @@ typing==3.7.4.1 # via fs
urllib3==1.25.7 # via requests

# The following packages are considered to be unsafe in a requirements file:
# setuptools==42.0.1 # via fs
# setuptools
8 changes: 4 additions & 4 deletions requirements/travis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#
# make upgrade
#
certifi==2019.9.11 # via requests, urllib3
certifi==2019.11.28 # via requests, urllib3
cffi==1.13.2 # via cryptography
chardet==3.0.4 # via requests
configparser==4.0.2 # via importlib-metadata
contextlib2==0.6.0.post1 # via importlib-metadata
coverage==4.5.4 # via coveralls
coveralls==1.8.2
coveralls==1.9.2
cryptography==2.8 # via pyopenssl, urllib3
docopt==0.6.2 # via coveralls
enum34==1.1.6 # via cryptography
filelock==3.0.12 # via tox
idna==2.8 # via requests, urllib3
importlib-metadata==0.23 # via pluggy, tox
importlib-metadata==1.1.0 # via pluggy, tox
ipaddress==1.0.23 # via cryptography, urllib3
more-itertools==5.0.0 # via zipp
packaging==19.2 # via tox
Expand All @@ -31,7 +31,7 @@ scandir==1.10.0 # via pathlib2
six==1.13.0 # via cryptography, packaging, pathlib2, pyopenssl, tox
toml==0.10.0 # via tox
tox-battery==0.5.1
tox==3.14.1
tox==3.14.2
urllib3[secure]==1.25.7 # via coveralls, requests
virtualenv==16.7.8 # via tox
zipp==0.6.0 # via importlib-metadata
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ commands =
python manage.py test {posargs}

[testenv:quality]
basepython = python3.5
whitelist_externals =
make
deps =
Expand Down

0 comments on commit b0a78b0

Please sign in to comment.