equal
deleted
inserted
replaced
1 """provide utilies for web (live) unit testing""" |
1 """provide utilies for web (live) unit testing |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 """ |
2 |
7 |
3 import socket |
8 import socket |
4 import logging |
9 import logging |
5 from os.path import join, dirname, exists |
10 from os.path import join, dirname, exists |
6 from StringIO import StringIO |
11 from StringIO import StringIO |
39 datadir = self.config.locate_resource(segments[1]) |
44 datadir = self.config.locate_resource(segments[1]) |
40 if datadir: |
45 if datadir: |
41 return static.File(str(datadir), segments[1:]) |
46 return static.File(str(datadir), segments[1:]) |
42 # Otherwise we use this single resource |
47 # Otherwise we use this single resource |
43 return self, () |
48 return self, () |
44 |
49 |
45 |
50 |
46 |
51 |
47 def make_site(cube, options=None): |
52 def make_site(cube, options=None): |
48 from cubicweb.etwist import twconfig # trigger configuration registration |
53 from cubicweb.etwist import twconfig # trigger configuration registration |
49 sourcefile = options.sourcefile |
54 sourcefile = options.sourcefile |
50 config = LivetestConfiguration(cube, sourcefile, |
55 config = LivetestConfiguration(cube, sourcefile, |
51 pyro_name=options.pyro_name, |
56 pyro_name=options.pyro_name, |
73 reactor.run() |
78 reactor.run() |
74 |
79 |
75 def saveconf(templhome, port, user, passwd): |
80 def saveconf(templhome, port, user, passwd): |
76 import pickle |
81 import pickle |
77 conffile = file(join(templhome, 'test', 'livetest.conf'), 'w') |
82 conffile = file(join(templhome, 'test', 'livetest.conf'), 'w') |
78 |
83 |
79 pickle.dump((port, user, passwd, get_starturl(port, user, passwd)), |
84 pickle.dump((port, user, passwd, get_starturl(port, user, passwd)), |
80 conffile) |
85 conffile) |
81 conffile.close() |
86 conffile.close() |
82 |
87 |
83 |
88 |
97 def hijack_twill_output(new_output): |
102 def hijack_twill_output(new_output): |
98 from twill import commands as twc |
103 from twill import commands as twc |
99 from twill import browser as twb |
104 from twill import browser as twb |
100 twc.OUT = new_output |
105 twc.OUT = new_output |
101 twb.OUT = new_output |
106 twb.OUT = new_output |
102 |
107 |
103 |
108 |
104 class LiveTestCase(TestCase): |
109 class LiveTestCase(TestCase): |
105 |
110 |
106 sourcefile = None |
111 sourcefile = None |
107 cube = '' |
112 cube = '' |
108 def setUp(self): |
113 def setUp(self): |
116 self.repo, self.cnx = in_memory_cnx(self.config, user, passwd) |
121 self.repo, self.cnx = in_memory_cnx(self.config, user, passwd) |
117 self.setup_db(self.cnx) |
122 self.setup_db(self.cnx) |
118 |
123 |
119 def tearDown(self): |
124 def tearDown(self): |
120 self.teardown_db(self.cnx) |
125 self.teardown_db(self.cnx) |
121 |
126 |
122 |
127 |
123 def setup_db(self, cnx): |
128 def setup_db(self, cnx): |
124 """override setup_db() to setup your environment""" |
129 """override setup_db() to setup your environment""" |
125 |
130 |
126 def teardown_db(self, cnx): |
131 def teardown_db(self, cnx): |
139 execute_scenario = staticmethod(execute_scenario) |
144 execute_scenario = staticmethod(execute_scenario) |
140 |
145 |
141 |
146 |
142 if __name__ == '__main__': |
147 if __name__ == '__main__': |
143 runserver() |
148 runserver() |
144 |
|
145 |
|