~ubuntu-branches/ubuntu/jaunty/trac/jaunty

« back to all changes in this revision

Viewing changes to trac/tests/functional/testcases.py

  • Committer: Bazaar Package Importer
  • Author(s): Luis Matos
  • Date: 2008-07-13 23:46:20 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080713234620-13ynpdpkbaymfg1z
Tags: 0.11-2
* Re-added python-setup-tools to build dependences. Closes: #490320 #468705
* New upstream release Closes: 489727
* Added sugestion for other vcs support available: git bazaar mercurial 
* Added spamfilter plugin to sugests
* Moved packaging from python-support to python-central
* Added an entry to the NEWS about the cgi Closes: #490275
* Updated 10_remove_trac_suffix_from_title patch to be used in 0.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import os
 
3
from subprocess import call
 
4
from tempfile import mkdtemp
 
5
from trac.tests.functional import *
 
6
from trac.util.datefmt import format_date, utc
 
7
 
 
8
 
 
9
class TestEmptyRepo(FunctionalTwillTestCaseSetup):
 
10
    def runTest(self):
 
11
        """Check empty repository"""
 
12
        browser_url = self._tester.url + '/browser'
 
13
        tc.go(browser_url)
 
14
        tc.url(browser_url)
 
15
        # This tests the current behavior; I'm not sure it's the best
 
16
        # behavior.
 
17
        tc.follow('Last Change')
 
18
        tc.find('Error: No such changeset')
 
19
        tc.back()
 
20
        tc.follow('Revision Log')
 
21
        tc.notfind('Error: Nonexistent path')
 
22
 
 
23
 
 
24
class TestRepoCreation(FunctionalTwillTestCaseSetup):
 
25
    def runTest(self):
 
26
        """Create a directory tree in the repository"""
 
27
        # This should probably use the svn bindings...
 
28
        directories = []
 
29
        for component in ('component1', 'component2'):
 
30
            directories.append(component)
 
31
            for subdir in ('branches', 'tags', 'trunk'):
 
32
                directories.append('/'.join([component, subdir]))
 
33
        commit_message = 'Create component trees.'
 
34
        self._tester.svn_mkdir(directories, commit_message)
 
35
 
 
36
        browser_url = self._tester.url + '/browser'
 
37
        tc.go(browser_url)
 
38
        tc.url(browser_url)
 
39
        tc.find('component1')
 
40
        tc.find('component2')
 
41
        tc.follow('Last Change')
 
42
        tc.url(self._tester.url + '/changeset/1/')
 
43
        tc.find(commit_message)
 
44
        for directory in directories:
 
45
            tc.find(directory)
 
46
        tc.back()
 
47
        tc.follow('Revision Log')
 
48
        # (Note that our commit log message is short enough to avoid
 
49
        # truncation.)
 
50
        tc.find(commit_message)
 
51
        tc.follow('Timeline')
 
52
        # (Note that our commit log message is short enough to avoid
 
53
        # truncation.)
 
54
        tc.find(commit_message)
 
55
        tc.formvalue('prefs', 'ticket', False)
 
56
        tc.formvalue('prefs', 'milestone', False)
 
57
        tc.formvalue('prefs', 'wiki', False)
 
58
        tc.submit()
 
59
        tc.find('by.*admin')
 
60
        # (Note that our commit log message is short enough to avoid
 
61
        # truncation.)
 
62
        tc.find(commit_message)
 
63
 
 
64
 
 
65
class RegressionTestRev6017(FunctionalTwillTestCaseSetup):
 
66
    def runTest(self):
 
67
        """Test for regression of the plugin reload fix in r6017"""
 
68
        # Setup the DeleteTicket plugin
 
69
        plugin = open(os.path.join(self._testenv.command_cwd, 'sample-plugins',
 
70
            'workflow', 'DeleteTicket.py')).read()
 
71
        open(os.path.join(self._testenv.tracdir, 'plugins', 'DeleteTicket.py'),
 
72
             'w').write(plugin)
 
73
        env = self._testenv.get_trac_environment()
 
74
        prevconfig = env.config.get('ticket', 'workflow')
 
75
        env.config.set('ticket', 'workflow',
 
76
                       prevconfig + ',DeleteTicketActionController')
 
77
        env.config.save()
 
78
        env = self._testenv.get_trac_environment() # reloads the environment
 
79
 
 
80
        loaded_components = env.compmgr.__metaclass__._components
 
81
        delete_plugins = [c for c in loaded_components
 
82
                          if 'DeleteTicketActionController' in c.__name__]
 
83
        try:
 
84
            self.assertEqual(len(delete_plugins), 1,
 
85
                             "Plugin loaded more than once.")
 
86
 
 
87
        finally:
 
88
            # Remove the DeleteTicket plugin
 
89
            env.config.set('ticket', 'workflow', prevconfig)
 
90
            env.config.save()
 
91
            self._testenv.restart()
 
92
            for ext in ('py', 'pyc', 'pyo'):
 
93
                filename = os.path.join(self._testenv.tracdir, 'plugins',
 
94
                                        'DeleteTicket.%s' % ext)
 
95
                if os.path.exists(filename):
 
96
                    os.unlink(filename)
 
97
 
 
98
 
 
99
class RegressionTestTicket3833a(FunctionalTestCaseSetup):
 
100
    def runTest(self):
 
101
        """Test for regression of http://trac.edgewall.org/ticket/3833 a"""
 
102
        # Assume the logging is already set to debug.
 
