904 |
904 |
assert '>CGU<' in resp.text
|
905 |
905 |
|
906 |
906 |
|
|
907 |
def test_serve_asset(settings, app, admin_user):
|
|
908 |
settings.COMBO_ASSET_SLOTS = {'collectivity:banner': {'label': 'Banner'}}
|
|
909 |
app = login(app)
|
|
910 |
|
|
911 |
resp = app.get('/manage/assets/')
|
|
912 |
assert '>Banner<' in resp.text
|
|
913 |
assert '>Delete<' not in resp.text
|
|
914 |
resp = resp.click('Overwrite')
|
|
915 |
resp.form['upload'] = Upload(
|
|
916 |
'test.png',
|
|
917 |
base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAgAABAADRWoApgAA\nAABJRU5ErkJggg=='),
|
|
918 |
'image/png')
|
|
919 |
resp = resp.form.submit().follow()
|
|
920 |
assert Asset.objects.filter(key='collectivity:banner').count() == 1
|
|
921 |
asset = Asset.objects.latest('pk')
|
|
922 |
|
|
923 |
assert app.get('/assets/collectivity:banner', status=302)['location'].endswith('test.png')
|
|
924 |
assert app.get('/assets/collectivity:banner?width=200', status=302)['location'].startswith('/media/cache/')
|
|
925 |
assert app.get('/assets/collectivity:banner?height=200', status=302)['location'].startswith('/media/cache/')
|
|
926 |
assert app.get('/assets/collectivity:banner?crop=center', status=302)['location'].endswith('test.png')
|
|
927 |
assert app.get('/assets/collectivity:banner?width=200&crop=center', status=302)['location'].startswith('/media/cache/')
|
|
928 |
|
|
929 |
# file is missing
|
|
930 |
os.remove(asset.asset.path)
|
|
931 |
app.get('/assets/collectivity:banner', status=404)
|
|
932 |
|
|
933 |
# upload a SVG
|
|
934 |
resp = resp.click('Delete')
|
|
935 |
resp = resp.form.submit()
|
|
936 |
assert Asset.objects.filter(key='collectivity:banner').count() == 0
|
|
937 |
|
|
938 |
resp = app.get('/manage/assets/')
|
|
939 |
assert '>Banner<' in resp.text
|
|
940 |
assert '>Delete<' not in resp.text
|
|
941 |
resp = resp.click('Overwrite')
|
|
942 |
resp.form['upload'] = Upload(
|
|
943 |
'test.svg',
|
|
944 |
base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAgAABAADRWoApgAA\nAABJRU5ErkJggg=='),
|
|
945 |
'image/svg+xml')
|
|
946 |
resp = resp.form.submit()
|
|
947 |
assert Asset.objects.filter(key='collectivity:banner').count() == 1
|
|
948 |
|
|
949 |
# SVG: no thumbnail !
|
|
950 |
assert app.get('/assets/collectivity:banner', status=302)['location'].endswith('test.svg')
|
|
951 |
assert app.get('/assets/collectivity:banner?width=200', status=302)['location'].endswith('test.svg')
|
|
952 |
assert app.get('/assets/collectivity:banner?height=200', status=302)['location'].endswith('test.svg')
|
|
953 |
assert app.get('/assets/collectivity:banner?crop=center', status=302)['location'].endswith('test.svg')
|
|
954 |
assert app.get('/assets/collectivity:banner?width=200&crop=center', status=302)['location'].endswith('test.svg')
|
|
955 |
|
|
956 |
# unknown Asset key
|
|
957 |
app.get('/assets/foo:bar', status=404)
|
|
958 |
|
|
959 |
|
907 |
960 |
def test_asset_export_import(app, admin_user):
|
908 |
961 |
for path in ('uploads', 'assets', 'cache'):
|
909 |
962 |
if os.path.exists(default_storage.path(path)):
|
910 |
|
-
|