Skip to content

Commit

Permalink
Merge pull request #77 from edx/ammar/auto-generated-images-fixes
Browse files Browse the repository at this point in the history
auto generated images fixes
  • Loading branch information
muhammad-ammar authored Jul 4, 2017
2 parents 7084212 + dccf16f commit a03f599
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
36 changes: 25 additions & 11 deletions edxval/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,10 @@ def setUp(self):
Used for manually creating profile objects which EncodedVideos require.
"""
self.course_id = 'test_course_id'
self.video = Video.objects.create(**constants.VIDEO_DICT_FISH)
self.course_video = CourseVideo.objects.create(video=self.video, course_id=self.course_id)
self.video1 = Video.objects.create(**constants.VIDEO_DICT_FISH)
self.video2 = Video.objects.create(**constants.VIDEO_DICT_DIFFERENT_ID_FISH)
self.course_video1 = CourseVideo.objects.create(video=self.video1, course_id=self.course_id)
self.course_video2 = CourseVideo.objects.create(video=self.video2, course_id=self.course_id)
super(VideoImagesViewTest, self).setUp()

def test_update_auto_generated_images(self):
Expand All @@ -820,39 +822,51 @@ def test_update_auto_generated_images(self):
url = reverse('update-video-images')
response = self.client.post(
url,
{'course_id': self.course_id, 'generated_images': generated_images},
{
'course_id': self.course_id,
'edx_video_id': self.video1.edx_video_id,
'generated_images': generated_images
},
format='json'
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.course_video.video_image.image.name, generated_images[0])
self.assertEqual(self.course_video.video_image.generated_images, generated_images)
self.assertEqual(self.course_video1.video_image.image.name, generated_images[0])
self.assertEqual(self.course_video1.video_image.generated_images, generated_images)

# verify that if we post again then `VideoImage.image.name` should not be updated
# but `VideoImage.generated_images` should be updated with new names.
new_generated_images = ['a.png', 'b.png', 'c.png']
response = self.client.post(
url,
{'course_id': self.course_id, 'generated_images': new_generated_images},
{
'course_id': self.course_id,
'edx_video_id': self.video1.edx_video_id,
'generated_images': new_generated_images
},
format='json'
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.course_video.video_image.image.name, generated_images[0])
course_video = CourseVideo.objects.get(video=self.video, course_id=self.course_id)
self.assertEqual(self.course_video1.video_image.image.name, generated_images[0])
course_video = CourseVideo.objects.get(video=self.video1, course_id=self.course_id)
self.assertEqual(course_video.video_image.generated_images, new_generated_images)

@data(
{
'post_data': {},
'message': u'course_id and generated_images must be specified to update a video image.'
'message': u'course_id and edx_video_id and generated_images must be specified to update a video image.'
},
{
'post_data': {'course_id': 'does_not_exit_course', 'generated_images': []},
'post_data': {'course_id': 'does_not_exit_course', 'edx_video_id': 'super-soaker', 'generated_images': []},
'message': u'CourseVideo not found for course_id: does_not_exit_course'
},
{
'post_data': {'course_id': 'test_course_id', 'generated_images': [1, 2, 3]},
'post_data': {'course_id': 'test_course_id', 'edx_video_id': 'does_not_exit_video', 'generated_images': []},
'message': u'CourseVideo not found for course_id: test_course_id'
},
{
'post_data': {'course_id': 'test_course_id', 'edx_video_id': 'super-soaker', 'generated_images': [1, 2, 3]},
'message': "[u'list must only contain strings.']"
},
)
Expand Down
5 changes: 3 additions & 2 deletions edxval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def post(self, request):
"""
Update a course video image instance with auto generated image names.
"""
attrs = ('course_id', 'generated_images')
attrs = ('course_id', 'edx_video_id', 'generated_images')
missing = [attr for attr in attrs if attr not in request.data]
if missing:
return Response(
Expand All @@ -126,11 +126,12 @@ def post(self, request):
)

course_id = request.data['course_id']
edx_video_id = request.data['edx_video_id']
generated_images = request.data['generated_images']

try:
course_video = CourseVideo.objects.select_related('video_image').get(
course_id=unicode(course_id)
course_id=unicode(course_id), video__edx_video_id=edx_video_id
)
except CourseVideo.DoesNotExist:
return Response(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_requirements(*requirements_paths):

setup(
name='edxval',
version='0.0.15',
version='0.0.16',
author='edX',
url='http://github.com/edx/edx-val',
description='edx-val',
Expand Down

0 comments on commit a03f599

Please sign in to comment.