root/mail-onna-stick/trunk/lib/mosweb/test_pages.py

Revision 315, 4.4 kB (checked in by grig, 11 years ago)

Fairly massive refactoring. Merged db.init with db.conn and called the resulting function db.conn. It's more forgiving now -- if you call it a second time, it returns the existing connection.

It's great that we have both backend unit tests and twill tests. All unit tests were happy, but the twill tests were failing miserably. The reason? All the files in lib/mosweb were still calling db.init....

All tests pass at this time. It felt really good to watch the Selenium tests pass. It reinforced the conclusion that we really *need* all types of automated tests, GUI included.

Now on to mocking the Durus interface.....

Line 
1 """
2 Support for various testing stuff.
3 """
4
5 import os
6 from twill import commands
7
8 import mos
9 import templates
10 import mostest
11
12 billboard_server = 'http://issola.caltech.edu/~t/test-cgi/submit_event.cgi'
13
14 def write_selenium_html(key, value):
15     thisdir = os.path.dirname(__file__)
16     logdir = os.path.join(thisdir, '../../var/Selenium')
17     logdir = os.path.realpath(logdir)
18
19     try:
20         os.mkdir(logdir)
21     except OSError:
22         pass
23
24     filename = key + '.html'
25     filename = os.path.join(logdir, filename)
26
27     try:
28         o = open(filename, 'w')
29         o.write(value)
30         o.close()
31     except IOError:
32         pass
33
34 class TestPages:
35     exposed = True
36     event_id = None
37
38     def index(self):
39         return templates.wrap_page("""\
40 <h2>Testing miscellany</h2>
41 <p>
42 <a href="./report_coverage">coverage report</a><p>
43 <a href="/static/selenium/TestRunner.html?test=./tests/MOSTestSuite.html">Selenium tests</a> <a href="/static/selenium/TestRunner.html?test=./tests/MOSTestSuite.html&auto=true&resultsUrl=/tests/post_selenium_results">(run automatically and post results)</a><p>
44 <a href="/twill/">twill scripts</a>
45 <hr>
46 <a href="./reset">reset database</a><p>
47 <a href="./post_event?event=hello&publisher=test_pages">post event</a><p>
48 coverage recording <a href="./set_coverage?on=1">on</a> / <a href="./set_coverage?on=0">off</a>
49 <hr>
50 <a href="http://vallista.idyll.org:8010/">buildbot page</a>
51 """)
52     index.exposed = True
53        
54     def reset(self):
55         mos.db.erase()
56         mos.db.conn(should_exist=False)
57
58         return "reset"
59     reset.exposed = True
60
61     def post_event(self, publisher, event, text_data='', new_event=False):
62         from billboard import client
63         server = billboard_server
64
65         if new_event or self.event_id is None:
66             eid = client.post_new_event(server, publisher, event, text_data)
67             self.event_id = eid
68         else:
69             eid = client.post_event(server, self.event_id, publisher, event,
70                                     text_data)
71
72     post_event.exposed = True
73
74     def post_coverage(self, publisher, event, new_event=False):
75         from billboard.objects import BillboardInfoContainer
76         from billboard.objects.coverage_info import CoverageInfo
77         import billboard.client
78
79         server = billboard_server
80
81         cont = BillboardInfoContainer(publisher, event)
82         files = mostest._get_package_files()
83         c = CoverageInfo(files)
84         cont.add_info(c)
85
86         event_id = None
87         if not new_event:
88             event_id = self.event_id
89
90         eid = billboard.client.post_info(server, cont, event_id)
91
92         if new_event:
93             self.event_id = eid
94     post_coverage.exposed = True
95
96     def report_coverage(self):
97         import mostest
98         return "<pre>%s</pre>" % (mostest.report(),)
99     report_coverage.exposed = True
100
101     def post_selenium_results(self, exit=True, **kw):
102         from billboard.objects import BillboardInfoContainer
103         from billboard.objects.coverage_info import CoverageInfo
104         from billboard.objects.selenium_info import SeleniumInfo
105         import billboard.client
106
107         server = billboard_server
108
109         cont = BillboardInfoContainer('selenium_tests', 'summary')
110
111         # add coverage info, if it's been on from the start.
112         if mostest.coverage_on_start:
113             files = mostest._get_package_files()
114             c = CoverageInfo(files)
115             cont.add_info(c)
116
117         # add selenium info
118         selenium = SeleniumInfo(**kw)
119         cont.add_info(selenium)
120        
121         eid = billboard.client.post_info(server, cont)
122
123         if exit:
124             print 'SELENIUM RESULTS:'
125             print '****'
126             for k, v in kw.items():
127                 if k == 'suite' or k.startswith('testTable'):
128                     write_selenium_html(k, v)
129                 if len(v) > 20:
130                     v = v[:17] + '...'
131                 print k, v
132
133             print '****'
134
135             if kw['result'] != 'passed':
136                 print 'DID NOT PASS; failure exit'
137                 import cherrypy
138                 cherrypy.server.stop()
139                 cherrypy.server.interrupt = Exception("selenium test failure")
140             else:
141                 raise SystemExit
142            
143     post_selenium_results.exposed = True
144
145 #    def set_coverage(self, on=1):
146 #        coverage.use_cache(False)
147 #       
148 #        if on:
149 #            coverage.start()
150 #        else:
151 #            coverage.stop()
152 #        return "%s" % (on,)
153 #    set_coverage.exposed = True
154
Note: See TracBrowser for help on using the browser.