Skip to content

Commit

Permalink
done (oppia#5522)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishucr7 authored and vojtechjelinek committed Aug 14, 2018
1 parent 81d9528 commit f4c686e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 8 additions & 3 deletions core/domain/html_validation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,17 @@ def get_filename_with_dimensions(old_filename, exp_id):
file_system_class = (
fs_domain.ExplorationFileSystem if feconf.DEV_MODE
else fs_domain.GcsFileSystem)
fs = fs_domain.AbstractFileSystem(file_system_class(exp_id))
fs = fs_domain.AbstractFileSystem(file_system_class(
'exploration/%s' % exp_id))
filepath = (
old_filename if feconf.DEV_MODE
else ('image/%s' % old_filename))
content = fs.get(filepath)
height, width = gae_image_services.get_image_dimensions(content)
try:
content = fs.get(filepath)
height, width = gae_image_services.get_image_dimensions(content)
except IOError:
height = 120
width = 120
new_filename = regenerate_image_filename_using_dimensions(
old_filename, height, width)
return new_filename
16 changes: 15 additions & 1 deletion core/domain/html_validation_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,20 @@ def test_add_dimensions_to_image_tags(self):
'expected_output': (
u'<p>Hey this is a test case with no images.</p>'
)
}, {
'html_content': (
'<p><oppia-noninteractive-image filepath-with-value="&amp;quot;'
'does_not_exist.png&amp;quot;"></oppia-noninteractive-image>'
'Hello this is test case to check that default dimensions '
'(120, 120) are added in case the image does not exist.</p>'
),
'expected_output': (
u'<p><oppia-noninteractive-image filepath-with-value="&amp;'
'quot;does_not_exist_height_120_width_120.png&amp;quot;">'
'</oppia-noninteractive-image>Hello this is test case'
' to check that default dimensions (120, 120) '
'are added in case the image does not exist.</p>'
)
}]

EXP_ID = 'eid'
Expand All @@ -1024,7 +1038,7 @@ def test_add_dimensions_to_image_tags(self):
with open(os.path.join(feconf.TESTS_DATA_DIR, 'img.png')) as f:
raw_image = f.read()
fs = fs_domain.AbstractFileSystem(
fs_domain.ExplorationFileSystem(EXP_ID))
fs_domain.ExplorationFileSystem('exploration/%s' % EXP_ID))
fs.commit(OWNER_ID, 'abc1.png', raw_image, mimetype='image/png')
fs.commit(OWNER_ID, 'abc2.png', raw_image, mimetype='image/png')
fs.commit(OWNER_ID, 'abc3.png', raw_image, mimetype='image/png')
Expand Down

0 comments on commit f4c686e

Please sign in to comment.