221 additionel credential might be required""" |
221 additionel credential might be required""" |
222 cnxprops = ConnectionProperties('inmemory') |
222 cnxprops = ConnectionProperties('inmemory') |
223 return repo_connect(repo, login, cnxprops=cnxprops, **kwargs) |
223 return repo_connect(repo, login, cnxprops=cnxprops, **kwargs) |
224 |
224 |
225 def in_memory_repo_cnx(config, login, **kwargs): |
225 def in_memory_repo_cnx(config, login, **kwargs): |
226 """usefull method for testing and scripting to get a dbapi.Connection |
226 """useful method for testing and scripting to get a dbapi.Connection |
227 object connected to an in-memory repository instance |
227 object connected to an in-memory repository instance |
228 """ |
228 """ |
229 # connection to the CubicWeb repository |
229 # connection to the CubicWeb repository |
230 repo = in_memory_repo(config) |
230 repo = in_memory_repo(config) |
231 return repo, in_memory_cnx(repo, login, **kwargs) |
231 return repo, in_memory_cnx(repo, login, **kwargs) |
|
232 |
|
233 |
|
234 def anonymous_session(vreg): |
|
235 """return a new anonymous session |
|
236 |
|
237 raises an AuthenticationError if anonymous usage is not allowed |
|
238 """ |
|
239 anoninfo = vreg.config.anonymous_user() |
|
240 if anoninfo is None: # no anonymous user |
|
241 raise AuthenticationError('anonymous access is not authorized') |
|
242 anon_login, anon_password = anoninfo |
|
243 cnxprops = ConnectionProperties(vreg.config.repo_method) |
|
244 # use vreg's repository cache |
|
245 repo = vreg.config.repository(vreg) |
|
246 anon_cnx = repo_connect(repo, anon_login, |
|
247 cnxprops=cnxprops, password=anon_password) |
|
248 anon_cnx.vreg = vreg |
|
249 return DBAPISession(anon_cnx, anon_login) |
|
250 |
232 |
251 |
233 class _NeedAuthAccessMock(object): |
252 class _NeedAuthAccessMock(object): |
234 def __getattribute__(self, attr): |
253 def __getattribute__(self, attr): |
235 raise AuthenticationError() |
254 raise AuthenticationError() |
236 def __nonzero__(self): |
255 def __nonzero__(self): |