root/mail-onna-stick/trunk/tests/twill-tests/test-via-wsgi.py

Revision 315, 4.5 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 Test the loading of mail sources.
3 """
4
5 import os, time, sys, re
6 from cStringIO import StringIO
7
8 import twill
9 from twill import commands, wsgi_intercept, add_wsgi_intercept, \
10      remove_wsgi_intercept
11
12 import twilltestlib
13 twilltestlib.add_lib_dirs()
14
15 import mos
16 from mos import index, config, mbox
17 import mostest
18
19 import mosweb
20 import twill_extensions
21
22 ###
23
24 log = mos.config.get_log()
25
26 setup_succeeded = False
27 def setup_module():
28     """
29     setup: change into the test directory.
30     """
31     global setup_succeeded
32     setup_succeeded = False
33
34     twilltestlib.cd_testdir()
35     mos.config.debug_on()
36
37     twill.commands.config('use_tidy', 0)
38
39     log('TEST setup_module: running')
40
41     wsgi_intercept.debuglevel = 0
42
43     mosweb.setup()
44
45     _cache = {}
46     def get_app(_cache=_cache):
47         if not _cache:
48             import cherrypy
49            
50             cherrypy.config.update({ 'server.logToScreen' : False })
51             cherrypy.server.start(initOnly=True, serverClass=None)
52
53             app = mosweb.get_wsgi_app()
54             _cache['app'] = app
55         return _cache['app']
56
57     add_wsgi_intercept('localhost', 8080, get_app)
58
59     log('TEST teardown_module: finished')
60
61     twill.set_output(StringIO())
62
63     if not mostest.DEBUG_AVOID_SLOW:
64         commands.go('http://localhost:8080/tests/reset')
65         commands.code('200')
66
67         twill.execute_file('../../lib/mosweb/static/twill/load-test-mboxes',
68                            initial_url='http://localhost:8080/')
69
70     twill.set_output(None)
71
72     setup_succeeded = True
73    
74 def teardown_module():
75     """
76     teardown: change back out of the test directory.
77     """
78     log('TEST tearDown: starting')
79
80     remove_wsgi_intercept('localhost', 8080)
81     mosweb.cleanup()
82
83     log('TEST tearDown: finished')
84
85     if not setup_succeeded:
86         print 'SETUP FAILED; log file sez:'
87         print open(mos.config.get('logfile')).read()
88    
89     twilltestlib.pop_testdir()
90     mos.config.debug_off()
91
92 class WSGI_Tests:
93     """
94     All the actual tests.
95     """
96    
97     def test_ok(self):
98         "Can we connect to the server?"
99        
100         log('TEST: test_ok starting')
101         twill.execute_file('scripts/test-ok.twill',
102                            initial_url='http://localhost:8080/')
103        
104     def test_load_already_exists(self):
105         "Does loading all of the test mailboxes twice cause an error?"
106        
107         log('TEST: test_load_already_exists starting')
108        
109         if not mostest.DEBUG_AVOID_SLOW:
110             twill.execute_file('../../lib/mosweb/static/twill/load-test-mboxes',
111                                initial_url='http://localhost:8080/')
112
113     def test_message_browse(self):
114         "Can we browse through all the messages in a particular mailbox?"
115         log('TEST: test_message_browse starting')
116        
117         if not mostest.DEBUG_AVOID_SLOW:
118             twill.execute_file('scripts/test-browsing-messages.twill',
119                                initial_url='http://localhost:8080/')
120
121     def test_search(self):
122         "Test basic search capability."
123         log('TEST: test_search starting')
124
125         if not mostest.DEBUG_AVOID_SLOW:
126             twill.execute_file('scripts/test-search.twill',
127                                initial_url='http://localhost:8080/')
128
129     def test_comments(self):
130         "Test basic commenting capability."
131         log('TEST: test_comments starting')
132
133         if not mostest.DEBUG_AVOID_SLOW:
134             twill.execute_file('scripts/test-comments.twill',
135                                initial_url='http://localhost:8080/')
136
137     def test_twill_runscript_stuff(self):
138         "Test the ability to run twill scripts from with MOS."
139         log('TEST: test_twill_runscript starting')
140
141         commands.go('http://localhost:8080/twill/')
142         commands.code('200')
143
144         from mosweb.twillscripts import TwillTop
145         t = TwillTop()
146
147         print t.runscript('test')
148
149         result = t.runscript('../../else/where')
150         assert result.find('cannot run this') != -1
151
152     def test_the_tests_page(self):
153         "Run through the tests page stuff."
154         log('TEST: test_the_tests_page starting')
155
156         if not mostest.DEBUG_AVOID_SLOW:
157             twill.execute_file('scripts/test-the-tests-page.twill',
158                                initial_url='http://localhost:8080/')
159
160     def test_configure_pages(self):
161         "Run through the configure pages stuff."
162         log('TEST: test_configure_pages')
163
164         twill.execute_file('scripts/test-configure.twill',
165                            initial_url='http://localhost:8080/')
Note: See TracBrowser for help on using the browser.