diff --git a/common/djangoapps/static_replace/__init__.py b/common/djangoapps/static_replace/__init__.py index 04a240debbb8e39816e4431ef284e3e7c08bf936..6ec87706cb51f3080867b5ae5b82e9d35b849352 100644 --- a/common/djangoapps/static_replace/__init__.py +++ b/common/djangoapps/static_replace/__init__.py @@ -3,12 +3,10 @@ import logging import re -import six from django.conf import settings from django.contrib.staticfiles import finders from django.contrib.staticfiles.storage import staticfiles_storage from opaque_keys.edx.locator import AssetLocator -from six import text_type from xmodule.contentstore.content import StaticContent @@ -39,7 +37,7 @@ def try_staticfiles_lookup(path): try: url = staticfiles_storage.url(path) except Exception as err: # lint-amnesty, pylint: disable=broad-except - log.warning("staticfiles_storage couldn't find path {0}: {1}".format( + log.warning("staticfiles_storage couldn't find path {}: {}".format( path, str(err))) # Just return the original path; don't kill everything. url = path @@ -85,7 +83,7 @@ def replace_course_urls(text, course_key): returns: text with the links replaced """ - course_id = text_type(course_key) + course_id = str(course_key) def replace_course_url(match): quote = match.group('quote') @@ -114,7 +112,7 @@ def process_static_urls(text, replacement_function, data_dir=None): # works for actual static assets and for magical course asset URLs.... full_url = prefix + rest - starts_with_static_url = full_url.startswith(six.text_type(settings.STATIC_URL)) + starts_with_static_url = full_url.startswith(str(settings.STATIC_URL)) starts_with_prefix = full_url.startswith(XBLOCK_STATIC_RESOURCE_PREFIX) contains_prefix = XBLOCK_STATIC_RESOURCE_PREFIX in full_url if starts_with_prefix or (starts_with_static_url and contains_prefix): @@ -123,7 +121,7 @@ def process_static_urls(text, replacement_function, data_dir=None): return replacement_function(original, prefix, quote, rest) return re.sub( - _url_replace_regex(u'(?:{static_url}|/static/)(?!{data_dir})'.format( + _url_replace_regex('(?:{static_url}|/static/)(?!{data_dir})'.format( static_url=settings.STATIC_URL, data_dir=data_dir )), @@ -192,7 +190,7 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_ try: exists_in_staticfiles_storage = staticfiles_storage.exists(rest) except Exception as err: # lint-amnesty, pylint: disable=broad-except - log.warning("staticfiles_storage couldn't find path {0}: {1}".format( + log.warning("staticfiles_storage couldn't find path {}: {}".format( rest, str(err))) if exists_in_staticfiles_storage: @@ -220,7 +218,7 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_ url = staticfiles_storage.url(course_path) # And if that fails, assume that it's course content, and add manually data directory except Exception as err: # lint-amnesty, pylint: disable=broad-except - log.warning("staticfiles_storage couldn't find path {0}: {1}".format( + log.warning("staticfiles_storage couldn't find path {}: {}".format( rest, str(err))) url = "".join([prefix, course_path]) diff --git a/common/djangoapps/static_replace/management/commands/clear_collectstatic_cache.py b/common/djangoapps/static_replace/management/commands/clear_collectstatic_cache.py index 7a1d5a2125cfd3af97a6c9ee505292380cade8c8..48655c671ab72ba204c4a08774f1972e04093261 100644 --- a/common/djangoapps/static_replace/management/commands/clear_collectstatic_cache.py +++ b/common/djangoapps/static_replace/management/commands/clear_collectstatic_cache.py @@ -3,8 +3,8 @@ Django management command to clear the 'staticfiles' Django cache """ -from django.core.management.base import BaseCommand from django.core.cache import caches +from django.core.management.base import BaseCommand class Command(BaseCommand): diff --git a/common/djangoapps/static_replace/migrations/0001_initial.py b/common/djangoapps/static_replace/migrations/0001_initial.py index 875813fd7a75bf73b57f6a6d0a50b0b8e8b09974..9cccfeaf36bf05d6d2921fcd135516adbc3ebbba 100644 --- a/common/djangoapps/static_replace/migrations/0001_initial.py +++ b/common/djangoapps/static_replace/migrations/0001_initial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - import django.db.models.deletion from django.conf import settings from django.db import migrations, models @@ -19,7 +16,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')), ('enabled', models.BooleanField(default=False, verbose_name='Enabled')), - ('base_url', models.TextField(help_text=u'The alternative hostname to serve static assets from. Should be in the form of hostname[:port].', blank=True)), + ('base_url', models.TextField(help_text='The alternative hostname to serve static assets from. Should be in the form of hostname[:port].', blank=True)), ('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')), ], ), diff --git a/common/djangoapps/static_replace/migrations/0002_assetexcludedextensionsconfig.py b/common/djangoapps/static_replace/migrations/0002_assetexcludedextensionsconfig.py index d0862300020cc53674458885d86c03acfebc41db..1a6f61fbc865c2994a9372fcb1adb975d353fca6 100644 --- a/common/djangoapps/static_replace/migrations/0002_assetexcludedextensionsconfig.py +++ b/common/djangoapps/static_replace/migrations/0002_assetexcludedextensionsconfig.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - import django.db.models.deletion from django.conf import settings from django.db import migrations, models @@ -20,7 +17,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')), ('enabled', models.BooleanField(default=False, verbose_name='Enabled')), - ('excluded_extensions', models.TextField(default=u'html', help_text=u'The file extensions to exclude from canonicalization. No leading period required. Values should be space separated i.e. "html svg css"')), + ('excluded_extensions', models.TextField(default='html', help_text='The file extensions to exclude from canonicalization. No leading period required. Values should be space separated i.e. "html svg css"')), ('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')), ], ), diff --git a/common/djangoapps/static_replace/models.py b/common/djangoapps/static_replace/models.py index d905043ff2770d1e8c2ed9381a7c231fc092a80a..d7f982368ec1afb4ad6ccb5b84fc90225b33b629 100644 --- a/common/djangoapps/static_replace/models.py +++ b/common/djangoapps/static_replace/models.py @@ -3,9 +3,6 @@ Models for static_replace """ -import six -from six.moves import map - from config_models.models import ConfigurationModel from django.db.models.fields import TextField from django.utils.encoding import python_2_unicode_compatible @@ -19,12 +16,12 @@ class AssetBaseUrlConfig(ConfigurationModel): .. no_pii: """ - class Meta(object): + class Meta: app_label = 'static_replace' base_url = TextField( blank=True, - help_text=u"The alternative hostname to serve static assets from. Should be in the form of hostname[:port]." + help_text="The alternative hostname to serve static assets from. Should be in the form of hostname[:port]." ) @classmethod @@ -33,10 +30,10 @@ class AssetBaseUrlConfig(ConfigurationModel): return cls.current().base_url def __repr__(self): - return '<AssetBaseUrlConfig(base_url={})>'.format(self.get_base_url()) + return f'<AssetBaseUrlConfig(base_url={self.get_base_url()})>' def __str__(self): - return six.text_type(repr(self)) + return str(repr(self)) @python_2_unicode_compatible @@ -47,12 +44,12 @@ class AssetExcludedExtensionsConfig(ConfigurationModel): .. no_pii: """ - class Meta(object): + class Meta: app_label = 'static_replace' excluded_extensions = TextField( - default=u'html', - help_text=u'The file extensions to exclude from canonicalization. No leading period required. ' + + default='html', + help_text='The file extensions to exclude from canonicalization. No leading period required. ' + 'Values should be space separated i.e. "html svg css"' ) @@ -63,7 +60,7 @@ class AssetExcludedExtensionsConfig(ConfigurationModel): return list(map(add_period, cls.current().excluded_extensions.split())) def __repr__(self): - return '<AssetExcludedExtensionsConfig(extensions={})>'.format(self.get_excluded_extensions()) + return f'<AssetExcludedExtensionsConfig(extensions={self.get_excluded_extensions()})>' def __str__(self): - return six.text_type(repr(self)) + return str(repr(self)) diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index fde36d64e644b4d9d7f6d750e4057b5c50a862ac..0afe3ee35f1c9af01b0236b6c742c1ed5cbae9d8 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -1,18 +1,17 @@ -# -*- coding: utf-8 -*- """Tests for static_replace""" import re -from six import BytesIO -from six.moves.urllib.parse import parse_qsl, urlparse, urlunparse +from unittest.mock import Mock, patch import ddt import pytest from django.test import override_settings from django.utils.http import urlencode, urlquote -from mock import Mock, patch from opaque_keys.edx.keys import CourseKey from PIL import Image +from io import BytesIO +from urllib.parse import parse_qsl, urlparse, urlunparse from common.djangoapps.static_replace import ( _url_replace_regex, @@ -68,7 +67,7 @@ def test_process_url(): def test_process_url_data_dir_exists(): - base = '"/static/{data_dir}/file.png"'.format(data_dir=DATA_DIRECTORY) + base = f'"/static/{DATA_DIRECTORY}/file.png"' def processor(original, prefix, quote, rest): # pylint: disable=unused-argument return quote + 'test' + rest + quote @@ -119,7 +118,7 @@ def test_mongo_filestore(mock_get_excluded_extensions, mock_get_base_url, mock_m mock_modulestore.return_value = Mock(MongoModuleStore) mock_static_content.get_canonicalized_asset_path.return_value = "c4x://mock_url" - mock_get_base_url.return_value = u'' + mock_get_base_url.return_value = '' mock_get_excluded_extensions.return_value = ['foobar'] # No namespace => no change to path @@ -129,7 +128,7 @@ def test_mongo_filestore(mock_get_excluded_extensions, mock_get_base_url, mock_m assert '"' + mock_static_content.get_canonicalized_asset_path.return_value + '"' == \ replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY, course_id=COURSE_KEY) - mock_static_content.get_canonicalized_asset_path.assert_called_once_with(COURSE_KEY, 'file.png', u'', ['foobar']) + mock_static_content.get_canonicalized_asset_path.assert_called_once_with(COURSE_KEY, 'file.png', '', ['foobar']) @patch('common.djangoapps.static_replace.settings', autospec=True) @@ -193,9 +192,9 @@ def test_static_paths_out(mock_modulestore, mock_storage): raw_url = '/static/js/capa/protex/protex.nocache.js?raw' xblock_url = '/static/xblock/resources/babys_first.lil_xblock/public/images/pacifier.png' # xss-lint: disable=python-wrap-html - pre_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_url, xblock_url, raw_url) + pre_text = f'EMBED src ="{static_url}" xblock={xblock_url} text <tag a="{raw_url}"/><div class="' # xss-lint: disable=python-wrap-html - post_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_course_url, xblock_url, raw_url) # lint-amnesty, pylint: disable=line-too-long + post_text = f'EMBED src ="{static_course_url}" xblock={xblock_url} text <tag a="{raw_url}"/><div class="' # lint-amnesty, pylint: disable=line-too-long static_paths = [] assert replace_static_urls(pre_text, DATA_DIRECTORY, COURSE_KEY, static_paths_out=static_paths) == post_text assert static_paths == [(static_url, static_course_url), (raw_url, raw_url)] @@ -213,11 +212,11 @@ def test_regex(): regex = _url_replace_regex('/static/') for s in yes: - print('Should match: {0!r}'.format(s)) + print(f'Should match: {s!r}') assert re.match(regex, s) for s in no: - print('Should not match: {0!r}'.format(s)) + print(f'Should not match: {s!r}') assert not re.match(regex, s) @@ -264,7 +263,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): def setUpClass(cls): cls.courses = {} - super(CanonicalContentTest, cls).setUpClass() + super().setUpClass() names_and_prefixes = [(ModuleStoreEnum.Type.split, 'split'), (ModuleStoreEnum.Type.mongo, 'old')] for store, prefix in names_and_prefixes: @@ -272,7 +271,7 @@ class CanonicalContentTest(SharedModuleStoreTestCase): cls.courses[prefix] = CourseFactory.create(org='a', course='b', run=prefix) # Create an unlocked image. - unlock_content = cls.create_image(prefix, (32, 32), 'blue', u'{}_ünlöck.png') + unlock_content = cls.create_image(prefix, (32, 32), 'blue', '{}_ünlöck.png') # Create a locked image. lock_content = cls.create_image(prefix, (32, 32), 'green', '{}_lock.png', locked=True) @@ -282,14 +281,14 @@ class CanonicalContentTest(SharedModuleStoreTestCase): contentstore().generate_thumbnail(lock_content, dimensions=(16, 16)) # Create an unlocked image in a subdirectory. - cls.create_image(prefix, (1, 1), 'red', u'special/{}_ünlöck.png') + cls.create_image(prefix, (1, 1), 'red', 'special/{}_ünlöck.png') # Create a locked image in a subdirectory. cls.create_image(prefix, (1, 1), 'yellow', 'special/{}_lock.png', locked=True) # Create an unlocked image with funky characters in the name. - cls.create_image(prefix, (1, 1), 'black', u'weird {}_ünlöck.png') - cls.create_image(prefix, (1, 1), 'black', u'special/weird {}_ünlöck.png') + cls.create_image(prefix, (1, 1), 'black', 'weird {}_ünlöck.png') + cls.create_image(prefix, (1, 1), 'black', 'special/weird {}_ünlöck.png') # Create an HTML file to test extension exclusion, and create a control file. cls.create_arbitrary_content(prefix, '{}_not_excluded.htm') @@ -365,185 +364,185 @@ class CanonicalContentTest(SharedModuleStoreTestCase): @ddt.data( # No leading slash. - (u'', u'{prfx}_ünlöck.png', u'/{asset}@{prfx}_ünlöck.png', 1), - (u'', u'{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'', u'weird {prfx}_ünlöck.png', u'/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'', u'{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'', u'{prfx}_not_excluded.htm', u'/{asset}@{prfx}_not_excluded.htm', 1), - (u'dev', u'{prfx}_ünlöck.png', u'//dev/{asset}@{prfx}_ünlöck.png', 1), - (u'dev', u'{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'dev', u'weird {prfx}_ünlöck.png', u'//dev/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'dev', u'{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'dev', u'{prfx}_not_excluded.htm', u'//dev/{asset}@{prfx}_not_excluded.htm', 1), + ('', '{prfx}_ünlöck.png', '/{asset}@{prfx}_ünlöck.png', 1), + ('', '{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('', 'weird {prfx}_ünlöck.png', '/{asset}@weird_{prfx}_ünlöck.png', 1), + ('', '{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('', '{prfx}_not_excluded.htm', '/{asset}@{prfx}_not_excluded.htm', 1), + ('dev', '{prfx}_ünlöck.png', '//dev/{asset}@{prfx}_ünlöck.png', 1), + ('dev', '{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('dev', 'weird {prfx}_ünlöck.png', '//dev/{asset}@weird_{prfx}_ünlöck.png', 1), + ('dev', '{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('dev', '{prfx}_not_excluded.htm', '//dev/{asset}@{prfx}_not_excluded.htm', 1), # No leading slash with subdirectory. This ensures we properly substitute slashes. - (u'', u'special/{prfx}_ünlöck.png', u'/{asset}@special_{prfx}_ünlöck.png', 1), - (u'', u'special/{prfx}_lock.png', u'/{asset}@special_{prfx}_lock.png', 1), - (u'', u'special/weird {prfx}_ünlöck.png', u'/{asset}@special_weird_{prfx}_ünlöck.png', 1), - (u'', u'special/{prfx}_excluded.html', u'/{base_asset}@special_{prfx}_excluded.html', 1), - (u'', u'special/{prfx}_not_excluded.htm', u'/{asset}@special_{prfx}_not_excluded.htm', 1), - (u'dev', u'special/{prfx}_ünlöck.png', u'//dev/{asset}@special_{prfx}_ünlöck.png', 1), - (u'dev', u'special/{prfx}_lock.png', u'/{asset}@special_{prfx}_lock.png', 1), - (u'dev', u'special/weird {prfx}_ünlöck.png', u'//dev/{asset}@special_weird_{prfx}_ünlöck.png', 1), - (u'dev', u'special/{prfx}_excluded.html', u'/{base_asset}@special_{prfx}_excluded.html', 1), - (u'dev', u'special/{prfx}_not_excluded.htm', u'//dev/{asset}@special_{prfx}_not_excluded.htm', 1), + ('', 'special/{prfx}_ünlöck.png', '/{asset}@special_{prfx}_ünlöck.png', 1), + ('', 'special/{prfx}_lock.png', '/{asset}@special_{prfx}_lock.png', 1), + ('', 'special/weird {prfx}_ünlöck.png', '/{asset}@special_weird_{prfx}_ünlöck.png', 1), + ('', 'special/{prfx}_excluded.html', '/{base_asset}@special_{prfx}_excluded.html', 1), + ('', 'special/{prfx}_not_excluded.htm', '/{asset}@special_{prfx}_not_excluded.htm', 1), + ('dev', 'special/{prfx}_ünlöck.png', '//dev/{asset}@special_{prfx}_ünlöck.png', 1), + ('dev', 'special/{prfx}_lock.png', '/{asset}@special_{prfx}_lock.png', 1), + ('dev', 'special/weird {prfx}_ünlöck.png', '//dev/{asset}@special_weird_{prfx}_ünlöck.png', 1), + ('dev', 'special/{prfx}_excluded.html', '/{base_asset}@special_{prfx}_excluded.html', 1), + ('dev', 'special/{prfx}_not_excluded.htm', '//dev/{asset}@special_{prfx}_not_excluded.htm', 1), # Leading slash. - (u'', u'/{prfx}_ünlöck.png', u'/{asset}@{prfx}_ünlöck.png', 1), - (u'', u'/{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'', u'/weird {prfx}_ünlöck.png', u'/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'', u'/{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'', u'/{prfx}_not_excluded.htm', u'/{asset}@{prfx}_not_excluded.htm', 1), - (u'dev', u'/{prfx}_ünlöck.png', u'//dev/{asset}@{prfx}_ünlöck.png', 1), - (u'dev', u'/{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'dev', u'/weird {prfx}_ünlöck.png', u'//dev/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'dev', u'/{prfx}_not_excluded.htm', u'//dev/{asset}@{prfx}_not_excluded.htm', 1), + ('', '/{prfx}_ünlöck.png', '/{asset}@{prfx}_ünlöck.png', 1), + ('', '/{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('', '/weird {prfx}_ünlöck.png', '/{asset}@weird_{prfx}_ünlöck.png', 1), + ('', '/{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('', '/{prfx}_not_excluded.htm', '/{asset}@{prfx}_not_excluded.htm', 1), + ('dev', '/{prfx}_ünlöck.png', '//dev/{asset}@{prfx}_ünlöck.png', 1), + ('dev', '/{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('dev', '/weird {prfx}_ünlöck.png', '//dev/{asset}@weird_{prfx}_ünlöck.png', 1), + ('dev', '/{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('dev', '/{prfx}_not_excluded.htm', '//dev/{asset}@{prfx}_not_excluded.htm', 1), # Leading slash with subdirectory. This ensures we properly substitute slashes. - (u'', u'/special/{prfx}_ünlöck.png', u'/{asset}@special_{prfx}_ünlöck.png', 1), - (u'', u'/special/{prfx}_lock.png', u'/{asset}@special_{prfx}_lock.png', 1), - (u'', u'/special/weird {prfx}_ünlöck.png', u'/{asset}@special_weird_{prfx}_ünlöck.png', 1), - (u'', u'/special/{prfx}_excluded.html', u'/{base_asset}@special_{prfx}_excluded.html', 1), - (u'', u'/special/{prfx}_not_excluded.htm', u'/{asset}@special_{prfx}_not_excluded.htm', 1), - (u'dev', u'/special/{prfx}_ünlöck.png', u'//dev/{asset}@special_{prfx}_ünlöck.png', 1), - (u'dev', u'/special/{prfx}_lock.png', u'/{asset}@special_{prfx}_lock.png', 1), - (u'dev', u'/special/weird {prfx}_ünlöck.png', u'//dev/{asset}@special_weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/special/{prfx}_excluded.html', u'/{base_asset}@special_{prfx}_excluded.html', 1), - (u'dev', u'/special/{prfx}_not_excluded.htm', u'//dev/{asset}@special_{prfx}_not_excluded.htm', 1), + ('', '/special/{prfx}_ünlöck.png', '/{asset}@special_{prfx}_ünlöck.png', 1), + ('', '/special/{prfx}_lock.png', '/{asset}@special_{prfx}_lock.png', 1), + ('', '/special/weird {prfx}_ünlöck.png', '/{asset}@special_weird_{prfx}_ünlöck.png', 1), + ('', '/special/{prfx}_excluded.html', '/{base_asset}@special_{prfx}_excluded.html', 1), + ('', '/special/{prfx}_not_excluded.htm', '/{asset}@special_{prfx}_not_excluded.htm', 1), + ('dev', '/special/{prfx}_ünlöck.png', '//dev/{asset}@special_{prfx}_ünlöck.png', 1), + ('dev', '/special/{prfx}_lock.png', '/{asset}@special_{prfx}_lock.png', 1), + ('dev', '/special/weird {prfx}_ünlöck.png', '//dev/{asset}@special_weird_{prfx}_ünlöck.png', 1), + ('dev', '/special/{prfx}_excluded.html', '/{base_asset}@special_{prfx}_excluded.html', 1), + ('dev', '/special/{prfx}_not_excluded.htm', '//dev/{asset}@special_{prfx}_not_excluded.htm', 1), # Static path. - (u'', u'/static/{prfx}_ünlöck.png', u'/{asset}@{prfx}_ünlöck.png', 1), - (u'', u'/static/{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'', u'/static/weird {prfx}_ünlöck.png', u'/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'', u'/static/{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'', u'/static/{prfx}_not_excluded.htm', u'/{asset}@{prfx}_not_excluded.htm', 1), - (u'dev', u'/static/{prfx}_ünlöck.png', u'//dev/{asset}@{prfx}_ünlöck.png', 1), - (u'dev', u'/static/{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'dev', u'/static/weird {prfx}_ünlöck.png', u'//dev/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/static/{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'dev', u'/static/{prfx}_not_excluded.htm', u'//dev/{asset}@{prfx}_not_excluded.htm', 1), + ('', '/static/{prfx}_ünlöck.png', '/{asset}@{prfx}_ünlöck.png', 1), + ('', '/static/{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('', '/static/weird {prfx}_ünlöck.png', '/{asset}@weird_{prfx}_ünlöck.png', 1), + ('', '/static/{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('', '/static/{prfx}_not_excluded.htm', '/{asset}@{prfx}_not_excluded.htm', 1), + ('dev', '/static/{prfx}_ünlöck.png', '//dev/{asset}@{prfx}_ünlöck.png', 1), + ('dev', '/static/{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('dev', '/static/weird {prfx}_ünlöck.png', '//dev/{asset}@weird_{prfx}_ünlöck.png', 1), + ('dev', '/static/{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('dev', '/static/{prfx}_not_excluded.htm', '//dev/{asset}@{prfx}_not_excluded.htm', 1), # Static path with subdirectory. This ensures we properly substitute slashes. - (u'', u'/static/special/{prfx}_ünlöck.png', u'/{asset}@special_{prfx}_ünlöck.png', 1), - (u'', u'/static/special/{prfx}_lock.png', u'/{asset}@special_{prfx}_lock.png', 1), - (u'', u'/static/special/weird {prfx}_ünlöck.png', u'/{asset}@special_weird_{prfx}_ünlöck.png', 1), - (u'', u'/static/special/{prfx}_excluded.html', u'/{base_asset}@special_{prfx}_excluded.html', 1), - (u'', u'/static/special/{prfx}_not_excluded.htm', u'/{asset}@special_{prfx}_not_excluded.htm', 1), - (u'dev', u'/static/special/{prfx}_ünlöck.png', u'//dev/{asset}@special_{prfx}_ünlöck.png', 1), - (u'dev', u'/static/special/{prfx}_lock.png', u'/{asset}@special_{prfx}_lock.png', 1), - (u'dev', u'/static/special/weird {prfx}_ünlöck.png', u'//dev/{asset}@special_weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/static/special/{prfx}_excluded.html', u'/{base_asset}@special_{prfx}_excluded.html', 1), - (u'dev', u'/static/special/{prfx}_not_excluded.htm', u'//dev/{asset}@special_{prfx}_not_excluded.htm', 1), + ('', '/static/special/{prfx}_ünlöck.png', '/{asset}@special_{prfx}_ünlöck.png', 1), + ('', '/static/special/{prfx}_lock.png', '/{asset}@special_{prfx}_lock.png', 1), + ('', '/static/special/weird {prfx}_ünlöck.png', '/{asset}@special_weird_{prfx}_ünlöck.png', 1), + ('', '/static/special/{prfx}_excluded.html', '/{base_asset}@special_{prfx}_excluded.html', 1), + ('', '/static/special/{prfx}_not_excluded.htm', '/{asset}@special_{prfx}_not_excluded.htm', 1), + ('dev', '/static/special/{prfx}_ünlöck.png', '//dev/{asset}@special_{prfx}_ünlöck.png', 1), + ('dev', '/static/special/{prfx}_lock.png', '/{asset}@special_{prfx}_lock.png', 1), + ('dev', '/static/special/weird {prfx}_ünlöck.png', '//dev/{asset}@special_weird_{prfx}_ünlöck.png', 1), + ('dev', '/static/special/{prfx}_excluded.html', '/{base_asset}@special_{prfx}_excluded.html', 1), + ('dev', '/static/special/{prfx}_not_excluded.htm', '//dev/{asset}@special_{prfx}_not_excluded.htm', 1), # Static path with query parameter. ( - u'', - u'/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', - u'/{asset}@{prfx}_ünlöck.png?foo={encoded_asset}{prfx}_lock.png', + '', + '/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', + '/{asset}@{prfx}_ünlöck.png?foo={encoded_asset}{prfx}_lock.png', 2 ), ( - u'', - u'/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', - u'/{asset}@{prfx}_lock.png?foo={encoded_asset}{prfx}_ünlöck.png', + '', + '/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', + '/{asset}@{prfx}_lock.png?foo={encoded_asset}{prfx}_ünlöck.png', 2 ), ( - u'', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', - u'/{base_asset}@{prfx}_excluded.html?foo={encoded_base_asset}{prfx}_excluded.html', + '', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', + '/{base_asset}@{prfx}_excluded.html?foo={encoded_base_asset}{prfx}_excluded.html', 2 ), ( - u'', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', - u'/{base_asset}@{prfx}_excluded.html?foo={encoded_asset}{prfx}_not_excluded.htm', + '', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', + '/{base_asset}@{prfx}_excluded.html?foo={encoded_asset}{prfx}_not_excluded.htm', 2 ), ( - u'', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', - u'/{asset}@{prfx}_not_excluded.htm?foo={encoded_base_asset}{prfx}_excluded.html', + '', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', + '/{asset}@{prfx}_not_excluded.htm?foo={encoded_base_asset}{prfx}_excluded.html', 2 ), ( - u'', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', - u'/{asset}@{prfx}_not_excluded.htm?foo={encoded_asset}{prfx}_not_excluded.htm', + '', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', + '/{asset}@{prfx}_not_excluded.htm?foo={encoded_asset}{prfx}_not_excluded.htm', 2 ), ( - u'dev', - u'/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', - u'//dev/{asset}@{prfx}_ünlöck.png?foo={encoded_asset}{prfx}_lock.png', + 'dev', + '/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', + '//dev/{asset}@{prfx}_ünlöck.png?foo={encoded_asset}{prfx}_lock.png', 2 ), ( - u'dev', - u'/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', - u'/{asset}@{prfx}_lock.png?foo={encoded_base_url}{encoded_asset}{prfx}_ünlöck.png', + 'dev', + '/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', + '/{asset}@{prfx}_lock.png?foo={encoded_base_url}{encoded_asset}{prfx}_ünlöck.png', 2 ), ( - u'dev', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', - u'/{base_asset}@{prfx}_excluded.html?foo={encoded_base_asset}{prfx}_excluded.html', + 'dev', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', + '/{base_asset}@{prfx}_excluded.html?foo={encoded_base_asset}{prfx}_excluded.html', 2 ), ( - u'dev', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', - u'/{base_asset}@{prfx}_excluded.html?foo={encoded_base_url}{encoded_asset}{prfx}_not_excluded.htm', + 'dev', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', + '/{base_asset}@{prfx}_excluded.html?foo={encoded_base_url}{encoded_asset}{prfx}_not_excluded.htm', 2 ), ( - u'dev', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', - u'//dev/{asset}@{prfx}_not_excluded.htm?foo={encoded_base_asset}{prfx}_excluded.html', + 'dev', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', + '//dev/{asset}@{prfx}_not_excluded.htm?foo={encoded_base_asset}{prfx}_excluded.html', 2 ), ( - u'dev', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', - u'//dev/{asset}@{prfx}_not_excluded.htm?foo={encoded_base_url}{encoded_asset}{prfx}_not_excluded.htm', + 'dev', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', + '//dev/{asset}@{prfx}_not_excluded.htm?foo={encoded_base_url}{encoded_asset}{prfx}_not_excluded.htm', 2 ), # Already asset key. - (u'', u'/{base_asset}@{prfx}_ünlöck.png', u'/{asset}@{prfx}_ünlöck.png', 1), - (u'', u'/{base_asset}@{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'', u'/{base_asset}@weird_{prfx}_ünlöck.png', u'/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'', u'/{base_asset}@{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'', u'/{base_asset}@{prfx}_not_excluded.htm', u'/{asset}@{prfx}_not_excluded.htm', 1), - (u'dev', u'/{base_asset}@{prfx}_ünlöck.png', u'//dev/{asset}@{prfx}_ünlöck.png', 1), - (u'dev', u'/{base_asset}@{prfx}_lock.png', u'/{asset}@{prfx}_lock.png', 1), - (u'dev', u'/{base_asset}@weird_{prfx}_ünlöck.png', u'//dev/{asset}@weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/{base_asset}@{prfx}_excluded.html', u'/{base_asset}@{prfx}_excluded.html', 1), - (u'dev', u'/{base_asset}@{prfx}_not_excluded.htm', u'//dev/{asset}@{prfx}_not_excluded.htm', 1), + ('', '/{base_asset}@{prfx}_ünlöck.png', '/{asset}@{prfx}_ünlöck.png', 1), + ('', '/{base_asset}@{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('', '/{base_asset}@weird_{prfx}_ünlöck.png', '/{asset}@weird_{prfx}_ünlöck.png', 1), + ('', '/{base_asset}@{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('', '/{base_asset}@{prfx}_not_excluded.htm', '/{asset}@{prfx}_not_excluded.htm', 1), + ('dev', '/{base_asset}@{prfx}_ünlöck.png', '//dev/{asset}@{prfx}_ünlöck.png', 1), + ('dev', '/{base_asset}@{prfx}_lock.png', '/{asset}@{prfx}_lock.png', 1), + ('dev', '/{base_asset}@weird_{prfx}_ünlöck.png', '//dev/{asset}@weird_{prfx}_ünlöck.png', 1), + ('dev', '/{base_asset}@{prfx}_excluded.html', '/{base_asset}@{prfx}_excluded.html', 1), + ('dev', '/{base_asset}@{prfx}_not_excluded.htm', '//dev/{asset}@{prfx}_not_excluded.htm', 1), # Old, c4x-style path. - (u'', u'/{c4x}/{prfx}_ünlöck.png', u'/{c4x}/{prfx}_ünlöck.png', 1), - (u'', u'/{c4x}/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'', u'/{c4x}/weird_{prfx}_lock.png', u'/{c4x}/weird_{prfx}_lock.png', 1), - (u'', u'/{c4x}/{prfx}_excluded.html', u'/{c4x}/{prfx}_excluded.html', 1), - (u'', u'/{c4x}/{prfx}_not_excluded.htm', u'/{c4x}/{prfx}_not_excluded.htm', 1), - (u'dev', u'/{c4x}/{prfx}_ünlöck.png', u'/{c4x}/{prfx}_ünlöck.png', 1), - (u'dev', u'/{c4x}/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'dev', u'/{c4x}/weird_{prfx}_ünlöck.png', u'/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/{c4x}/{prfx}_excluded.html', u'/{c4x}/{prfx}_excluded.html', 1), - (u'dev', u'/{c4x}/{prfx}_not_excluded.htm', u'/{c4x}/{prfx}_not_excluded.htm', 1), + ('', '/{c4x}/{prfx}_ünlöck.png', '/{c4x}/{prfx}_ünlöck.png', 1), + ('', '/{c4x}/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('', '/{c4x}/weird_{prfx}_lock.png', '/{c4x}/weird_{prfx}_lock.png', 1), + ('', '/{c4x}/{prfx}_excluded.html', '/{c4x}/{prfx}_excluded.html', 1), + ('', '/{c4x}/{prfx}_not_excluded.htm', '/{c4x}/{prfx}_not_excluded.htm', 1), + ('dev', '/{c4x}/{prfx}_ünlöck.png', '/{c4x}/{prfx}_ünlöck.png', 1), + ('dev', '/{c4x}/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('dev', '/{c4x}/weird_{prfx}_ünlöck.png', '/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('dev', '/{c4x}/{prfx}_excluded.html', '/{c4x}/{prfx}_excluded.html', 1), + ('dev', '/{c4x}/{prfx}_not_excluded.htm', '/{c4x}/{prfx}_not_excluded.htm', 1), # Thumbnails. - (u'', u'/{base_th_key}@{prfx}_ünlöck-{th_ext}', u'/{th_key}@{prfx}_ünlöck-{th_ext}', 1), - (u'', u'/{base_th_key}@{prfx}_lock-{th_ext}', u'/{th_key}@{prfx}_lock-{th_ext}', 1), - (u'dev', u'/{base_th_key}@{prfx}_ünlöck-{th_ext}', u'//dev/{th_key}@{prfx}_ünlöck-{th_ext}', 1), - (u'dev', u'/{base_th_key}@{prfx}_lock-{th_ext}', u'//dev/{th_key}@{prfx}_lock-{th_ext}', 1), + ('', '/{base_th_key}@{prfx}_ünlöck-{th_ext}', '/{th_key}@{prfx}_ünlöck-{th_ext}', 1), + ('', '/{base_th_key}@{prfx}_lock-{th_ext}', '/{th_key}@{prfx}_lock-{th_ext}', 1), + ('dev', '/{base_th_key}@{prfx}_ünlöck-{th_ext}', '//dev/{th_key}@{prfx}_ünlöck-{th_ext}', 1), + ('dev', '/{base_th_key}@{prfx}_lock-{th_ext}', '//dev/{th_key}@{prfx}_lock-{th_ext}', 1), ) @ddt.unpack def test_canonical_asset_path_with_new_style_assets(self, base_url, start, expected, mongo_calls): exts = ['.html', '.tm'] - prefix = u'split' - encoded_base_url = urlquote(u'//' + base_url) - c4x = u'c4x/a/b/asset' - base_asset_key = u'asset-v1:a+b+{}+type@asset+block'.format(prefix) + prefix = 'split' + encoded_base_url = urlquote('//' + base_url) + c4x = 'c4x/a/b/asset' + base_asset_key = f'asset-v1:a+b+{prefix}+type@asset+block' adjusted_asset_key = base_asset_key - encoded_asset_key = urlquote(u'/asset-v1:a+b+{}+type@asset+block@'.format(prefix)) + encoded_asset_key = urlquote(f'/asset-v1:a+b+{prefix}+type@asset+block@') encoded_base_asset_key = encoded_asset_key - base_th_key = u'asset-v1:a+b+{}+type@thumbnail+block'.format(prefix) + base_th_key = f'asset-v1:a+b+{prefix}+type@thumbnail+block' adjusted_th_key = base_th_key - th_ext = u'png-16x16.jpg' + th_ext = 'png-16x16.jpg' start = start.format( prfx=prefix, @@ -563,9 +562,9 @@ class CanonicalContentTest(SharedModuleStoreTestCase): # - finally shove back in our regex patterns digest = CanonicalContentTest.get_content_digest_for_asset_path(prefix, start) if digest: - adjusted_asset_key = u'assets/courseware/VMARK/HMARK/asset-v1:a+b+{}+type@asset+block'.format(prefix) - adjusted_th_key = u'assets/courseware/VMARK/HMARK/asset-v1:a+b+{}+type@thumbnail+block'.format(prefix) - encoded_asset_key = u'/assets/courseware/VMARK/HMARK/asset-v1:a+b+{}+type@asset+block@'.format(prefix) + adjusted_asset_key = f'assets/courseware/VMARK/HMARK/asset-v1:a+b+{prefix}+type@asset+block' + adjusted_th_key = f'assets/courseware/VMARK/HMARK/asset-v1:a+b+{prefix}+type@thumbnail+block' + encoded_asset_key = f'/assets/courseware/VMARK/HMARK/asset-v1:a+b+{prefix}+type@asset+block@' encoded_asset_key = urlquote(encoded_asset_key) expected = expected.format( @@ -592,155 +591,155 @@ class CanonicalContentTest(SharedModuleStoreTestCase): @ddt.data( # No leading slash. - (u'', u'{prfx}_ünlöck.png', u'/{c4x}/{prfx}_ünlöck.png', 1), - (u'', u'{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'', u'weird {prfx}_ünlöck.png', u'/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'', u'{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'', u'{prfx}_not_excluded.htm', u'/{c4x}/{prfx}_not_excluded.htm', 1), - (u'dev', u'{prfx}_ünlöck.png', u'//dev/{c4x}/{prfx}_ünlöck.png', 1), - (u'dev', u'{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'dev', u'weird {prfx}_ünlöck.png', u'//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'dev', u'{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'dev', u'{prfx}_not_excluded.htm', u'//dev/{c4x}/{prfx}_not_excluded.htm', 1), + ('', '{prfx}_ünlöck.png', '/{c4x}/{prfx}_ünlöck.png', 1), + ('', '{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('', 'weird {prfx}_ünlöck.png', '/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('', '{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('', '{prfx}_not_excluded.htm', '/{c4x}/{prfx}_not_excluded.htm', 1), + ('dev', '{prfx}_ünlöck.png', '//dev/{c4x}/{prfx}_ünlöck.png', 1), + ('dev', '{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('dev', 'weird {prfx}_ünlöck.png', '//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('dev', '{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('dev', '{prfx}_not_excluded.htm', '//dev/{c4x}/{prfx}_not_excluded.htm', 1), # No leading slash with subdirectory. This ensures we probably substitute slashes. - (u'', u'special/{prfx}_ünlöck.png', u'/{c4x}/special_{prfx}_ünlöck.png', 1), - (u'', u'special/{prfx}_lock.png', u'/{c4x}/special_{prfx}_lock.png', 1), - (u'', u'special/weird {prfx}_ünlöck.png', u'/{c4x}/special_weird_{prfx}_ünlöck.png', 1), - (u'', u'special/{prfx}_excluded.html', u'/{base_c4x}/special_{prfx}_excluded.html', 1), - (u'', u'special/{prfx}_not_excluded.htm', u'/{c4x}/special_{prfx}_not_excluded.htm', 1), - (u'dev', u'special/{prfx}_ünlöck.png', u'//dev/{c4x}/special_{prfx}_ünlöck.png', 1), - (u'dev', u'special/{prfx}_lock.png', u'/{c4x}/special_{prfx}_lock.png', 1), - (u'dev', u'special/weird {prfx}_ünlöck.png', u'//dev/{c4x}/special_weird_{prfx}_ünlöck.png', 1), - (u'dev', u'special/{prfx}_excluded.html', u'/{base_c4x}/special_{prfx}_excluded.html', 1), - (u'dev', u'special/{prfx}_not_excluded.htm', u'//dev/{c4x}/special_{prfx}_not_excluded.htm', 1), + ('', 'special/{prfx}_ünlöck.png', '/{c4x}/special_{prfx}_ünlöck.png', 1), + ('', 'special/{prfx}_lock.png', '/{c4x}/special_{prfx}_lock.png', 1), + ('', 'special/weird {prfx}_ünlöck.png', '/{c4x}/special_weird_{prfx}_ünlöck.png', 1), + ('', 'special/{prfx}_excluded.html', '/{base_c4x}/special_{prfx}_excluded.html', 1), + ('', 'special/{prfx}_not_excluded.htm', '/{c4x}/special_{prfx}_not_excluded.htm', 1), + ('dev', 'special/{prfx}_ünlöck.png', '//dev/{c4x}/special_{prfx}_ünlöck.png', 1), + ('dev', 'special/{prfx}_lock.png', '/{c4x}/special_{prfx}_lock.png', 1), + ('dev', 'special/weird {prfx}_ünlöck.png', '//dev/{c4x}/special_weird_{prfx}_ünlöck.png', 1), + ('dev', 'special/{prfx}_excluded.html', '/{base_c4x}/special_{prfx}_excluded.html', 1), + ('dev', 'special/{prfx}_not_excluded.htm', '//dev/{c4x}/special_{prfx}_not_excluded.htm', 1), # Leading slash. - (u'', u'/{prfx}_ünlöck.png', u'/{c4x}/{prfx}_ünlöck.png', 1), - (u'', u'/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'', u'/weird {prfx}_ünlöck.png', u'/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'', u'/{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'', u'/{prfx}_not_excluded.htm', u'/{c4x}/{prfx}_not_excluded.htm', 1), - (u'dev', u'/{prfx}_ünlöck.png', u'//dev/{c4x}/{prfx}_ünlöck.png', 1), - (u'dev', u'/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'dev', u'/weird {prfx}_ünlöck.png', u'//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'dev', u'/{prfx}_not_excluded.htm', u'//dev/{c4x}/{prfx}_not_excluded.htm', 1), + ('', '/{prfx}_ünlöck.png', '/{c4x}/{prfx}_ünlöck.png', 1), + ('', '/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('', '/weird {prfx}_ünlöck.png', '/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('', '/{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('', '/{prfx}_not_excluded.htm', '/{c4x}/{prfx}_not_excluded.htm', 1), + ('dev', '/{prfx}_ünlöck.png', '//dev/{c4x}/{prfx}_ünlöck.png', 1), + ('dev', '/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('dev', '/weird {prfx}_ünlöck.png', '//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('dev', '/{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('dev', '/{prfx}_not_excluded.htm', '//dev/{c4x}/{prfx}_not_excluded.htm', 1), # Leading slash with subdirectory. This ensures we properly substitute slashes. - (u'', u'/special/{prfx}_ünlöck.png', u'/{c4x}/special_{prfx}_ünlöck.png', 1), - (u'', u'/special/{prfx}_lock.png', u'/{c4x}/special_{prfx}_lock.png', 1), - (u'', u'/special/weird {prfx}_ünlöck.png', u'/{c4x}/special_weird_{prfx}_ünlöck.png', 1), - (u'', u'/special/{prfx}_excluded.html', u'/{base_c4x}/special_{prfx}_excluded.html', 1), - (u'', u'/special/{prfx}_not_excluded.htm', u'/{c4x}/special_{prfx}_not_excluded.htm', 1), - (u'dev', u'/special/{prfx}_ünlöck.png', u'//dev/{c4x}/special_{prfx}_ünlöck.png', 1), - (u'dev', u'/special/{prfx}_lock.png', u'/{c4x}/special_{prfx}_lock.png', 1), - (u'dev', u'/special/weird {prfx}_ünlöck.png', u'//dev/{c4x}/special_weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/special/{prfx}_excluded.html', u'/{base_c4x}/special_{prfx}_excluded.html', 1), - (u'dev', u'/special/{prfx}_not_excluded.htm', u'//dev/{c4x}/special_{prfx}_not_excluded.htm', 1), + ('', '/special/{prfx}_ünlöck.png', '/{c4x}/special_{prfx}_ünlöck.png', 1), + ('', '/special/{prfx}_lock.png', '/{c4x}/special_{prfx}_lock.png', 1), + ('', '/special/weird {prfx}_ünlöck.png', '/{c4x}/special_weird_{prfx}_ünlöck.png', 1), + ('', '/special/{prfx}_excluded.html', '/{base_c4x}/special_{prfx}_excluded.html', 1), + ('', '/special/{prfx}_not_excluded.htm', '/{c4x}/special_{prfx}_not_excluded.htm', 1), + ('dev', '/special/{prfx}_ünlöck.png', '//dev/{c4x}/special_{prfx}_ünlöck.png', 1), + ('dev', '/special/{prfx}_lock.png', '/{c4x}/special_{prfx}_lock.png', 1), + ('dev', '/special/weird {prfx}_ünlöck.png', '//dev/{c4x}/special_weird_{prfx}_ünlöck.png', 1), + ('dev', '/special/{prfx}_excluded.html', '/{base_c4x}/special_{prfx}_excluded.html', 1), + ('dev', '/special/{prfx}_not_excluded.htm', '//dev/{c4x}/special_{prfx}_not_excluded.htm', 1), # Static path. - (u'', u'/static/{prfx}_ünlöck.png', u'/{c4x}/{prfx}_ünlöck.png', 1), - (u'', u'/static/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'', u'/static/weird {prfx}_ünlöck.png', u'/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'', u'/static/{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'', u'/static/{prfx}_not_excluded.htm', u'/{c4x}/{prfx}_not_excluded.htm', 1), - (u'dev', u'/static/{prfx}_ünlöck.png', u'//dev/{c4x}/{prfx}_ünlöck.png', 1), - (u'dev', u'/static/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'dev', u'/static/weird {prfx}_ünlöck.png', u'//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/static/{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'dev', u'/static/{prfx}_not_excluded.htm', u'//dev/{c4x}/{prfx}_not_excluded.htm', 1), + ('', '/static/{prfx}_ünlöck.png', '/{c4x}/{prfx}_ünlöck.png', 1), + ('', '/static/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('', '/static/weird {prfx}_ünlöck.png', '/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('', '/static/{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('', '/static/{prfx}_not_excluded.htm', '/{c4x}/{prfx}_not_excluded.htm', 1), + ('dev', '/static/{prfx}_ünlöck.png', '//dev/{c4x}/{prfx}_ünlöck.png', 1), + ('dev', '/static/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('dev', '/static/weird {prfx}_ünlöck.png', '//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('dev', '/static/{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('dev', '/static/{prfx}_not_excluded.htm', '//dev/{c4x}/{prfx}_not_excluded.htm', 1), # Static path with subdirectory. This ensures we properly substitute slashes. - (u'', u'/static/special/{prfx}_ünlöck.png', u'/{c4x}/special_{prfx}_ünlöck.png', 1), - (u'', u'/static/special/{prfx}_lock.png', u'/{c4x}/special_{prfx}_lock.png', 1), - (u'', u'/static/special/weird {prfx}_ünlöck.png', u'/{c4x}/special_weird_{prfx}_ünlöck.png', 1), - (u'', u'/static/special/{prfx}_excluded.html', u'/{base_c4x}/special_{prfx}_excluded.html', 1), - (u'', u'/static/special/{prfx}_not_excluded.htm', u'/{c4x}/special_{prfx}_not_excluded.htm', 1), - (u'dev', u'/static/special/{prfx}_ünlöck.png', u'//dev/{c4x}/special_{prfx}_ünlöck.png', 1), - (u'dev', u'/static/special/{prfx}_lock.png', u'/{c4x}/special_{prfx}_lock.png', 1), - (u'dev', u'/static/special/weird {prfx}_ünlöck.png', u'//dev/{c4x}/special_weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/static/special/{prfx}_excluded.html', u'/{base_c4x}/special_{prfx}_excluded.html', 1), - (u'dev', u'/static/special/{prfx}_not_excluded.htm', u'//dev/{c4x}/special_{prfx}_not_excluded.htm', 1), + ('', '/static/special/{prfx}_ünlöck.png', '/{c4x}/special_{prfx}_ünlöck.png', 1), + ('', '/static/special/{prfx}_lock.png', '/{c4x}/special_{prfx}_lock.png', 1), + ('', '/static/special/weird {prfx}_ünlöck.png', '/{c4x}/special_weird_{prfx}_ünlöck.png', 1), + ('', '/static/special/{prfx}_excluded.html', '/{base_c4x}/special_{prfx}_excluded.html', 1), + ('', '/static/special/{prfx}_not_excluded.htm', '/{c4x}/special_{prfx}_not_excluded.htm', 1), + ('dev', '/static/special/{prfx}_ünlöck.png', '//dev/{c4x}/special_{prfx}_ünlöck.png', 1), + ('dev', '/static/special/{prfx}_lock.png', '/{c4x}/special_{prfx}_lock.png', 1), + ('dev', '/static/special/weird {prfx}_ünlöck.png', '//dev/{c4x}/special_weird_{prfx}_ünlöck.png', 1), + ('dev', '/static/special/{prfx}_excluded.html', '/{base_c4x}/special_{prfx}_excluded.html', 1), + ('dev', '/static/special/{prfx}_not_excluded.htm', '//dev/{c4x}/special_{prfx}_not_excluded.htm', 1), # Static path with query parameter. ( - u'', - u'/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', - u'/{c4x}/{prfx}_ünlöck.png?foo={encoded_c4x}{prfx}_lock.png', + '', + '/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', + '/{c4x}/{prfx}_ünlöck.png?foo={encoded_c4x}{prfx}_lock.png', 2 ), ( - u'', - u'/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', - u'/{c4x}/{prfx}_lock.png?foo={encoded_c4x}{prfx}_ünlöck.png', + '', + '/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', + '/{c4x}/{prfx}_lock.png?foo={encoded_c4x}{prfx}_ünlöck.png', 2 ), ( - u'', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', - u'/{base_c4x}/{prfx}_excluded.html?foo={encoded_base_c4x}{prfx}_excluded.html', + '', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', + '/{base_c4x}/{prfx}_excluded.html?foo={encoded_base_c4x}{prfx}_excluded.html', 2 ), ( - u'', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', - u'/{base_c4x}/{prfx}_excluded.html?foo={encoded_c4x}{prfx}_not_excluded.htm', + '', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', + '/{base_c4x}/{prfx}_excluded.html?foo={encoded_c4x}{prfx}_not_excluded.htm', 2 ), ( - u'', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', - u'/{c4x}/{prfx}_not_excluded.htm?foo={encoded_base_c4x}{prfx}_excluded.html', + '', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', + '/{c4x}/{prfx}_not_excluded.htm?foo={encoded_base_c4x}{prfx}_excluded.html', 2 ), ( - u'', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', - u'/{c4x}/{prfx}_not_excluded.htm?foo={encoded_c4x}{prfx}_not_excluded.htm', + '', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', + '/{c4x}/{prfx}_not_excluded.htm?foo={encoded_c4x}{prfx}_not_excluded.htm', 2 ), ( - u'dev', - u'/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', - u'//dev/{c4x}/{prfx}_ünlöck.png?foo={encoded_c4x}{prfx}_lock.png', + 'dev', + '/static/{prfx}_ünlöck.png?foo=/static/{prfx}_lock.png', + '//dev/{c4x}/{prfx}_ünlöck.png?foo={encoded_c4x}{prfx}_lock.png', 2 ), ( - u'dev', - u'/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', - u'/{c4x}/{prfx}_lock.png?foo={encoded_base_url}{encoded_c4x}{prfx}_ünlöck.png', + 'dev', + '/static/{prfx}_lock.png?foo=/static/{prfx}_ünlöck.png', + '/{c4x}/{prfx}_lock.png?foo={encoded_base_url}{encoded_c4x}{prfx}_ünlöck.png', 2 ), ( - u'dev', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', - u'/{base_c4x}/{prfx}_excluded.html?foo={encoded_base_c4x}{prfx}_excluded.html', + 'dev', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_excluded.html', + '/{base_c4x}/{prfx}_excluded.html?foo={encoded_base_c4x}{prfx}_excluded.html', 2 ), ( - u'dev', - u'/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', - u'/{base_c4x}/{prfx}_excluded.html?foo={encoded_base_url}{encoded_c4x}{prfx}_not_excluded.htm', + 'dev', + '/static/{prfx}_excluded.html?foo=/static/{prfx}_not_excluded.htm', + '/{base_c4x}/{prfx}_excluded.html?foo={encoded_base_url}{encoded_c4x}{prfx}_not_excluded.htm', 2 ), ( - u'dev', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', - u'//dev/{c4x}/{prfx}_not_excluded.htm?foo={encoded_base_c4x}{prfx}_excluded.html', + 'dev', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_excluded.html', + '//dev/{c4x}/{prfx}_not_excluded.htm?foo={encoded_base_c4x}{prfx}_excluded.html', 2 ), ( - u'dev', - u'/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', - u'//dev/{c4x}/{prfx}_not_excluded.htm?foo={encoded_base_url}{encoded_c4x}{prfx}_not_excluded.htm', + 'dev', + '/static/{prfx}_not_excluded.htm?foo=/static/{prfx}_not_excluded.htm', + '//dev/{c4x}/{prfx}_not_excluded.htm?foo={encoded_base_url}{encoded_c4x}{prfx}_not_excluded.htm', 2 ), # Old, c4x-style path. - (u'', u'/{c4x}/{prfx}_ünlöck.png', u'/{c4x}/{prfx}_ünlöck.png', 1), - (u'', u'/{c4x}/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'', u'/{c4x}/weird_{prfx}_lock.png', u'/{c4x}/weird_{prfx}_lock.png', 1), - (u'', u'/{c4x}/{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'', u'/{c4x}/{prfx}_not_excluded.htm', u'/{c4x}/{prfx}_not_excluded.htm', 1), - (u'dev', u'/{c4x}/{prfx}_ünlöck.png', u'//dev/{c4x}/{prfx}_ünlöck.png', 1), - (u'dev', u'/{c4x}/{prfx}_lock.png', u'/{c4x}/{prfx}_lock.png', 1), - (u'dev', u'/{c4x}/weird_{prfx}_ünlöck.png', u'//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), - (u'dev', u'/{c4x}/{prfx}_excluded.html', u'/{base_c4x}/{prfx}_excluded.html', 1), - (u'dev', u'/{c4x}/{prfx}_not_excluded.htm', u'//dev/{c4x}/{prfx}_not_excluded.htm', 1), + ('', '/{c4x}/{prfx}_ünlöck.png', '/{c4x}/{prfx}_ünlöck.png', 1), + ('', '/{c4x}/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('', '/{c4x}/weird_{prfx}_lock.png', '/{c4x}/weird_{prfx}_lock.png', 1), + ('', '/{c4x}/{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('', '/{c4x}/{prfx}_not_excluded.htm', '/{c4x}/{prfx}_not_excluded.htm', 1), + ('dev', '/{c4x}/{prfx}_ünlöck.png', '//dev/{c4x}/{prfx}_ünlöck.png', 1), + ('dev', '/{c4x}/{prfx}_lock.png', '/{c4x}/{prfx}_lock.png', 1), + ('dev', '/{c4x}/weird_{prfx}_ünlöck.png', '//dev/{c4x}/weird_{prfx}_ünlöck.png', 1), + ('dev', '/{c4x}/{prfx}_excluded.html', '/{base_c4x}/{prfx}_excluded.html', 1), + ('dev', '/{c4x}/{prfx}_not_excluded.htm', '//dev/{c4x}/{prfx}_not_excluded.htm', 1), ) @ddt.unpack def test_canonical_asset_path_with_c4x_style_assets(self, base_url, start, expected, mongo_calls):