5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
10 from logilab.common.testlib import mock_object as Mock |
|
11 from logilab.common.adbh import get_adv_func_helper |
10 from logilab.common.adbh import get_adv_func_helper |
12 |
11 |
13 from indexer import get_indexer |
12 from indexer import get_indexer |
14 |
13 |
15 from cubicweb import RequestSessionMixIn |
14 from cubicweb.req import RequestSessionBase |
16 from cubicweb.cwvreg import CubicWebVRegistry |
15 from cubicweb.cwvreg import CubicWebVRegistry |
17 from cubicweb.web.request import CubicWebRequestBase |
16 from cubicweb.web.request import CubicWebRequestBase |
18 from cubicweb.devtools import BASE_URL, BaseApptestConfiguration |
17 from cubicweb.devtools import BASE_URL, BaseApptestConfiguration |
19 |
18 |
20 |
19 |
79 """ |
78 """ |
80 pass |
79 pass |
81 |
80 |
82 def set_header(self, header, value, raw=True): |
81 def set_header(self, header, value, raw=True): |
83 """set an output HTTP header""" |
82 """set an output HTTP header""" |
84 pass |
83 self._headers[header] = value |
85 |
84 |
86 def add_header(self, header, value): |
85 def add_header(self, header, value): |
87 """set an output HTTP header""" |
86 """set an output HTTP header""" |
88 pass |
87 self._headers[header] = value # XXX |
89 |
88 |
90 def remove_header(self, header): |
89 def remove_header(self, header): |
91 """remove an output HTTP header""" |
90 """remove an output HTTP header""" |
92 pass |
91 self._headers.pop(header, None) |
93 |
92 |
94 def get_header(self, header, default=None): |
93 def get_header(self, header, default=None): |
95 """return the value associated with the given input header, |
94 """return the value associated with the given input header, |
96 raise KeyError if the header is not set |
95 raise KeyError if the header is not set |
97 """ |
96 """ |
98 return self._headers.get(header, default) |
97 return self._headers.get(header, default) |
99 |
98 |
100 def set_cookie(self, cookie, key, maxage=300): |
99 def set_cookie(self, cookie, key, maxage=300, expires=None): |
101 """set / update a cookie key |
100 """set / update a cookie key |
102 |
101 |
103 by default, cookie will be available for the next 5 minutes |
102 by default, cookie will be available for the next 5 minutes |
104 """ |
103 """ |
105 pass |
104 morsel = cookie[key] |
|
105 if maxage is not None: |
|
106 morsel['Max-Age'] = maxage |
|
107 if expires: |
|
108 morsel['expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S %z') |
|
109 # make sure cookie is set on the correct path |
|
110 morsel['path'] = self.base_url_path() |
|
111 self.add_header('Set-Cookie', morsel.OutputString()) |
|
112 self.add_header('Cookie', morsel.OutputString()) |
106 |
113 |
107 def remove_cookie(self, cookie, key): |
114 def remove_cookie(self, cookie, key): |
108 """remove a cookie by expiring it""" |
115 self.remove_header('Set-Cookie') |
109 pass |
116 self.remove_header('Cookie') |
110 |
117 |
111 def validate_cache(self): |
118 def validate_cache(self): |
112 pass |
119 pass |
113 |
120 |
114 # session compatibility (in some test are using this class to test server |
121 # session compatibility (in some test are using this class to test server |
128 eid = 0 |
135 eid = 0 |
129 def in_groups(self, groups): |
136 def in_groups(self, groups): |
130 return True |
137 return True |
131 |
138 |
132 |
139 |
133 class FakeSession(RequestSessionMixIn): |
140 class FakeSession(RequestSessionBase): |
134 def __init__(self, repo=None, user=None): |
141 def __init__(self, repo=None, user=None): |
135 self.repo = repo |
142 self.repo = repo |
136 self.vreg = getattr(self.repo, 'vreg', CubicWebVRegistry(FakeConfig(), initlog=False)) |
143 self.vreg = getattr(self.repo, 'vreg', CubicWebVRegistry(FakeConfig(), initlog=False)) |
137 self.pool = FakePool() |
144 self.pool = FakePool() |
138 self.user = user or FakeUser() |
145 self.user = user or FakeUser() |