[ldapfeed] ldap3 do not raise an exception in case of failure of cnx.bind()
but return 'False' instead.
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.fromsiximportPY3fromlogilab.common.testlibimportunittest_mainfromcubicweb.devtools.testlibimportCubicWebTCfromcubicweb.ext.restimportrest_publishclassRestTC(CubicWebTC):defcontext(self,req):returnreq.execute('CWUser X WHERE X login "admin"').get_entity(0,0)deftest_eid_role(self):withself.admin_access.web_request()asreq:context=self.context(req)self.assertEqual(rest_publish(context,':eid:`%s`'%context.eid),'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">''#%s</a></p>\n'%context.eid)self.assertEqual(rest_publish(context,':eid:`%s:some text`'%context.eid),'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">''some text</a></p>\n')deftest_bad_rest_no_crash(self):withself.admin_access.web_request()asreq:rest_publish(self.context(req),'''| card | implication |--------------------------| 1-1 | N1 = N2 || 1-? | N1 <= N2 || 1-+ | N1 >= N2 || 1-* | N1>0 => N2>0 |--------------------------| ?-? | N1 # N2 || ?-+ | N1 >= N2 || ?-* | N1 # N2 |--------------------------| +-+ | N1>0 => N2>0 et || | N2>0 => N1>0 || +-* | N1>+ => N2>0 |--------------------------| *-* | N1#N2 |--------------------------''')deftest_disable_field_name_colspan(self):withself.admin_access.web_request()asreq:context=self.context(req)value=rest_publish(context,'''my field list::a long dumb param name: value''')self.assertNotIn('colspan',value)deftest_rql_role_with_vid(self):withself.admin_access.web_request()asreq:context=self.context(req)out=rest_publish(context,':rql:`Any X WHERE X is CWUser:table`')self.assertTrue(out.endswith('<a href="http://testing.fr/cubicweb/cwuser/anon" ''title="">anon</a></td></tr>\n</tbody></table>''</div></p>\n'))deftest_rql_role_with_vid_empty_rset(self):withself.admin_access.web_request()asreq:context=self.context(req)out=rest_publish(context,':rql:`Any X WHERE X is CWUser, X login "nono":table`')self.assertTrue(out.endswith('<p><div class="searchMessage"><strong>''No result matching query</strong></div>\n</p>\n'))deftest_rql_role_with_unknown_vid(self):withself.admin_access.web_request()asreq:context=self.context(req)out=rest_publish(context,':rql:`Any X WHERE X is CWUser:toto`')self.assertTrue(out.startswith("<p>an error occurred while interpreting this ""rql directive: ObjectNotFound(%s'toto',)</p>"%(''ifPY3else'u')),out)deftest_rql_role_without_vid(self):withself.admin_access.web_request()asreq:context=self.context(req)out=rest_publish(context,':rql:`Any X WHERE X is CWUser`')self.assertEqual(out,u'<p><h1>CWUser_plural</h1><div class="section">''<a href="http://testing.fr/cubicweb/cwuser/admin" title="">admin</a>''</div><div class="section">''<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a>''</div></p>\n')deftest_bookmark_role(self):withself.admin_access.web_request()asreq:context=self.context(req)rset=req.execute('INSERT Bookmark X: X title "hello", X path ''"/view?rql=Any X WHERE X is CWUser"')eid=rset[0][0]out=rest_publish(context,':bookmark:`%s`'%eid)self.assertEqual(out,u'<p><h1>CWUser_plural</h1><div class="section">''<a href="http://testing.fr/cubicweb/cwuser/admin" title="">admin''</a></div><div class="section">''<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon''</a></div></p>\n')deftest_rqltable_nocontent(self):withself.admin_access.web_request()asreq:context=self.context(req)out=rest_publish(context,""".. rql-table::""")self.assertIn("System Message: ERROR",out)self.assertIn("Content block expected for the "rql-table" ""directive; none found",out)deftest_rqltable_norset(self):withself.admin_access.web_request()asreq:context=self.context(req)rql="Any X WHERE X is CWUser, X firstname 'franky'"out=rest_publish(context,"""\.. rql-table::%(rql)s"""%{'rql':rql})self.assertIn("System Message: WARNING",out)self.assertIn("empty result set",out)deftest_rqltable_nooptions(self):withself.admin_access.web_request()asreq:rql="Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"out=rest_publish(self.context(req),"""\.. rql-table::%(rql)s """%{'rql':rql})view=self.vreg['views'].select('table',req,rset=req.execute(rql))self.assertEqual(view.render(w=None)[49:],out[49:])deftest_rqltable_vid(self):withself.admin_access.web_request()asreq:rql="Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"vid='mytable'out=rest_publish(self.context(req),"""\.. rql-table:: :vid: %(vid)s%(rql)s """%{'rql':rql,'vid':vid})view=self.vreg['views'].select(vid,req,rset=req.execute(rql))self.assertEqual(view.render(w=None)[49:],out[49:])self.assertIn(vid,out[:49])deftest_rqltable_badvid(self):withself.admin_access.web_request()asreq:rql="Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"vid='mytabel'out=rest_publish(self.context(req),"""\.. rql-table:: :vid: %(vid)s%(rql)s """%{'rql':rql,'vid':vid})self.assertIn("fail to select '%s' view"%vid,out)deftest_rqltable_headers(self):withself.admin_access.web_request()asreq:rql="Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"headers=["nom","prenom","identifiant"]out=rest_publish(self.context(req),"""\.. rql-table:: :headers: %(headers)s%(rql)s """%{'rql':rql,'headers':', '.join(headers)})view=self.vreg['views'].select('table',req,rset=req.execute(rql))view.headers=headersself.assertEqual(view.render(w=None)[49:],out[49:])deftest_rqltable_headers_missing(self):withself.admin_access.web_request()asreq:rql="Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"headers=["nom","","identifiant"]out=rest_publish(self.context(req),"""\.. rql-table:: :headers: %(headers)s%(rql)s """%{'rql':rql,'headers':', '.join(headers)})view=self.vreg['views'].select('table',req,rset=req.execute(rql))view.headers=[headers[0],None,headers[2]]self.assertEqual(view.render(w=None)[49:],out[49:])deftest_rqltable_headers_missing_edges(self):withself.admin_access.web_request()asreq:rql="Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"headers=[" ","prenom",""]out=rest_publish(self.context(req),"""\.. rql-table:: :headers: %(headers)s%(rql)s """%{'rql':rql,'headers':', '.join(headers)})view=self.vreg['views'].select('table',req,rset=req.execute(rql))view.headers=[None,headers[1],None]self.assertEqual(view.render(w=None)[49:],out[49:])deftest_rqltable_colvids(self):withself.admin_access.web_request()asreq:rql="Any X,S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L"colvids={0:"oneline"}out=rest_publish(self.context(req),"""\.. rql-table:: :colvids: %(colvids)s%(rql)s """%{'rql':rql,'colvids':', '.join(["%d=%s"%(k,v)fork,vincolvids.items()])})view=self.vreg['views'].select('table',req,rset=req.execute(rql))view.cellvids=colvidsself.assertEqual(view.render(w=None)[49:],out[49:])if__name__=='__main__':unittest_main()