cubicweb/web/test/unittest_web.py
changeset 11159 b07406dae25e
parent 11157 42fa15632493
child 11909 244cd7f407b8
equal deleted inserted replaced
11158:669eac69ea21 11159:b07406dae25e
    26     assert [int(n) for n in requests.__version__.split('.', 2)][:2] >= [1, 2]
    26     assert [int(n) for n in requests.__version__.split('.', 2)][:2] >= [1, 2]
    27 except (ImportError, AssertionError):
    27 except (ImportError, AssertionError):
    28     requests = None
    28     requests = None
    29 
    29 
    30 from logilab.common.testlib import TestCase, unittest_main
    30 from logilab.common.testlib import TestCase, unittest_main
    31 from cubicweb.devtools.httptest import CubicWebServerTC
    31 from cubicweb.devtools.httptest import CubicWebWsgiTC
    32 from cubicweb.devtools.fake import FakeRequest
    32 from cubicweb.devtools.fake import FakeRequest
    33 
    33 
    34 class AjaxReplaceUrlTC(TestCase):
    34 class AjaxReplaceUrlTC(TestCase):
    35 
    35 
    36     def test_ajax_replace_url_1(self):
    36     def test_ajax_replace_url_1(self):
    54             '{pageid: "%s"},"get","replace"); }' %
    54             '{pageid: "%s"},"get","replace"); }' %
    55             (cbname, qs, req.pageid),
    55             (cbname, qs, req.pageid),
    56             req.html_headers.post_inlined_scripts[0])
    56             req.html_headers.post_inlined_scripts[0])
    57 
    57 
    58 
    58 
    59 class FileUploadTC(CubicWebServerTC):
    59 class FileUploadTC(CubicWebWsgiTC):
    60 
    60 
    61     def setUp(self):
    61     def setUp(self):
    62         "Skip whole test class if a suitable requests module is not available"
    62         "Skip whole test class if a suitable requests module is not available"
    63         if requests is None:
    63         if requests is None:
    64             self.skipTest('Python ``requests`` module is not available')
    64             self.skipTest('Python ``requests`` module is not available')
    99                             ['views.py', self._fhash('views.py')]],}
    99                             ['views.py', self._fhash('views.py')]],}
   100         self.assertEqual(webreq.status_code, 200)
   100         self.assertEqual(webreq.status_code, 200)
   101         self.assertDictEqual(expect, loads(webreq.text))
   101         self.assertDictEqual(expect, loads(webreq.text))
   102 
   102 
   103 
   103 
   104 class LanguageTC(CubicWebServerTC):
   104 class LanguageTC(CubicWebWsgiTC):
   105 
   105 
   106     def test_language_neg(self):
   106     def test_language_neg(self):
   107         headers = {'Accept-Language': 'fr'}
   107         headers = {'Accept-Language': 'fr'}
   108         webreq = self.web_request(headers=headers)
   108         webreq = self.web_request(headers=headers)
   109         self.assertIn('lang="fr"', webreq.read())
   109         self.assertIn(b'lang="fr"', webreq.read())
   110         vary = [h.lower().strip() for h in webreq.getheader('Vary').split(',')]
   110         vary = [h.lower().strip() for h in webreq.getheader('Vary').split(',')]
   111         self.assertIn('accept-language', vary)
   111         self.assertIn('accept-language', vary)
   112         headers = {'Accept-Language': 'en'}
   112         headers = {'Accept-Language': 'en'}
   113         webreq = self.web_request(headers=headers)
   113         webreq = self.web_request(headers=headers)
   114         self.assertIn('lang="en"', webreq.read())
   114         self.assertIn(b'lang="en"', webreq.read())
   115         vary = [h.lower().strip() for h in webreq.getheader('Vary').split(',')]
   115         vary = [h.lower().strip() for h in webreq.getheader('Vary').split(',')]
   116         self.assertIn('accept-language', vary)
   116         self.assertIn('accept-language', vary)
   117 
   117 
   118     def test_response_codes(self):
   118     def test_response_codes(self):
   119         with self.admin_access.client_cnx() as cnx:
   119         with self.admin_access.client_cnx() as cnx:
   130     def test_session_cookie_httponly(self):
   130     def test_session_cookie_httponly(self):
   131         webreq = self.web_request()
   131         webreq = self.web_request()
   132         self.assertIn('HttpOnly', webreq.getheader('set-cookie'))
   132         self.assertIn('HttpOnly', webreq.getheader('set-cookie'))
   133 
   133 
   134 
   134 
   135 class MiscOptionsTC(CubicWebServerTC):
   135 class MiscOptionsTC(CubicWebWsgiTC):
   136     @classmethod
   136     @classmethod
   137     def setUpClass(cls):
   137     def setUpClass(cls):
   138         super(MiscOptionsTC, cls).setUpClass()
   138         super(MiscOptionsTC, cls).setUpClass()
   139         cls.logfile = tempfile.NamedTemporaryFile()
   139         cls.logfile = tempfile.NamedTemporaryFile()
   140 
   140 
   149         self.web_request()
   149         self.web_request()
   150         self.assertTrue(self.logfile.read())
   150         self.assertTrue(self.logfile.read())
   151 
   151 
   152     def test_datadir_url(self):
   152     def test_datadir_url(self):
   153         webreq = self.web_request()
   153         webreq = self.web_request()
   154         self.assertNotIn('/data/', webreq.read())
   154         self.assertNotIn(b'/data/', webreq.read())
   155 
   155 
   156     @classmethod
   156     @classmethod
   157     def tearDownClass(cls):
   157     def tearDownClass(cls):
   158         super(MiscOptionsTC, cls).tearDownClass()
   158         super(MiscOptionsTC, cls).tearDownClass()
   159         cls.logfile.close()
   159         cls.logfile.close()