[webtests] finish to give all self.view(....) a req=req parameter
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 06 Jun 2014 14:55:26 +0200
changeset 9864 f60a80592224
parent 9863 3fbad401eb61
child 9865 fd45020eabfe
[webtests] finish to give all self.view(....) a req=req parameter
devtools/__init__.py
devtools/test/unittest_testlib.py
doc/book/en/devrepo/testing.rst
web/test/unittest_views_json.py
--- a/devtools/__init__.py	Thu Jun 05 16:30:58 2014 +0200
+++ b/devtools/__init__.py	Fri Jun 06 14:55:26 2014 +0200
@@ -277,8 +277,9 @@
                                               sourcefile='/path/to/sources')
 
           def test_something(self):
-              rset = self.execute('Any X WHERE X is CWUser')
-              self.view('foaf', rset)
+              with self.admin_access.web_request() as req:
+                  rset = req.execute('Any X WHERE X is CWUser')
+                  self.view('foaf', rset, req=req)
 
     """
     skip_db_create_and_restore = True
--- a/devtools/test/unittest_testlib.py	Thu Jun 05 16:30:58 2014 +0200
+++ b/devtools/test/unittest_testlib.py	Fri Jun 06 14:55:26 2014 +0200
@@ -41,11 +41,11 @@
             def test_error_view(self):
                 with self.admin_access.web_request() as req:
                     req.create_entity('Bug', title=u"bt")
-                    self.view('raising', req.execute('Bug B'), template=None)
+                    self.view('raising', req.execute('Bug B'), template=None, req=req)
 
             def test_correct_view(self):
                 with self.admin_access.web_request() as req:
-                    self.view('primary', req.execute('CWUser U'), template=None)
+                    self.view('primary', req.execute('CWUser U'), template=None, req=req)
 
         tests = [MyWebTest('test_error_view'), MyWebTest('test_correct_view')]
         result = self.runner.run(TestSuite(tests))
--- a/doc/book/en/devrepo/testing.rst	Thu Jun 05 16:30:58 2014 +0200
+++ b/doc/book/en/devrepo/testing.rst	Fri Jun 06 14:55:26 2014 +0200
@@ -335,7 +335,7 @@
             req = self.request()
             rset = req.execute('Any B ORDERBY D DESC WHERE B is BlogEntry, '
                 'B created_by U, U login "logilab", B creation_date D')
-            self.view('rss', rset)
+            self.view('rss', rset, req=req)
 
 
 Testing with other cubes
--- a/web/test/unittest_views_json.py	Thu Jun 05 16:30:58 2014 +0200
+++ b/web/test/unittest_views_json.py	Fri Jun 06 14:55:26 2014 +0200
@@ -30,14 +30,14 @@
     def test_json_rsetexport(self):
         with self.admin_access.web_request() as req:
             rset = req.execute('Any GN,COUNT(X) GROUPBY GN ORDERBY GN WHERE X in_group G, G name GN')
-            data = self.view('jsonexport', rset)
+            data = self.view('jsonexport', rset, req=req)
             self.assertEqual(req.headers_out.getRawHeaders('content-type'), ['application/json'])
             self.assertListEqual(data, [["guests", 1], ["managers", 1]])
 
     def test_json_rsetexport_empty_rset(self):
         with self.admin_access.web_request() as req:
             rset = req.execute('Any X WHERE X is CWUser, X login "foobarbaz"')
-            data = self.view('jsonexport', rset)
+            data = self.view('jsonexport', rset, req=req)
             self.assertEqual(req.headers_out.getRawHeaders('content-type'), ['application/json'])
             self.assertListEqual(data, [])
 
@@ -65,7 +65,7 @@
     def test_json_ersetexport(self):
         with self.admin_access.web_request() as req:
             rset = req.execute('Any G ORDERBY GN WHERE G is CWGroup, G name GN')
-            data = self.view('ejsonexport', rset)
+            data = self.view('ejsonexport', rset, req=req)
             self.assertEqual(req.headers_out.getRawHeaders('content-type'), ['application/json'])
             self.assertEqual(data[0]['name'], 'guests')
             self.assertEqual(data[1]['name'], 'managers')