16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
19 from logilab.common.testlib import TestCase, unittest_main |
19 from logilab.common.testlib import TestCase, unittest_main |
20 from cubicweb import ObjectNotFound |
20 from cubicweb import ObjectNotFound |
21 from cubicweb.req import RequestSessionBase, FindEntityError |
21 from cubicweb.req import RequestSessionBase |
22 from cubicweb.devtools.testlib import CubicWebTC |
22 from cubicweb.devtools.testlib import CubicWebTC |
23 from cubicweb import Unauthorized |
23 from cubicweb import Unauthorized |
24 |
24 |
25 |
25 |
26 class RequestTC(TestCase): |
26 class RequestTC(TestCase): |
60 def test_base_url(self): |
60 def test_base_url(self): |
61 base_url = self.config['base-url'] |
61 base_url = self.config['base-url'] |
62 with self.admin_access.repo_cnx() as session: |
62 with self.admin_access.repo_cnx() as session: |
63 self.assertEqual(session.base_url(), base_url) |
63 self.assertEqual(session.base_url(), base_url) |
64 |
64 |
65 def test_secure_deprecated(self): |
|
66 with self.admin_access.cnx() as cnx: |
|
67 with self.assertWarns(DeprecationWarning): |
|
68 cnx.base_url(secure=True) |
|
69 with self.assertRaises(TypeError): |
|
70 cnx.base_url(thing=42) |
|
71 with self.assertWarns(DeprecationWarning): |
|
72 cnx.build_url('ah', __secure__='whatever') |
|
73 |
|
74 def test_view_catch_ex(self): |
65 def test_view_catch_ex(self): |
75 with self.admin_access.web_request() as req: |
66 with self.admin_access.web_request() as req: |
76 rset = req.execute('CWUser X WHERE X login "hop"') |
67 rset = req.execute('CWUser X WHERE X login "hop"') |
77 self.assertEqual(req.view('oneline', rset, 'null'), '') |
68 self.assertEqual(req.view('oneline', rset, 'null'), '') |
78 self.assertRaises(ObjectNotFound, req.view, 'onelinee', rset, 'null') |
69 self.assertRaises(ObjectNotFound, req.view, 'onelinee', rset, 'null') |
79 |
|
80 def test_find_one_entity(self): |
|
81 with self.admin_access.web_request() as req: |
|
82 req.create_entity( |
|
83 'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
|
84 surname=u'de Vienne', firstname=u'Christophe', |
|
85 in_group=req.find('CWGroup', name=u'users').one()) |
|
86 |
|
87 req.create_entity( |
|
88 'CWUser', login=u'adim', upassword='adim', surname=u'di mascio', |
|
89 firstname=u'adrien', |
|
90 in_group=req.find('CWGroup', name=u'users').one()) |
|
91 |
|
92 u = req.find_one_entity('CWUser', login=u'cdevienne') |
|
93 self.assertEqual(u.firstname, u"Christophe") |
|
94 |
|
95 with self.assertRaises(FindEntityError): |
|
96 req.find_one_entity('CWUser', login=u'patanok') |
|
97 |
|
98 with self.assertRaises(FindEntityError): |
|
99 req.find_one_entity('CWUser') |
|
100 |
|
101 def test_find_entities(self): |
|
102 with self.admin_access.web_request() as req: |
|
103 req.create_entity( |
|
104 'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
|
105 surname=u'de Vienne', firstname=u'Christophe', |
|
106 in_group=req.find('CWGroup', name=u'users').one()) |
|
107 |
|
108 req.create_entity( |
|
109 'CWUser', login=u'adim', upassword='adim', surname=u'di mascio', |
|
110 firstname=u'adrien', |
|
111 in_group=req.find('CWGroup', name=u'users').one()) |
|
112 |
|
113 users = list(req.find_entities('CWUser', login=u'cdevienne')) |
|
114 self.assertEqual(1, len(users)) |
|
115 self.assertEqual(users[0].firstname, u"Christophe") |
|
116 |
|
117 users = list(req.find_entities('CWUser', login=u'patanok')) |
|
118 self.assertEqual(0, len(users)) |
|
119 |
|
120 users = list(req.find_entities('CWUser')) |
|
121 self.assertEqual(4, len(users)) |
|
122 |
70 |
123 def test_find(self): |
71 def test_find(self): |
124 with self.admin_access.web_request() as req: |
72 with self.admin_access.web_request() as req: |
125 req.create_entity( |
73 req.create_entity( |
126 'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
74 'CWUser', login=u'cdevienne', upassword=u'cdevienne', |