diff options
Diffstat (limited to 'tests/test_config')
| -rw-r--r-- | tests/test_config/pkgs/cachebust/__init__.py | 0 | ||||
| -rw-r--r-- | tests/test_config/pkgs/cachebust/override/foo.png | bin | 0 -> 72 bytes | |||
| -rw-r--r-- | tests/test_config/pkgs/cachebust/path/foo.png | bin | 0 -> 72 bytes | |||
| -rw-r--r-- | tests/test_config/test_assets.py | 61 | ||||
| -rw-r--r-- | tests/test_config/test_views.py | 25 |
5 files changed, 80 insertions, 6 deletions
diff --git a/tests/test_config/pkgs/cachebust/__init__.py b/tests/test_config/pkgs/cachebust/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/test_config/pkgs/cachebust/__init__.py diff --git a/tests/test_config/pkgs/cachebust/override/foo.png b/tests/test_config/pkgs/cachebust/override/foo.png Binary files differnew file mode 100644 index 000000000..1cc2f763c --- /dev/null +++ b/tests/test_config/pkgs/cachebust/override/foo.png diff --git a/tests/test_config/pkgs/cachebust/path/foo.png b/tests/test_config/pkgs/cachebust/path/foo.png Binary files differnew file mode 100644 index 000000000..43440f881 --- /dev/null +++ b/tests/test_config/pkgs/cachebust/path/foo.png diff --git a/tests/test_config/test_assets.py b/tests/test_config/test_assets.py index 1d2cfcd5c..ea2fff741 100644 --- a/tests/test_config/test_assets.py +++ b/tests/test_config/test_assets.py @@ -638,6 +638,28 @@ class TestPackageOverrides(unittest.TestCase): po.overrides = overrides self.assertEqual(list(po.filtered_sources('whatever')), ['foo']) + def test_get_spec(self): + source = DummyAssetSource(spec='test:foo.pt') + overrides = [DummyOverride(None), DummyOverride((source, ''))] + package = DummyPackage('package') + po = self._makeOne(package) + po.overrides = overrides + result = po.get_spec('whatever') + self.assertEqual(result, 'test:foo.pt') + self.assertEqual(source.resource_name, '') + + def test_get_spec_file_doesnt_exist(self): + source = DummyAssetSource(spec=None) + overrides = [ + DummyOverride(None), + DummyOverride((source, 'wont_exist')), + ] + package = DummyPackage('package') + po = self._makeOne(package) + po.overrides = overrides + self.assertEqual(po.get_spec('whatever'), None) + self.assertEqual(source.resource_name, 'wont_exist') + def test_get_filename(self): source = DummyAssetSource(filename='foo.pt') overrides = [DummyOverride(None), DummyOverride((source, ''))] @@ -916,6 +938,24 @@ class TestPackageAssetSource(AssetSourceIntegrationTests, unittest.TestCase): klass = self._getTargetClass() return klass(package, prefix) + def test_get_spec(self): + source = self._makeOne('') + self.assertEqual( + source.get_spec('test_assets.py'), + 'tests.test_config:test_assets.py', + ) + + def test_get_spec_with_prefix(self): + source = self._makeOne('test_assets.py') + self.assertEqual( + source.get_spec(''), + 'tests.test_config:test_assets.py', + ) + + def test_get_spec_file_doesnt_exist(self): + source = self._makeOne('') + self.assertIsNone(source.get_spec('wont_exist')) + class TestFSAssetSource(AssetSourceIntegrationTests, unittest.TestCase): def _getTargetClass(self): @@ -927,6 +967,23 @@ class TestFSAssetSource(AssetSourceIntegrationTests, unittest.TestCase): klass = self._getTargetClass() return klass(os.path.join(base_prefix, prefix)) + def test_get_spec(self): + source = self._makeOne('') + self.assertEqual( + source.get_spec('test_assets.py'), + os.path.join(here, 'test_assets.py'), + ) + + def test_get_spec_with_prefix(self): + source = self._makeOne('test_assets.py') + self.assertEqual( + source.get_spec(''), os.path.join(here, 'test_assets.py') + ) + + def test_get_spec_file_doesnt_exist(self): + source = self._makeOne('') + self.assertEqual(source.get_spec('wont_exist'), None) + class TestDirectoryOverride(unittest.TestCase): def _getTargetClass(self): @@ -1018,6 +1075,10 @@ class DummyAssetSource: def __init__(self, **kw): self.kw = kw + def get_spec(self, resource_name): + self.resource_name = resource_name + return self.kw['spec'] + def get_filename(self, resource_name): self.resource_name = resource_name return self.kw['filename'] diff --git a/tests/test_config/test_views.py b/tests/test_config/test_views.py index 2018e61f2..ce7038b5d 100644 --- a/tests/test_config/test_views.py +++ b/tests/test_config/test_views.py @@ -4065,9 +4065,12 @@ class TestStaticURLInfo(unittest.TestCase): config = testing.setUp() try: request = testing.DummyRequest() - config.add_static_view('static', 'path') + config.add_static_view( + 'static', 'tests.test_config.pkgs.cachebust:path/' + ) config.override_asset( - 'tests.test_config:path/', 'tests.test_config:other_path/' + 'tests.test_config.pkgs.cachebust:path/', + 'tests.test_config.pkgs.cachebust:override/', ) def cb(val): @@ -4077,11 +4080,21 @@ class TestStaticURLInfo(unittest.TestCase): return cb_ - config.add_cache_buster('path', cb('foo')) - result = request.static_url('path/foo.png') + config.add_cache_buster( + 'tests.test_config.pkgs.cachebust:path/', cb('foo') + ) + result = request.static_url( + 'tests.test_config.pkgs.cachebust:path/foo.png' + ) self.assertEqual(result, 'http://example.com/static/foo.png?x=foo') - config.add_cache_buster('other_path', cb('bar'), explicit=True) - result = request.static_url('path/foo.png') + config.add_cache_buster( + 'tests.test_config.pkgs.cachebust:override/', + cb('bar'), + explicit=True, + ) + result = request.static_url( + 'tests.test_config.pkgs.cachebust:path/foo.png' + ) self.assertEqual(result, 'http://example.com/static/foo.png?x=bar') finally: testing.tearDown() |
