Mercurial > bitten > bitten-test
annotate bitten/tests/web_ui.py @ 503:a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
author | wbell |
---|---|
date | Mon, 09 Mar 2009 00:46:14 +0000 |
parents | c9ac97df8a5e |
children | f3bf55de8a34 |
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 | 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 | 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.href import Href |
439 | 21 from bitten.main import BuildSystem |
22 from bitten.model import Build, BuildConfig, BuildStep, TargetPlatform, schema | |
23 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
|
24 |
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 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
|
27 |
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 def setUp(self): |
458 | 29 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
|
30 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
|
31 |
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 # 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 |
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 # 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
|
41 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
|
42 '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
|
43 |
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 # 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 ) |
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 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
|
52 |
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 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
|
54 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
|
55 |
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 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
|
57 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
|
58 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
|
59 path_info='/build', href=Href('/trac'), args={}, chrome={}, |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
60 perm=PermissionCache(self.env, 'joe')) |
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
|
61 |
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 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
|
63 assert module.match_request(req) |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
64 _, data, _ = module.process_request(req) |
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
|
65 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
66 self.assertEqual('overview', data['page_mode']) |
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
|
67 |
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 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 |
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 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
|
75 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
|
76 path_info='/build/test', href=Href('/trac'), args={}, |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
77 chrome={}, authname='joe', |
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
|
78 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
|
79 |
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 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 |
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 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
|
87 assert module.match_request(req) |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
88 _, data, _ = module.process_request(req) |
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
|
89 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
90 self.assertEqual('view_config', data['page_mode']) |
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
91 assert not 'next' in req.chrome['links'] |
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
|
92 |
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 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 |
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 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
|
100 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
|
101 path_info='/build/test', href=Href('/trac'), args={}, |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
102 chrome={}, authname='joe', |
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
|
103 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
|
104 |
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 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 |
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 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
|
112 assert module.match_request(req) |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
113 _, data, _ = module.process_request(req) |
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
|
114 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
458
diff
changeset
|
115 if req.chrome: |
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
|
116 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
|
117 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
|
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 |
439 | 120 class SourceFileLinkFormatterTestCase(unittest.TestCase): |
121 | |
122 def setUp(self): | |
458 | 123 self.env = EnvironmentStub(enable=['trac.*', 'bitten.*']) |
439 | 124 |
125 # Create tables | |
126 db = self.env.get_db_cnx() | |
127 cursor = db.cursor() | |
128 connector, _ = DatabaseManager(self.env)._get_connector() | |
129 for table in schema: | |
130 for stmt in connector.to_sql(table): | |
131 cursor.execute(stmt) | |
132 | |
133 # Hook up a dummy repository | |
134 self.repos = Mock( | |
135 get_node=lambda path, rev=None: Mock(get_history=lambda: [], | |
136 isdir=True), | |
137 normalize_path=lambda path: path, | |
138 sync=lambda: None | |
139 ) | |
140 self.env.get_repository = lambda authname=None: self.repos | |
141 | |
142 def tearDown(self): | |
143 pass | |
144 | |
145 def test_format_simple_link_in_repos(self): | |
146 BuildConfig(self.env, name='test', path='trunk').insert() | |
147 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42, | |
148 status=Build.SUCCESS, slave='hal') | |
149 build.insert() | |
150 step = BuildStep(self.env, build=build.id, name='foo', | |
151 status=BuildStep.SUCCESS) | |
152 step.insert() | |
153 | |
154 self.repos.get_node = lambda path, rev: (path, rev) | |
155 | |
156 req = Mock(method='GET', href=Href('/trac'), authname='hal') | |
157 comp = SourceFileLinkFormatter(self.env) | |
158 formatter = comp.get_formatter(req, build) | |
159 | |
440
e660687ac89c
Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents:
439
diff
changeset
|
160 output = formatter(step, None, None, u'error in foo/bar.c: bad') |
439 | 161 self.assertEqual(Markup, type(output)) |
162 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
|
163 'foo/bar.c</a>: bad', output) |
439 | 164 |
165 def test_format_simple_link_not_in_repos(self): | |
166 BuildConfig(self.env, name='test', path='trunk').insert() | |
167 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42, | |
168 status=Build.SUCCESS, slave='hal') | |
169 build.insert() | |
170 step = BuildStep(self.env, build=build.id, name='foo', | |
171 status=BuildStep.SUCCESS) | |
172 step.insert() | |
173 | |
174 def _raise(): | |
175 raise TracError('No such node') | |
176 self.repos.get_node = lambda path, rev: _raise() | |
177 | |
178 req = Mock(method='GET', href=Href('/trac'), authname='hal') | |
179 comp = SourceFileLinkFormatter(self.env) | |
180 formatter = comp.get_formatter(req, build) | |
181 | |
440
e660687ac89c
Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents:
439
diff
changeset
|
182 output = formatter(step, None, None, u'error in foo/bar.c: bad') |
439 | 183 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
|
184 self.assertEqual('error in foo/bar.c: bad', output) |
439 | 185 |
186 def test_format_link_in_repos_with_line(self): | |
187 BuildConfig(self.env, name='test', path='trunk').insert() | |
188 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42, | |
189 status=Build.SUCCESS, slave='hal') | |
190 build.insert() | |
191 step = BuildStep(self.env, build=build.id, name='foo', | |
192 status=BuildStep.SUCCESS) | |
193 step.insert() | |
194 | |
195 self.repos.get_node = lambda path, rev: (path, rev) | |
196 | |
197 req = Mock(method='GET', href=Href('/trac'), authname='hal') | |
198 comp = SourceFileLinkFormatter(self.env) | |
199 formatter = comp.get_formatter(req, build) | |
200 | |
440
e660687ac89c
Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents:
439
diff
changeset
|
201 output = formatter(step, None, None, u'error in foo/bar.c:123: bad') |
439 | 202 self.assertEqual(Markup, type(output)) |
203 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
|
204 'foo/bar.c:123</a>: bad', output) |
439 | 205 |
206 def test_format_link_not_in_repos_with_line(self): | |
207 BuildConfig(self.env, name='test', path='trunk').insert() | |
208 build = Build(self.env, config='test', platform=1, rev=123, rev_time=42, | |
209 status=Build.SUCCESS, slave='hal') | |
210 build.insert() | |
211 step = BuildStep(self.env, build=build.id, name='foo', | |
212 status=BuildStep.SUCCESS) | |
213 step.insert() | |
214 | |
215 def _raise(): | |
216 raise TracError('No such node') | |
217 self.repos.get_node = lambda path, rev: _raise() | |
218 | |
219 req = Mock(method='GET', href=Href('/trac'), authname='hal') | |
220 comp = SourceFileLinkFormatter(self.env) | |
221 formatter = comp.get_formatter(req, build) | |
222 | |
440
e660687ac89c
Follow-up fix to [486]: trailing chars in auto-linked log messages was getting removed.
cmlenz
parents:
439
diff
changeset
|
223 output = formatter(step, None, None, u'error in foo/bar.c:123: bad') |
439 | 224 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
|
225 self.assertEqual('error in foo/bar.c:123: bad', output) |
439 | 226 |
227 | |
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
|
228 def suite(): |
439 | 229 suite = unittest.TestSuite() |
230 suite.addTest(unittest.makeSuite(BuildConfigControllerTestCase, 'test')) | |
231 suite.addTest(unittest.makeSuite(SourceFileLinkFormatterTestCase, 'test')) | |
232 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
|
233 |
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
|
234 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
|
235 unittest.main(defaultTest='suite') |