# HG changeset patch # User Julien Cristau # Date 1405089882 -7200 # Node ID 4db650d79e32ad271260556b173a846fa0bd3a06 # Parent 3c2202e7bd31716b4ebf41eae3b0a55e4862ba46 [test] Fix the query-log-file test Testing this functionality in a CubicWebTC is awkward because the wrapping happens in handle_request, which tests basically bypass (they call core_handle directly, and do their own magic for linking the request with a cnx). The test method worked when ran on its own, but not together with the rest of the test class. So use a CubicWebServerTC instead, which goes through the whole stack. diff -r 3c2202e7bd31 -r 4db650d79e32 web/test/unittest_application.py --- a/web/test/unittest_application.py Fri Jul 11 13:48:07 2014 +0200 +++ b/web/test/unittest_application.py Fri Jul 11 16:44:42 2014 +0200 @@ -19,7 +19,6 @@ import base64, Cookie import httplib -import tempfile from logilab.common.testlib import TestCase, unittest_main from logilab.common.decorators import clear_cache, classproperty @@ -436,14 +435,6 @@ req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?' self.app_handle_request(req) - def test_log_queries(self): - logfile = tempfile.NamedTemporaryFile() - self.config.global_set_option('query-log-file', logfile.name) - with self.admin_access.web_request() as req: - self.app.handle_request(req, 'view') - self.assertTrue(logfile.read()) - logfile.close() - if __name__ == '__main__': unittest_main() diff -r 3c2202e7bd31 -r 4db650d79e32 web/test/unittest_web.py --- a/web/test/unittest_web.py Fri Jul 11 13:48:07 2014 +0200 +++ b/web/test/unittest_web.py Fri Jul 11 16:44:42 2014 +0200 @@ -18,6 +18,7 @@ from json import loads from os.path import join +import tempfile try: import requests @@ -103,6 +104,21 @@ webreq = self.web_request(headers=headers) self.assertIn('lang="en"', webreq.read()) +class LogQueriesTC(CubicWebServerTC): + @classmethod + def init_config(cls, config): + super(LogQueriesTC, cls).init_config(config) + cls.logfile = tempfile.NamedTemporaryFile() + config.global_set_option('query-log-file', cls.logfile.name) + + def test_log_queries(self): + self.web_request() + self.assertTrue(self.logfile.read()) + + @classmethod + def tearDownClass(cls): + cls.logfile.close() + if __name__ == '__main__': unittest_main()