author | David Douard <david.douard@logilab.fr> |
Fri, 03 Jul 2015 13:43:40 +0200 | |
changeset 10504 | 3755cd64fff8 |
parent 9650 | 896b63873173 |
child 10592 | dfa1dcf4d7f1 |
permissions | -rw-r--r-- |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
2 |
# copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
4 |
# |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
5 |
# This file is part of CubicWeb. |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
6 |
# |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
10 |
# any later version. |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
11 |
# |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
15 |
# details. |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
16 |
# |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
19 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
20 |
from functools import partial |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
21 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
22 |
from logilab.common.testlib import unittest_main |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
23 |
|
9650
896b63873173
[web/test] use real_error_handling context manager instead of open-coding it
Julien Cristau <julien.cristau@logilab.fr>
parents:
9649
diff
changeset
|
24 |
from cubicweb.devtools.testlib import CubicWebTC, real_error_handling |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
25 |
from cubicweb import view |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
26 |
from cubicweb.predicates import is_instance |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
27 |
|
8753
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
28 |
class IDownloadableUser(view.EntityAdapter): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
29 |
__regid__ = 'IDownloadable' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
30 |
__select__ = is_instance('CWUser') |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
31 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
32 |
def download_content_type(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
33 |
"""return MIME type of the downloadable content""" |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
34 |
return 'text/plain' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
35 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
36 |
def download_encoding(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
37 |
"""return encoding of the downloadable content""" |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
38 |
return 'ascii' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
39 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
40 |
def download_file_name(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
41 |
"""return file name of the downloadable content""" |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
42 |
return self.entity.name() + '.txt' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
43 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
44 |
def download_data(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
45 |
return 'Babar is not dead!' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
46 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
47 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
48 |
class BrokenIDownloadableGroup(IDownloadableUser): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
49 |
__regid__ = 'IDownloadable' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
50 |
__select__ = is_instance('CWGroup') |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
51 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
52 |
def download_file_name(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
53 |
return self.entity.name + '.txt' |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
54 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
55 |
def download_data(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
56 |
raise IOError() |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
57 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
58 |
class IDownloadableTC(CubicWebTC): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
59 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
60 |
def setUp(self): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
61 |
super(IDownloadableTC, self).setUp() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
62 |
self.vreg.register(IDownloadableUser) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
63 |
self.addCleanup(partial(self.vreg.unregister, IDownloadableUser)) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
64 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
65 |
def test_header_simple_case(self): |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
66 |
with self.admin_access.web_request() as req: |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
67 |
req.form['vid'] = 'download' |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
68 |
req.form['eid'] = str(req.user.eid) |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
69 |
data = self.ctrl_publish(req, 'view') |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
70 |
get = req.headers_out.getRawHeaders |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
71 |
self.assertEqual(['attachment;filename="admin.txt"'], |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
72 |
get('content-disposition')) |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
73 |
self.assertEqual(['text/plain;charset=ascii'], |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
74 |
get('content-type')) |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
75 |
self.assertEqual('Babar is not dead!', data) |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
76 |
|
8610
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
77 |
def test_header_with_space(self): |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
78 |
with self.admin_access.web_request() as req: |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
79 |
self.create_user(req, login=u'c c l a', password='babar') |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
80 |
req.cnx.commit() |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
81 |
with self.new_access(u'c c l a').web_request() as req: |
8610
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
82 |
req.form['vid'] = 'download' |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
83 |
req.form['eid'] = str(req.user.eid) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
84 |
data = self.ctrl_publish(req,'view') |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
85 |
get = req.headers_out.getRawHeaders |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
86 |
self.assertEqual(['attachment;filename="c c l a.txt"'], |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
87 |
get('content-disposition')) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
88 |
self.assertEqual(['text/plain;charset=ascii'], |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
89 |
get('content-type')) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
90 |
self.assertEqual('Babar is not dead!', data) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
91 |
|
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
92 |
def test_header_with_space_and_comma(self): |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
93 |
with self.admin_access.web_request() as req: |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
94 |
self.create_user(req, login=ur'c " l\ a', password='babar') |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
95 |
req.cnx.commit() |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
96 |
with self.new_access(ur'c " l\ a').web_request() as req: |
8610
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
97 |
req.form['vid'] = 'download' |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
98 |
req.form['eid'] = str(req.user.eid) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
99 |
data = self.ctrl_publish(req,'view') |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
100 |
get = req.headers_out.getRawHeaders |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
101 |
self.assertEqual([r'attachment;filename="c \" l\\ a.txt"'], |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
102 |
get('content-disposition')) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
103 |
self.assertEqual(['text/plain;charset=ascii'], |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
104 |
get('content-type')) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
105 |
self.assertEqual('Babar is not dead!', data) |
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
106 |
|
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
107 |
def test_header_unicode_filename(self): |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
108 |
with self.admin_access.web_request() as req: |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
109 |
self.create_user(req, login=u'cécilia', password='babar') |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
110 |
req.cnx.commit() |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
111 |
with self.new_access(u'cécilia').web_request() as req: |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
112 |
req.form['vid'] = 'download' |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
113 |
req.form['eid'] = str(req.user.eid) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
114 |
self.ctrl_publish(req,'view') |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
115 |
get = req.headers_out.getRawHeaders |
8610
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
116 |
self.assertEqual(['''attachment;filename="ccilia.txt";filename*=utf-8''c%C3%A9cilia.txt'''], |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
117 |
get('content-disposition')) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
118 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
119 |
def test_header_unicode_long_filename(self): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
120 |
name = u'Bèrte_hô_grand_nôm_ça_va_totallement_déborder_de_la_limite_là' |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
121 |
with self.admin_access.web_request() as req: |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
122 |
self.create_user(req, login=name, password='babar') |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
123 |
req.cnx.commit() |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
124 |
with self.new_access(name).web_request() as req: |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
125 |
req.form['vid'] = 'download' |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
126 |
req.form['eid'] = str(req.user.eid) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
127 |
self.ctrl_publish(req,'view') |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
128 |
get = req.headers_out.getRawHeaders |
8610
b1145ad53999
[downloadable] fix filename HTTP header for simple name with space (closes #2535715)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8600
diff
changeset
|
129 |
self.assertEqual(["""attachment;filename="Brte_h_grand_nm_a_va_totallement_dborder_de_la_limite_l.txt";filename*=utf-8''B%C3%A8rte_h%C3%B4_grand_n%C3%B4m_%C3%A7a_va_totallement_d%C3%A9border_de_la_limite_l%C3%A0.txt"""], |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
130 |
get('content-disposition')) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
131 |
|
8753
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
132 |
|
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
133 |
def test_download_data_error(self): |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
134 |
self.vreg.register(BrokenIDownloadableGroup) |
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
135 |
self.addCleanup(partial(self.vreg.unregister, BrokenIDownloadableGroup)) |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
136 |
with self.admin_access.web_request() as req: |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
137 |
req.form['vid'] = 'download' |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
138 |
req.form['eid'] = str(req.execute('CWGroup X WHERE X name "managers"')[0][0]) |
9650
896b63873173
[web/test] use real_error_handling context manager instead of open-coding it
Julien Cristau <julien.cristau@logilab.fr>
parents:
9649
diff
changeset
|
139 |
with real_error_handling(self.app): |
9649
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
140 |
data = self.app_handle_request(req) |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
141 |
get = req.headers_out.getRawHeaders |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
142 |
self.assertEqual(['text/html;charset=UTF-8'], |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
143 |
get('content-type')) |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
144 |
self.assertEqual(None, |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
145 |
get('content-disposition')) |
f89c2f127897
[web/test] port unittest_idownloadable to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8941
diff
changeset
|
146 |
self.assertEqual(req.status_out, 500) |
8753
b61a7c6352f2
[web publish] in case of error, ensure proper http status is set and Content-disposition header is reseted. Closes #2553066
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8694
diff
changeset
|
147 |
|
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
148 |
if __name__ == '__main__': |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
149 |
unittest_main() |