annotate bitten/tests/web_ui.py @ 458:c9ac97df8a5e

Fix build listener invocation.
author cmlenz
date Wed, 19 Sep 2007 09:32:18 +0000
parents e660687ac89c
children a7c795920c4a
rev   line source
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
2 #
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
4 # Copyright (C) 2007 Edgewall Software
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
5 # All rights reserved.
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
6 #
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
7 # This software is licensed as described in the file COPYING, which
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
8 # you should have received as part of this distribution. The terms
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
9 # are also available at http://bitten.edgewall.org/wiki/License.
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
10
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
11 import shutil
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
12 import tempfile
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
13 import unittest
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
14
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
15 from trac.core import TracError
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
16 from trac.db import DatabaseManager
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
17 from trac.perm import PermissionCache, PermissionSystem
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
18 from trac.test import EnvironmentStub, Mock
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
19 from trac.util.html import Markup
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
20 from trac.web.clearsilver import HDFWrapper
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
21 from trac.web.href import Href
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
22 from bitten.main import BuildSystem
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
23 from bitten.model import Build, BuildConfig, BuildStep, TargetPlatform, schema
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
24 from bitten.web_ui import BuildConfigController, SourceFileLinkFormatter
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
25
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
26
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
27 class BuildConfigControllerTestCase(unittest.TestCase):
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
28
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
29 def setUp(self):
458
c9ac97df8a5e Fix build listener invocation.
cmlenz
parents: 440
diff changeset
30 self.env = EnvironmentStub(enable=['trac.*', 'bitten.*'])
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
31 self.env.path = tempfile.mkdtemp()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
32
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
33 # Create tables
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
34 db = self.env.get_db_cnx()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
35 cursor = db.cursor()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
36 connector, _ = DatabaseManager(self.env)._get_connector()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
37 for table in schema:
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
38 for stmt in connector.to_sql(table):
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
39 cursor.execute(stmt)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
40
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
41 # Set up permissions
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
42 self.env.config.set('trac', 'permission_store',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
43 'DefaultPermissionStore')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
44
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
45 # Hook up a dummy repository
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
46 self.repos = Mock(
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
47 get_node=lambda path, rev=None: Mock(get_history=lambda: [],
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
48 isdir=True),
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
49 normalize_path=lambda path: path,
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
50 sync=lambda: None
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
51 )
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
52 self.env.get_repository = lambda authname=None: self.repos
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
53
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
54 def tearDown(self):
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
55 shutil.rmtree(self.env.path)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
56
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
57 def test_overview(self):
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
58 PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
59 req = Mock(method='GET', base_path='', cgi_location='',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
60 path_info='/build', href=Href('/trac'), args={}, chrome={},
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
61 hdf=HDFWrapper(), perm=PermissionCache(self.env, 'joe'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
62
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
63 module = BuildConfigController(self.env)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
64 assert module.match_request(req)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
65 module.process_request(req)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
66
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
67 self.assertEqual('overview', req.hdf['page.mode'])
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
68 self.assertEqual('0', req.hdf.get('build.can_create', '0'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
69
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
70 def test_view_config(self):
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
71 config = BuildConfig(self.env, name='test', path='trunk')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
72 config.insert()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
73 platform = TargetPlatform(self.env, config='test', name='any')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
74 platform.insert()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
75
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
76 PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
77 req = Mock(method='GET', base_path='', cgi_location='',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
78 path_info='/build/test', href=Href('/trac'), args={},
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
79 chrome={}, hdf=HDFWrapper(), authname='joe',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
80 perm=PermissionCache(self.env, 'joe'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
81
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
82 root = Mock(get_entries=lambda: ['foo'],
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
83 get_history=lambda: [('trunk', rev, 'edit') for rev in
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
84 range(123, 111, -1)])
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
85 self.repos = Mock(get_node=lambda path, rev=None: root,
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
86 sync=lambda: None, normalize_path=lambda path: path)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
87
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
88 module = BuildConfigController(self.env)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
89 assert module.match_request(req)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
90 module.process_request(req)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
91
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
92 self.assertEqual('view_config', req.hdf['page.mode'])
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
93 self.assertEqual('0', req.hdf.get('build.config.can_delete', '0'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
94 self.assertEqual('0', req.hdf.get('build.config.can_modify', '0'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
95 self.assertEqual(None, req.hdf.get('chrome.links.next.0.href'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
96
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
97 def test_view_config_paging(self):
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
98 config = BuildConfig(self.env, name='test', path='trunk')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
99 config.insert()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
100 platform = TargetPlatform(self.env, config='test', name='any')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
101 platform.insert()
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
102
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
103 PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
104 req = Mock(method='GET', base_path='', cgi_location='',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
105 path_info='/build/test', href=Href('/trac'), args={},
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
106 chrome={}, hdf=HDFWrapper(), authname='joe',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
107 perm=PermissionCache(self.env, 'joe'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
108
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
109 root = Mock(get_entries=lambda: ['foo'],
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
110 get_history=lambda: [('trunk', rev, 'edit') for rev in
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
111 range(123, 110, -1)])
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
112 self.repos = Mock(get_node=lambda path, rev=None: root,
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
113 sync=lambda: None, normalize_path=lambda path: path)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
114
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
115 module = BuildConfigController(self.env)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
116 assert module.match_request(req)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
117 module.process_request(req)
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
118
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
119 if req.chrome: # Trac 0.11
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
120 self.assertEqual('/trac/build/test?page=2',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
121 req.chrome['links']['next'][0]['href'])
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
122 else:
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
123 self.assertEqual('/trac/build/test?page=2',
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
124 req.hdf.get('chrome.links.next.0.href'))
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
125
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
126
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
127 class SourceFileLinkFormatterTestCase(unittest.TestCase):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
128
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
129 def setUp(self):
458
c9ac97df8a5e Fix build listener invocation.
cmlenz
parents: 440
diff changeset
130 self.env = EnvironmentStub(enable=['trac.*', 'bitten.*'])
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
131
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
132 # Create tables
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
133 db = self.env.get_db_cnx()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
134 cursor = db.cursor()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
135 connector, _ = DatabaseManager(self.env)._get_connector()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
136 for table in schema:
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
137 for stmt in connector.to_sql(table):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
138 cursor.execute(stmt)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
139
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
140 # Hook up a dummy repository
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
141 self.repos = Mock(
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
142 get_node=lambda path, rev=None: Mock(get_history=lambda: [],
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
143 isdir=True),
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
144 normalize_path=lambda path: path,
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
145 sync=lambda: None
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
146 )
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
147 self.env.get_repository = lambda authname=None: self.repos
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
148
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
149 def tearDown(self):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
150 pass
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
151
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
152 def test_format_simple_link_in_repos(self):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
153 BuildConfig(self.env, name='test', path='trunk').insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
154 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42,
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
155 status=Build.SUCCESS, slave='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
156 build.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
157 step = BuildStep(self.env, build=build.id, name='foo',
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
158 status=BuildStep.SUCCESS)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
159 step.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
160
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
161 self.repos.get_node = lambda path, rev: (path, rev)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
162
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
163 req = Mock(method='GET', href=Href('/trac'), authname='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
164 comp = SourceFileLinkFormatter(self.env)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
165 formatter = comp.get_formatter(req, build)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
166
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
167 output = formatter(step, None, None, u'error in foo/bar.c: bad')
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
168 self.assertEqual(Markup, type(output))
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
169 self.assertEqual('error in <a href="/trac/browser/trunk/foo/bar.c">'
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
170 'foo/bar.c</a>: bad', output)
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
171
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
172 def test_format_simple_link_not_in_repos(self):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
173 BuildConfig(self.env, name='test', path='trunk').insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
174 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42,
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
175 status=Build.SUCCESS, slave='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
176 build.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
177 step = BuildStep(self.env, build=build.id, name='foo',
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
178 status=BuildStep.SUCCESS)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
179 step.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
180
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
181 def _raise():
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
182 raise TracError('No such node')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
183 self.repos.get_node = lambda path, rev: _raise()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
184
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
185 req = Mock(method='GET', href=Href('/trac'), authname='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
186 comp = SourceFileLinkFormatter(self.env)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
187 formatter = comp.get_formatter(req, build)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
188
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
189 output = formatter(step, None, None, u'error in foo/bar.c: bad')
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
190 self.assertEqual(Markup, type(output))
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
191 self.assertEqual('error in foo/bar.c: bad', output)
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
192
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
193 def test_format_link_in_repos_with_line(self):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
194 BuildConfig(self.env, name='test', path='trunk').insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
195 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42,
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
196 status=Build.SUCCESS, slave='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
197 build.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
198 step = BuildStep(self.env, build=build.id, name='foo',
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
199 status=BuildStep.SUCCESS)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
200 step.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
201
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
202 self.repos.get_node = lambda path, rev: (path, rev)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
203
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
204 req = Mock(method='GET', href=Href('/trac'), authname='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
205 comp = SourceFileLinkFormatter(self.env)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
206 formatter = comp.get_formatter(req, build)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
207
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
208 output = formatter(step, None, None, u'error in foo/bar.c:123: bad')
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
209 self.assertEqual(Markup, type(output))
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
210 self.assertEqual('error in <a href="/trac/browser/trunk/foo/bar.c#L123">'
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
211 'foo/bar.c:123</a>: bad', output)
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
212
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
213 def test_format_link_not_in_repos_with_line(self):
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
214 BuildConfig(self.env, name='test', path='trunk').insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
215 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42,
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
216 status=Build.SUCCESS, slave='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
217 build.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
218 step = BuildStep(self.env, build=build.id, name='foo',
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
219 status=BuildStep.SUCCESS)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
220 step.insert()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
221
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
222 def _raise():
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
223 raise TracError('No such node')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
224 self.repos.get_node = lambda path, rev: _raise()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
225
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
226 req = Mock(method='GET', href=Href('/trac'), authname='hal')
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
227 comp = SourceFileLinkFormatter(self.env)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
228 formatter = comp.get_formatter(req, build)
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
229
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
230 output = formatter(step, None, None, u'error in foo/bar.c:123: bad')
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
231 self.assertEqual(Markup, type(output))
440
e660687ac89c Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents: 439
diff changeset
232 self.assertEqual('error in foo/bar.c:123: bad', output)
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
233
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
234
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
235 def suite():
439
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
236 suite = unittest.TestSuite()
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
237 suite.addTest(unittest.makeSuite(BuildConfigControllerTestCase, 'test'))
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
238 suite.addTest(unittest.makeSuite(SourceFileLinkFormatterTestCase, 'test'))
20ddfbb8e879 Fix for #154, added unit tests.
cmlenz
parents: 436
diff changeset
239 return suite
410
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
240
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
241 if __name__ == '__main__':
7930cdd83d13 More restructuring: got rid of the `trac_ext` subpackage, which makes no sense now that the master is also coupled to Trac.
cmlenz
parents:
diff changeset
242 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software