equal
deleted
inserted
replaced
12 from logilab.common.pytest import pause_tracing, resume_tracing |
12 from logilab.common.pytest import pause_tracing, resume_tracing |
13 |
13 |
14 import yams.schema |
14 import yams.schema |
15 |
15 |
16 from cubicweb.dbapi import repo_connect, ConnectionProperties, ProgrammingError |
16 from cubicweb.dbapi import repo_connect, ConnectionProperties, ProgrammingError |
17 from cubicweb.cwvreg import CubicWebRegistry |
17 from cubicweb.cwvreg import CubicWebVRegistry |
18 |
18 |
19 from cubicweb.web.application import CubicWebPublisher |
19 from cubicweb.web.application import CubicWebPublisher |
20 from cubicweb.web import Redirect |
20 from cubicweb.web import Redirect |
21 |
21 |
22 from cubicweb.devtools import ApptestConfiguration, init_test_database |
22 from cubicweb.devtools import ApptestConfiguration, init_test_database |
77 self.cnx = None |
77 self.cnx = None |
78 config.db_perms = False |
78 config.db_perms = False |
79 source = config.sources()['system'] |
79 source = config.sources()['system'] |
80 if verbose: |
80 if verbose: |
81 print "init test database ..." |
81 print "init test database ..." |
82 self.vreg = vreg = CubicWebRegistry(config) |
82 self.vreg = vreg = CubicWebVRegistry(config) |
83 self.admlogin = source['db-user'] |
83 self.admlogin = source['db-user'] |
84 # restore database <=> init database |
84 # restore database <=> init database |
85 self.restore_database() |
85 self.restore_database() |
86 if verbose: |
86 if verbose: |
87 print "init done" |
87 print "init done" |
189 assert template |
189 assert template |
190 if optional_args is None: |
190 if optional_args is None: |
191 optional_args = {} |
191 optional_args = {} |
192 optional_args['vid'] = vid |
192 optional_args['vid'] = vid |
193 req = self.create_request(rql=rql, **optional_args) |
193 req = self.create_request(rql=rql, **optional_args) |
194 return self.vreg.main_template(req, template) |
194 return self.vreg['views'].main_template(req, template) |
195 |
195 |
196 def call_edit(self, req): |
196 def call_edit(self, req): |
197 """shortcut for self.app.edit()""" |
197 """shortcut for self.app.edit()""" |
198 controller = self.vreg.select('controllers', 'edit', req) |
198 controller = self.vreg.select('controllers', 'edit', req) |
199 try: |
199 try: |
205 req.cnx.commit() |
205 req.cnx.commit() |
206 return result |
206 return result |
207 |
207 |
208 def iter_possible_views(self, req, rset): |
208 def iter_possible_views(self, req, rset): |
209 """returns a list of possible vids for <rql>""" |
209 """returns a list of possible vids for <rql>""" |
210 for view in self.vreg.possible_views(req, rset): |
210 for view in self.vreg['views'].possible_views(req, rset): |
211 if view.category == 'startupview': |
211 if view.category == 'startupview': |
212 continue |
212 continue |
213 yield view.id |
213 yield view.id |
214 if rset.rowcount == 1: |
214 if rset.rowcount == 1: |
215 yield 'edition' |
215 yield 'edition' |
216 |
216 |
217 def iter_startup_views(self, req): |
217 def iter_startup_views(self, req): |
218 """returns the list of startup views""" |
218 """returns the list of startup views""" |
219 for view in self.vreg.possible_views(req, None): |
219 for view in self.vreg['views'].possible_views(req, None): |
220 if view.category != 'startupview': |
220 if view.category != 'startupview': |
221 continue |
221 continue |
222 yield view.id |
222 yield view.id |
223 |
223 |
224 def iter_possible_actions(self, req, rset): |
224 def iter_possible_actions(self, req, rset): |
231 def __init__(self, appid, sourcefile, verbose=False): |
231 def __init__(self, appid, sourcefile, verbose=False): |
232 config = ApptestConfiguration(appid, sourcefile=sourcefile) |
232 config = ApptestConfiguration(appid, sourcefile=sourcefile) |
233 if verbose: |
233 if verbose: |
234 print "init test database ..." |
234 print "init test database ..." |
235 source = config.sources()['system'] |
235 source = config.sources()['system'] |
236 self.vreg = CubicWebRegistry(config) |
236 self.vreg = CubicWebVRegistry(config) |
237 self.cnx = init_test_database(driver=source['db-driver'], |
237 self.cnx = init_test_database(driver=source['db-driver'], |
238 vreg=self.vreg)[1] |
238 vreg=self.vreg)[1] |
239 if verbose: |
239 if verbose: |
240 print "init done" |
240 print "init done" |
241 self.app = CubicWebPublisher(config, vreg=self.vreg) |
241 self.app = CubicWebPublisher(config, vreg=self.vreg) |