author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 24 Feb 2010 11:21:51 +0100 | |
branch | stable |
changeset 4687 | 082e66184f71 |
parent 4473 | f2f5576aa6ef |
child 4766 | 162b2b127b15 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
"""unittests for gct.apptest module |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
|
9 |
from cStringIO import StringIO |
|
10 |
from unittest import TestSuite |
|
11 |
||
12 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
13 |
from logilab.common.testlib import (TestCase, unittest_main, |
0 | 14 |
SkipAwareTextTestRunner) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
15 |
|
0 | 16 |
from cubicweb.devtools import htmlparser |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
17 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 18 |
|
19 |
class WebTestTC(TestCase): |
|
20 |
||
21 |
def setUp(self): |
|
22 |
output = StringIO() |
|
23 |
self.runner = SkipAwareTextTestRunner(stream=output) |
|
24 |
||
25 |
def test_error_raised(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
26 |
class MyWebTest(CubicWebTC): |
0 | 27 |
|
28 |
def test_error_view(self): |
|
4472
d3b1d50fc29a
3.6 test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
29 |
self.request().create_entity('Bug', title=u"bt") |
0 | 30 |
self.view('raising', self.execute('Bug B'), template=None) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
31 |
|
0 | 32 |
def test_correct_view(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
33 |
self.view('primary', self.execute('CWUser U'), template=None) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
34 |
|
0 | 35 |
tests = [MyWebTest('test_error_view'), MyWebTest('test_correct_view')] |
36 |
result = self.runner.run(TestSuite(tests)) |
|
37 |
self.assertEquals(result.testsRun, 2) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
38 |
self.assertEquals(len(result.errors), 0) |
0 | 39 |
self.assertEquals(len(result.failures), 1) |
40 |
||
41 |
||
42 |
||
43 |
HTML_PAGE = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
44 |
<html> |
|
45 |
<head><title>need a title</title></head> |
|
46 |
<body> |
|
47 |
<h1>Hello World !</h1> |
|
48 |
</body> |
|
49 |
</html> |
|
50 |
""" |
|
51 |
||
52 |
HTML_PAGE2 = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
53 |
<html> |
|
54 |
<head><title>need a title</title></head> |
|
55 |
<body> |
|
56 |
<h1>Test</h1> |
|
57 |
<h1>Hello <a href="http://www.google.com">world</a> !</h1> |
|
58 |
<h2>h2 title</h2> |
|
59 |
<h3>h3 title</h3> |
|
60 |
<h2>antoher h2 title</h2> |
|
61 |
<h4>h4 title</h4> |
|
62 |
<p><a href="http://www.logilab.org">Logilab</a> introduces CW !</p> |
|
63 |
</body> |
|
64 |
</html> |
|
65 |
""" |
|
66 |
||
67 |
HTML_PAGE_ERROR = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
68 |
<html> |
|
69 |
<head><title>need a title</title></head> |
|
70 |
<body> |
|
71 |
Logilab</a> introduces CW ! |
|
72 |
</body> |
|
73 |
</html> |
|
74 |
""" |
|
75 |
||
76 |
HTML_NON_STRICT = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
77 |
<html> |
|
78 |
<head><title>need a title</title></head> |
|
79 |
<body> |
|
80 |
<h1><a href="something.com">title</h1> |
|
81 |
</body> |
|
82 |
</html> |
|
83 |
""" |
|
84 |
||
85 |
||
86 |
class HTMLPageInfoTC(TestCase): |
|
87 |
"""test cases for PageInfo""" |
|
88 |
def setUp(self): |
|
89 |
parser = htmlparser.DTDValidator() |
|
90 |
self.page_info = parser.parse_string(HTML_PAGE2) |
|
91 |
||
92 |
def test_source1(self): |
|
93 |
"""make sure source is stored correctly""" |
|
94 |
self.assertEquals(self.page_info.source, HTML_PAGE2) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
95 |
|
0 | 96 |
def test_source2(self): |
97 |
"""make sure source is stored correctly - raise exception""" |
|
98 |
parser = htmlparser.DTDValidator() |
|
99 |
self.assertRaises(AssertionError, parser.parse_string, HTML_PAGE_ERROR) |
|
100 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
101 |
|
0 | 102 |
def test_has_title_no_level(self): |
103 |
"""tests h? tags information""" |
|
104 |
self.assertEquals(self.page_info.has_title('Test'), True) |
|
105 |
self.assertEquals(self.page_info.has_title('Test '), False) |
|
106 |
self.assertEquals(self.page_info.has_title('Tes'), False) |
|
107 |
self.assertEquals(self.page_info.has_title('Hello world !'), True) |
|
108 |
||
109 |
def test_has_title_level(self): |
|
110 |
"""tests h? tags information""" |
|
111 |
self.assertEquals(self.page_info.has_title('Test', level = 1), True) |
|
112 |
self.assertEquals(self.page_info.has_title('Test', level = 2), False) |
|
113 |
self.assertEquals(self.page_info.has_title('Test', level = 3), False) |
|
114 |
self.assertEquals(self.page_info.has_title('Test', level = 4), False) |
|
115 |
self.assertRaises(IndexError, self.page_info.has_title, 'Test', level = 5) |
|
116 |
||
117 |
def test_has_title_regexp_no_level(self): |
|
118 |
"""tests has_title_regexp() with no particular level specified""" |
|
119 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title'), True) |
|
120 |
||
121 |
def test_has_title_regexp_level(self): |
|
122 |
"""tests has_title_regexp() with a particular level specified""" |
|
123 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 2), True) |
|
124 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 3), True) |
|
125 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 4), False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
126 |
|
0 | 127 |
def test_appears(self): |
128 |
"""tests PageInfo.appears()""" |
|
129 |
self.assertEquals(self.page_info.appears('CW'), True) |
|
130 |
self.assertEquals(self.page_info.appears('Logilab'), True) |
|
131 |
self.assertEquals(self.page_info.appears('Logilab introduces'), True) |
|
132 |
self.assertEquals(self.page_info.appears('H2 title'), False) |
|
133 |
||
134 |
def test_has_link(self): |
|
135 |
"""tests has_link()""" |
|
136 |
self.assertEquals(self.page_info.has_link('Logilab'), True) |
|
137 |
self.assertEquals(self.page_info.has_link('logilab'), False) |
|
138 |
self.assertEquals(self.page_info.has_link('Logilab', 'http://www.logilab.org'), True) |
|
139 |
self.assertEquals(self.page_info.has_link('Logilab', 'http://www.google.com'), False) |
|
140 |
||
141 |
def test_has_link_regexp(self): |
|
142 |
"""test has_link_regexp()""" |
|
143 |
self.assertEquals(self.page_info.has_link_regexp('L[oi]gilab'), True) |
|
144 |
self.assertEquals(self.page_info.has_link_regexp('L[ai]gilab'), False) |
|
145 |
||
146 |
||
147 |
if __name__ == '__main__': |
|
148 |
unittest_main() |