Make replace_static_urls leave alone urls that have '?raw' at the end

- needed for GWT'ed modules that rely on the filename to find dependencies
This commit is contained in:
Victor Shnayder
2013-02-11 17:07:15 -05:00
parent 754493597d
commit 2dcdeff4b6
2 changed files with 44 additions and 7 deletions

View File

@@ -1,5 +1,8 @@
from nose.tools import assert_equals
from static_replace import replace_static_urls, replace_course_urls
import re
from nose.tools import assert_equals, assert_true, assert_false
from static_replace import (replace_static_urls, replace_course_urls,
_url_replace_regex)
from mock import patch, Mock
from xmodule.modulestore import Location
from xmodule.modulestore.mongo import MongoModuleStore
@@ -75,3 +78,27 @@ def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings):
mock_storage.exists.return_value = False
assert_equals('"/static/data_dir/file.png"', replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY))
def test_raw_static_check():
path = '"/static/foo.png?raw"'
assert_equals(path, replace_static_urls(path, DATA_DIRECTORY))
def test_regex():
yes = ('"/static/foo.png"',
'"/static/foo.png"',
"'/static/foo.png'")
no = ('"/static/foo.png?raw"',
'"/static/foo', # no matching quote
)
regex = _url_replace_regex('/static/')
for s in yes:
print 'Should match: {0!r}'.format(s)
assert_true(re.match(regex, s))
for s in no:
print 'Should not match: {0!r}'.format(s)
assert_false(re.match(regex, s))