summaryrefslogtreecommitdiffstats
path: root/tests/test_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_manager.py')
-rw-r--r--tests/test_manager.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 3cb0ecd..da14d57 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -960,6 +960,59 @@ def test_asset_slots_management(app, admin_user):
assert '>CGU<' in resp.text
+def test_serve_asset(settings, app, admin_user):
+ settings.COMBO_ASSET_SLOTS = {'collectivity:banner': {'label': 'Banner'}}
+ app = login(app)
+
+ resp = app.get('/manage/assets/')
+ assert '>Banner<' in resp.text
+ assert '>Delete<' not in resp.text
+ resp = resp.click('Overwrite')
+ resp.form['upload'] = Upload(
+ 'test.png',
+ base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAgAABAADRWoApgAA\nAABJRU5ErkJggg=='),
+ 'image/png')
+ resp = resp.form.submit().follow()
+ assert Asset.objects.filter(key='collectivity:banner').count() == 1
+ asset = Asset.objects.latest('pk')
+
+ assert app.get('/assets/collectivity:banner', status=302)['location'].endswith('test.png')
+ assert app.get('/assets/collectivity:banner?width=200', status=302)['location'].startswith('/media/cache/')
+ assert app.get('/assets/collectivity:banner?height=200', status=302)['location'].startswith('/media/cache/')
+ assert app.get('/assets/collectivity:banner?crop=center', status=302)['location'].endswith('test.png')
+ assert app.get('/assets/collectivity:banner?width=200&crop=center', status=302)['location'].startswith('/media/cache/')
+
+ # file is missing
+ os.remove(asset.asset.path)
+ app.get('/assets/collectivity:banner', status=404)
+
+ # upload a SVG
+ resp = resp.click('Delete')
+ resp = resp.form.submit()
+ assert Asset.objects.filter(key='collectivity:banner').count() == 0
+
+ resp = app.get('/manage/assets/')
+ assert '>Banner<' in resp.text
+ assert '>Delete<' not in resp.text
+ resp = resp.click('Overwrite')
+ resp.form['upload'] = Upload(
+ 'test.svg',
+ base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAgAABAADRWoApgAA\nAABJRU5ErkJggg=='),
+ 'image/svg+xml')
+ resp = resp.form.submit()
+ assert Asset.objects.filter(key='collectivity:banner').count() == 1
+
+ # SVG: no thumbnail !
+ assert app.get('/assets/collectivity:banner', status=302)['location'].endswith('test.svg')
+ assert app.get('/assets/collectivity:banner?width=200', status=302)['location'].endswith('test.svg')
+ assert app.get('/assets/collectivity:banner?height=200', status=302)['location'].endswith('test.svg')
+ assert app.get('/assets/collectivity:banner?crop=center', status=302)['location'].endswith('test.svg')
+ assert app.get('/assets/collectivity:banner?width=200&crop=center', status=302)['location'].endswith('test.svg')
+
+ # unknown Asset key
+ app.get('/assets/foo:bar', status=404)
+
+
def test_asset_export_import(app, admin_user):
for path in ('uploads', 'assets', 'cache'):
if os.path.exists(default_storage.path(path)):