103
        traclogfile = open(os.path.join(self._testenv.tracdir, 'log',
 
104
                                        'trac.log'))
 
105
        # Seek to the end of file so we only look at new log output
 
106
        traclogfile.seek(0, 2)
 
107
        # Verify that logging is on initially
 
108
        env = self._testenv.get_trac_environment()
 
109
 
 
110
        env.log.debug("RegressionTestTicket3833 debug1")
 
111
        debug1 = traclogfile.read()
 
112
        self.assertNotEqual(debug1.find("RegressionTestTicket3833 debug1"), -1,
 
113
            'Logging off when it should have been on.\n%r' % debug1)
 
114
 
 
115
class RegressionTestTicket3833b(FunctionalTestCaseSetup):
 
116
    def runTest(self):
 
117
        """Test for regression of http://trac.edgewall.org/ticket/3833 b"""
 
118
        # Turn logging off, try to log something, and verify that it does
 
119
        # not show up.
 
120
        traclogfile = open(os.path.join(self._testenv.tracdir, 'log',
 
121
                                        'trac.log'))
 
122
        # Seek to the end of file so we only look at new log output
 
123
        traclogfile.seek(0, 2)
 
124
        env = self._testenv.get_trac_environment()
 
125
 
 
126
        env.config.set('logging', 'log_level', 'INFO')
 
127
        env.config.save()
 
128
        env = self._testenv.get_trac_environment()
 
129
        env.log.debug("RegressionTestTicket3833 debug2")
 
130
        env.log.info("RegressionTestTicket3833 info2")
 
131
        debug2 = traclogfile.read()
 
132
        self.assertNotEqual(debug2.find("RegressionTestTicket3833 info2"), -1,
 
133
                            'Logging at info failed.\n%r' % debug2)
 
134
        self.assertEqual(debug2.find("RegressionTestTicket3833 debug2"), -1,
 
135
            'Logging still on when it should have been off.\n%r' % debug2)
 
136
 
 
137
class RegressionTestTicket3833c(FunctionalTestCaseSetup):
 
138
    def runTest(self):
 
139
        """Test for regression of http://trac.edgewall.org/ticket/3833 c"""
 
140
        # Turn logging back on, try to log something, and verify that it
 
141
        # does show up.
 
142
        traclogfile = open(os.path.join(self._testenv.tracdir, 'log',
 
143
                                        'trac.log'))
 
144
        # Seek to the end of file so we only look at new log output
 
145
        traclogfile.seek(0, 2)
 
146
        env = self._testenv.get_trac_environment()
 
147
 
 
148
        env.config.set('logging', 'log_level', 'DEBUG')
 
149
        time.sleep(2)
 
150
        env.config.save()
 
151
        #time.sleep(2)
 
152
        env = self._testenv.get_trac_environment()
 
153
        #time.sleep(2)
 
154
        env.log.debug("RegressionTestTicket3833 debug3")
 
155
        env.log.info("RegressionTestTicket3833 info3")
 
156
        #time.sleep(2)
 
157
        debug3 = traclogfile.read()
 
158
        message = ''
 
159
        success = debug3.find("RegressionTestTicket3833 debug3") != -1
 
160
        if not success:
 
161
            # Ok, the testcase failed, but we really need logging enabled.
 
162
            self._testenv.restart()
 
163
            env.log.debug("RegressionTestTicket3833 fixup3")
 
164
            fixup3 = traclogfile.read()
 
165
            message = 'Logging still off when it should have been on.\n' \
 
166
                      '%r\n%r' % (debug3, fixup3)
 
167
        self.assert_(success, message)
 
168
 
 
169
 
 
170
class RegressionTestTicket5572(FunctionalTwillTestCaseSetup):
 
171
    def runTest(self):
 
172
        """Test for regression of http://trac.edgewall.org/ticket/5572"""
 
173
        # TODO: this ticket (implemented in r6011) adds a new feature to
 
174
        # make the progress bar more configurable.  We need to test this
 
175
        # new configurability.
 
176
 
 
177
 
 
178
def functionalSuite():
 
179
    suite = FunctionalTestSuite()
 
180
    # These basic tests of the repository need to occur before other things so
 
181
    # that we have a repository to work with.
 
182
    suite.addTest(TestEmptyRepo())
 
183
    suite.addTest(TestRepoCreation())
 
184
    return suite
 
185
 
 
186
 
 
187
def suite():
 
188
    suite = functionalSuite()
 
189
 
 
190
    suite.addTest(RegressionTestRev6017())
 
191
    suite.addTest(RegressionTestTicket3833a())
 
192
    suite.addTest(RegressionTestTicket3833b())
 
193
    suite.addTest(RegressionTestTicket3833c())
 
194
    suite.addTest(RegressionTestTicket5572())
 
195
 
 
196
    import trac.versioncontrol.tests
 
197
    trac.versioncontrol.tests.functionalSuite(suite)
 
198
    import trac.ticket.tests
 
199
    trac.ticket.tests.functionalSuite(suite)
 
200
    import trac.prefs.tests
 
201
    trac.prefs.tests.functionalSuite(suite)
 
202
    import trac.wiki.tests
 
203
    trac.wiki.tests.functionalSuite(suite)
 
204
    import trac.timeline.tests
 
205
    trac.timeline.tests.functionalSuite(suite)
 
206
 
 
207
    return suite
 
208
 
 
209
 
 
210
if __name__ == '__main__':
 
211
    unittest.main(defaultTest='suite')