author | Katia Saurfelt <katia.saurfelt@logilab.fr> |
Mon, 31 Aug 2009 16:29:10 +0200 | |
branch | stable |
changeset 3066 | ff83ccd612ce |
parent 1977 | 606923dff11b |
child 2773 | b2530e3e0afb |
child 4212 | ab6573088b4a |
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 |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
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 |
||
13 |
from logilab.common.testlib import (TestCase, unittest_main, mock_object, |
|
14 |
SkipAwareTextTestRunner) |
|
15 |
from cubicweb.devtools import htmlparser |
|
16 |
||
17 |
from cubicweb.devtools.testlib import WebTest, EnvBasedTC |
|
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): |
|
26 |
class MyWebTest(WebTest): |
|
27 |
||
28 |
def test_error_view(self): |
|
29 |
self.add_entity('Bug', title=u"bt") |
|
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 |
class TestLibTC(EnvBasedTC): |
|
43 |
def test_add_entity_with_relation(self): |
|
44 |
bug = self.add_entity(u'Bug', title=u"toto") |
|
45 |
self.add_entity(u'Bug', title=u"tata", identical_to=bug) |
|
46 |
||
47 |
rset = self.execute('Any BA WHERE BA is Bug, BA title "toto"') |
|
48 |
self.assertEquals(len(rset), 1) |
|
49 |
bug = tuple(rset.entities())[0] |
|
50 |
self.assertEquals(bug.identical_to[0].title, "tata") |
|
51 |
||
52 |
||
53 |
||
54 |
HTML_PAGE = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
55 |
<html> |
|
56 |
<head><title>need a title</title></head> |
|
57 |
<body> |
|
58 |
<h1>Hello World !</h1> |
|
59 |
</body> |
|
60 |
</html> |
|
61 |
""" |
|
62 |
||
63 |
HTML_PAGE2 = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
64 |
<html> |
|
65 |
<head><title>need a title</title></head> |
|
66 |
<body> |
|
67 |
<h1>Test</h1> |
|
68 |
<h1>Hello <a href="http://www.google.com">world</a> !</h1> |
|
69 |
<h2>h2 title</h2> |
|
70 |
<h3>h3 title</h3> |
|
71 |
<h2>antoher h2 title</h2> |
|
72 |
<h4>h4 title</h4> |
|
73 |
<p><a href="http://www.logilab.org">Logilab</a> introduces CW !</p> |
|
74 |
</body> |
|
75 |
</html> |
|
76 |
""" |
|
77 |
||
78 |
HTML_PAGE_ERROR = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
79 |
<html> |
|
80 |
<head><title>need a title</title></head> |
|
81 |
<body> |
|
82 |
Logilab</a> introduces CW ! |
|
83 |
</body> |
|
84 |
</html> |
|
85 |
""" |
|
86 |
||
87 |
HTML_NON_STRICT = u"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
88 |
<html> |
|
89 |
<head><title>need a title</title></head> |
|
90 |
<body> |
|
91 |
<h1><a href="something.com">title</h1> |
|
92 |
</body> |
|
93 |
</html> |
|
94 |
""" |
|
95 |
||
96 |
||
97 |
class HTMLPageInfoTC(TestCase): |
|
98 |
"""test cases for PageInfo""" |
|
99 |
def setUp(self): |
|
100 |
parser = htmlparser.DTDValidator() |
|
101 |
self.page_info = parser.parse_string(HTML_PAGE2) |
|
102 |
||
103 |
def test_source1(self): |
|
104 |
"""make sure source is stored correctly""" |
|
105 |
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
|
106 |
|
0 | 107 |
def test_source2(self): |
108 |
"""make sure source is stored correctly - raise exception""" |
|
109 |
parser = htmlparser.DTDValidator() |
|
110 |
self.assertRaises(AssertionError, parser.parse_string, HTML_PAGE_ERROR) |
|
111 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
112 |
|
0 | 113 |
def test_has_title_no_level(self): |
114 |
"""tests h? tags information""" |
|
115 |
self.assertEquals(self.page_info.has_title('Test'), True) |
|
116 |
self.assertEquals(self.page_info.has_title('Test '), False) |
|
117 |
self.assertEquals(self.page_info.has_title('Tes'), False) |
|
118 |
self.assertEquals(self.page_info.has_title('Hello world !'), True) |
|
119 |
||
120 |
def test_has_title_level(self): |
|
121 |
"""tests h? tags information""" |
|
122 |
self.assertEquals(self.page_info.has_title('Test', level = 1), True) |
|
123 |
self.assertEquals(self.page_info.has_title('Test', level = 2), False) |
|
124 |
self.assertEquals(self.page_info.has_title('Test', level = 3), False) |
|
125 |
self.assertEquals(self.page_info.has_title('Test', level = 4), False) |
|
126 |
self.assertRaises(IndexError, self.page_info.has_title, 'Test', level = 5) |
|
127 |
||
128 |
def test_has_title_regexp_no_level(self): |
|
129 |
"""tests has_title_regexp() with no particular level specified""" |
|
130 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title'), True) |
|
131 |
||
132 |
def test_has_title_regexp_level(self): |
|
133 |
"""tests has_title_regexp() with a particular level specified""" |
|
134 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 2), True) |
|
135 |
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 3), True) |
|
136 |
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
|
137 |
|
0 | 138 |
def test_appears(self): |
139 |
"""tests PageInfo.appears()""" |
|
140 |
self.assertEquals(self.page_info.appears('CW'), True) |
|
141 |
self.assertEquals(self.page_info.appears('Logilab'), True) |
|
142 |
self.assertEquals(self.page_info.appears('Logilab introduces'), True) |
|
143 |
self.assertEquals(self.page_info.appears('H2 title'), False) |
|
144 |
||
145 |
def test_has_link(self): |
|
146 |
"""tests has_link()""" |
|
147 |
self.assertEquals(self.page_info.has_link('Logilab'), True) |
|
148 |
self.assertEquals(self.page_info.has_link('logilab'), False) |
|
149 |
self.assertEquals(self.page_info.has_link('Logilab', 'http://www.logilab.org'), True) |
|
150 |
self.assertEquals(self.page_info.has_link('Logilab', 'http://www.google.com'), False) |
|
151 |
||
152 |
def test_has_link_regexp(self): |
|
153 |
"""test has_link_regexp()""" |
|
154 |
self.assertEquals(self.page_info.has_link_regexp('L[oi]gilab'), True) |
|
155 |
self.assertEquals(self.page_info.has_link_regexp('L[ai]gilab'), False) |
|
156 |
||
157 |
||
158 |
if __name__ == '__main__': |
|
159 |
unittest_main() |