Mercurial > piecrust2
diff tests/test_data_assetor.py @ 329:422052d2e978
internal: Try handling URLs in a consistent way.
* Now URLs passed to, and returned from, routes will always be absolute URLs,
i.e. URLs including the site root.
* Validate the site root at config loading time to make sure it starts and ends
with a slash.
* Get rid of unused stuff.
* Add tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 31 Mar 2015 23:03:28 -0700 |
parents | eb958151c8dc |
children | e7b865f8f335 |
line wrap: on
line diff
--- a/tests/test_data_assetor.py Tue Mar 31 22:38:56 2015 -0700 +++ b/tests/test_data_assetor.py Tue Mar 31 23:03:28 2015 -0700 @@ -1,32 +1,48 @@ import pytest from mock import MagicMock -from piecrust.data.assetor import (Assetor, UnsupportedAssetsError, - build_base_url) +from piecrust.data.assetor import ( + Assetor, UnsupportedAssetsError, build_base_url) from .mockutil import mock_fs, mock_fs_scope -@pytest.mark.parametrize('fs, expected', [ - (mock_fs().withPage('pages/foo/bar'), {}), +@pytest.mark.parametrize('fs, site_root, expected', [ + (mock_fs().withPage('pages/foo/bar'), '/', {}), (mock_fs() .withPage('pages/foo/bar') .withPageAsset('pages/foo/bar', 'one.txt', 'one'), + '/', {'one': 'one'}), (mock_fs() .withPage('pages/foo/bar') .withPageAsset('pages/foo/bar', 'one.txt', 'one') .withPageAsset('pages/foo/bar', 'two.txt', 'two'), + '/', + {'one': 'one', 'two': 'two'}), + + (mock_fs().withPage('pages/foo/bar'), '/whatever', {}), + (mock_fs() + .withPage('pages/foo/bar') + .withPageAsset('pages/foo/bar', 'one.txt', 'one'), + '/whatever', + {'one': 'one'}), + (mock_fs() + .withPage('pages/foo/bar') + .withPageAsset('pages/foo/bar', 'one.txt', 'one') + .withPageAsset('pages/foo/bar', 'two.txt', 'two'), + '/whatever', {'one': 'one', 'two': 'two'}) ]) -def test_assets(fs, expected): +def test_assets(fs, site_root, expected): + fs.withConfig({'site': {'root': site_root}}) with mock_fs_scope(fs): page = MagicMock() page.app = fs.getApp(cache=False) page.app.env.base_asset_url_format = '%uri%' page.path = fs.path('/kitchen/pages/foo/bar.md') - assetor = Assetor(page, '/foo/bar') + assetor = Assetor(page, site_root.rstrip('/') + '/foo/bar') for en in expected.keys(): assert hasattr(assetor, en) - path = '/foo/bar/%s.txt' % en + path = site_root.rstrip('/') + '/foo/bar/%s.txt' % en assert getattr(assetor, en) == path assert assetor[en] == path