author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Thu, 27 Jun 2013 18:15:57 +0200 | |
changeset 9117 | e25c5abc667c |
parent 8941 | 7b26fe71404f |
child 9118 | bb9e19df9a05 |
permissions | -rw-r--r-- |
8460
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5390
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6776
eebe86b89285
[tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6341
diff
changeset
|
18 |
"""unittests for cw.devtools.testlib module""" |
0 | 19 |
|
20 |
from cStringIO import StringIO |
|
21 |
||
6776
eebe86b89285
[tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6341
diff
changeset
|
22 |
from unittest import TextTestRunner |
eebe86b89285
[tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6341
diff
changeset
|
23 |
from logilab.common.testlib import TestSuite, TestCase, unittest_main |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
24 |
|
0 | 25 |
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
|
26 |
from cubicweb.devtools.testlib import CubicWebTC |
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4473
diff
changeset
|
27 |
from cubicweb.pytestconf import clean_repo_test_cls |
0 | 28 |
|
6776
eebe86b89285
[tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6341
diff
changeset
|
29 |
|
0 | 30 |
class WebTestTC(TestCase): |
31 |
||
32 |
def setUp(self): |
|
33 |
output = StringIO() |
|
6776
eebe86b89285
[tests] use TextTestRunner from unittest, no more need to use SkipAwareTextRunner from lgc.testlib (which doesn't exist anymore in recent releases
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6341
diff
changeset
|
34 |
self.runner = TextTestRunner(stream=output) |
5390
a40ffdce549d
cleanup debugging trace
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5389
diff
changeset
|
35 |
|
0 | 36 |
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
|
37 |
class MyWebTest(CubicWebTC): |
0 | 38 |
|
39 |
def test_error_view(self): |
|
4472
d3b1d50fc29a
3.6 test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
40 |
self.request().create_entity('Bug', title=u"bt") |
0 | 41 |
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
|
42 |
|
0 | 43 |
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
|
44 |
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
|
45 |
|
0 | 46 |
tests = [MyWebTest('test_error_view'), MyWebTest('test_correct_view')] |
47 |
result = self.runner.run(TestSuite(tests)) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
48 |
self.assertEqual(result.testsRun, 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
49 |
self.assertEqual(len(result.errors), 0) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
50 |
self.assertEqual(len(result.failures), 1) |
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4473
diff
changeset
|
51 |
clean_repo_test_cls(MyWebTest) |
0 | 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): |
|
8941
7b26fe71404f
drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8694
diff
changeset
|
100 |
parser = htmlparser.HTMLValidator() |
7b26fe71404f
drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8694
diff
changeset
|
101 |
# disable cleanup that would remove doctype |
7b26fe71404f
drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8694
diff
changeset
|
102 |
parser.preprocess_data = lambda data: data |
0 | 103 |
self.page_info = parser.parse_string(HTML_PAGE2) |
104 |
||
105 |
def test_source1(self): |
|
106 |
"""make sure source is stored correctly""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
107 |
self.assertEqual(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
|
108 |
|
0 | 109 |
def test_source2(self): |
110 |
"""make sure source is stored correctly - raise exception""" |
|
111 |
parser = htmlparser.DTDValidator() |
|
112 |
self.assertRaises(AssertionError, parser.parse_string, HTML_PAGE_ERROR) |
|
113 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
114 |
|
0 | 115 |
def test_has_title_no_level(self): |
116 |
"""tests h? tags information""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
117 |
self.assertEqual(self.page_info.has_title('Test'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
118 |
self.assertEqual(self.page_info.has_title('Test '), False) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
119 |
self.assertEqual(self.page_info.has_title('Tes'), False) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
120 |
self.assertEqual(self.page_info.has_title('Hello world !'), True) |
0 | 121 |
|
122 |
def test_has_title_level(self): |
|
123 |
"""tests h? tags information""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
124 |
self.assertEqual(self.page_info.has_title('Test', level = 1), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
125 |
self.assertEqual(self.page_info.has_title('Test', level = 2), False) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
126 |
self.assertEqual(self.page_info.has_title('Test', level = 3), False) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
127 |
self.assertEqual(self.page_info.has_title('Test', level = 4), False) |
0 | 128 |
self.assertRaises(IndexError, self.page_info.has_title, 'Test', level = 5) |
129 |
||
130 |
def test_has_title_regexp_no_level(self): |
|
131 |
"""tests has_title_regexp() with no particular level specified""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
132 |
self.assertEqual(self.page_info.has_title_regexp('h[23] title'), True) |
0 | 133 |
|
134 |
def test_has_title_regexp_level(self): |
|
135 |
"""tests has_title_regexp() with a particular level specified""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
136 |
self.assertEqual(self.page_info.has_title_regexp('h[23] title', 2), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
137 |
self.assertEqual(self.page_info.has_title_regexp('h[23] title', 3), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
138 |
self.assertEqual(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
|
139 |
|
0 | 140 |
def test_appears(self): |
141 |
"""tests PageInfo.appears()""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
142 |
self.assertEqual(self.page_info.appears('CW'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
143 |
self.assertEqual(self.page_info.appears('Logilab'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
144 |
self.assertEqual(self.page_info.appears('Logilab introduces'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
145 |
self.assertEqual(self.page_info.appears('H2 title'), False) |
0 | 146 |
|
147 |
def test_has_link(self): |
|
148 |
"""tests has_link()""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
149 |
self.assertEqual(self.page_info.has_link('Logilab'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
150 |
self.assertEqual(self.page_info.has_link('logilab'), False) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
151 |
self.assertEqual(self.page_info.has_link('Logilab', 'http://www.logilab.org'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
152 |
self.assertEqual(self.page_info.has_link('Logilab', 'http://www.google.com'), False) |
0 | 153 |
|
154 |
def test_has_link_regexp(self): |
|
155 |
"""test has_link_regexp()""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
156 |
self.assertEqual(self.page_info.has_link_regexp('L[oi]gilab'), True) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
157 |
self.assertEqual(self.page_info.has_link_regexp('L[ai]gilab'), False) |
0 | 158 |
|
159 |
||
8460
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
160 |
class CWUtilitiesTC(CubicWebTC): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
161 |
def test_temporary_permissions_eschema(self): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
162 |
eschema = self.schema['CWUser'] |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
163 |
with self.temporary_permissions(CWUser={'read': ()}): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
164 |
self.assertEqual(eschema.permissions['read'], ()) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
165 |
self.assertTrue(eschema.permissions['add']) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
166 |
self.assertTrue(eschema.permissions['read'], ()) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
167 |
|
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
168 |
def test_temporary_permissions_rdef(self): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
169 |
rdef = self.schema['CWUser'].rdef('in_group') |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
170 |
with self.temporary_permissions((rdef, {'read': ()})): |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
171 |
self.assertEqual(rdef.permissions['read'], ()) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
172 |
self.assertTrue(rdef.permissions['add']) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
173 |
self.assertTrue(rdef.permissions['read'], ()) |
b1f6777fc839
[testlib] introduce temporary_permissions context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6776
diff
changeset
|
174 |
|
9117
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
175 |
class RepoAccessTC(CubicWebTC): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
176 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
177 |
def test_repo_connection(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
178 |
acc = self.new_access('admin') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
179 |
with acc.repo_cnx() as cnx: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
180 |
rset = cnx.execute('Any X WHERE X is CWUser') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
181 |
self.assertTrue(rset) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
182 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
183 |
def test_client_connection(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
184 |
acc = self.new_access('admin') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
185 |
with acc.client_cnx() as cnx: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
186 |
rset = cnx.execute('Any X WHERE X is CWUser') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
187 |
self.assertTrue(rset) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
188 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
189 |
def test_web_request(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
190 |
acc = self.new_access('admin') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
191 |
with acc.web_request(elephant='babar') as req: |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
192 |
rset = req.execute('Any X WHERE X is CWUser') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
193 |
self.assertTrue(rset) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
194 |
self.assertEqual('babar', req.form['elephant']) |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
195 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
196 |
def test_close(self): |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
197 |
acc = self.new_access('admin') |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
198 |
acc.close() |
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
199 |
|
e25c5abc667c
[testlib] introduce a RepoAccess class to easily create connection and request
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8941
diff
changeset
|
200 |
|
0 | 201 |
if __name__ == '__main__': |
202 |
unittest_main() |