author | Denis Laxalde <denis.laxalde@logilab.fr> |
Tue, 14 Jan 2014 14:02:51 +0100 | |
changeset 9406 | 38debfa8b536 |
parent 8941 | 7b26fe71404f |
child 9649 | f89c2f127897 |
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 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
24 |
from cubicweb.devtools.testlib import CubicWebTC |
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): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
66 |
req = self.request() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
67 |
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
|
68 |
req.form['eid'] = str(req.user.eid) |
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
|
69 |
data = self.ctrl_publish(req, 'view') |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
70 |
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
|
71 |
self.assertEqual(['attachment;filename="admin.txt"'], |
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
72 |
get('content-disposition')) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
73 |
self.assertEqual(['text/plain;charset=ascii'], |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
74 |
get('content-type')) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
75 |
self.assertEqual('Babar is not dead!', data) |
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): |
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
|
78 |
req = self.request() |
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
|
79 |
self.create_user(req, login=u'c c l a', password='babar') |
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
|
80 |
self.commit() |
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
|
81 |
with self.login(u'c c l a', password='babar'): |
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 = self.request() |
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['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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
|
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
|
93 |
def test_header_with_space_and_comma(self): |
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
|
94 |
req = self.request() |
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
|
95 |
self.create_user(req, login=ur'c " l\ a', password='babar') |
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
|
96 |
self.commit() |
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 |
with self.login(ur'c " l\ a', password='babar'): |
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 = self.request() |
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 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
|
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
109 |
def test_header_unicode_filename(self): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
110 |
req = self.request() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
111 |
self.create_user(req, login=u'cécilia', password='babar') |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
112 |
self.commit() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
113 |
with self.login(u'cécilia', password='babar'): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
114 |
req = self.request() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
get('content-disposition')) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
121 |
|
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
122 |
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
|
123 |
req = self.request() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
124 |
name = u'Bèrte_hô_grand_nôm_ça_va_totallement_déborder_de_la_limite_là' |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
125 |
self.create_user(req, login=name, password='babar') |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
126 |
self.commit() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
127 |
with self.login(name, password='babar'): |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
128 |
req = self.request() |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
get('content-disposition')) |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
135 |
|
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
|
136 |
|
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
|
137 |
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
|
138 |
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
|
139 |
self.addCleanup(partial(self.vreg.unregister, 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
|
140 |
req = self.request() |
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
|
141 |
req.form['vid'] = 'download' |
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
|
142 |
req.form['eid'] = str(req.execute('CWGroup X WHERE X name "managers"')[0][0]) |
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
|
143 |
errhdlr = self.app.__dict__.pop('error_handler') # temporarily restore error handler |
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
|
144 |
try: |
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
|
145 |
data = self.app_handle_request(req) |
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
|
146 |
finally: |
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 |
self.app.error_handler = errhdlr |
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
|
148 |
get = req.headers_out.getRawHeaders |
8941
7b26fe71404f
drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8753
diff
changeset
|
149 |
self.assertEqual(['text/html;charset=UTF-8'], |
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
|
150 |
get('content-type')) |
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
|
151 |
self.assertEqual(None, |
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
|
152 |
get('content-disposition')) |
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
|
153 |
self.assertEqual(req.status_out, 500) |
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
|
154 |
|
8600
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
155 |
if __name__ == '__main__': |
d74addac92bb
[downloadable] fix filename in HTTP header (closes #2522325, #2522324)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
156 |
unittest_main() |