cubicweb/devtools/test/unittest_httptest.py
changeset 11162 d60d181b2b17
parent 11161 dd1933f56f4e
child 12530 9d88e1177c35
equal deleted inserted replaced
11161:dd1933f56f4e 11162:d60d181b2b17
    18 """unittest for cubicweb.devtools.httptest module"""
    18 """unittest for cubicweb.devtools.httptest module"""
    19 
    19 
    20 from six.moves import http_client
    20 from six.moves import http_client
    21 
    21 
    22 from logilab.common.testlib import Tags
    22 from logilab.common.testlib import Tags
    23 from cubicweb.devtools.httptest import CubicWebServerTC
    23 from cubicweb.devtools.httptest import CubicWebServerTC, CubicWebWsgiTC
    24 
    24 
    25 
    25 
    26 class TwistedCWAnonTC(CubicWebServerTC):
    26 class TwistedCWAnonTC(CubicWebServerTC):
    27 
    27 
    28     def test_response(self):
    28     def test_response(self):
    61         self.web_logout()
    61         self.web_logout()
    62         response = self.web_get()
    62         response = self.web_get()
    63         self.assertEqual(response.status, http_client.FORBIDDEN, response.body)
    63         self.assertEqual(response.status, http_client.FORBIDDEN, response.body)
    64 
    64 
    65 
    65 
       
    66 class WsgiCWAnonTC(CubicWebWsgiTC):
       
    67 
       
    68     def test_response(self):
       
    69         try:
       
    70             response = self.web_get()
       
    71         except http_client.NotConnected as ex:
       
    72             self.fail("Can't connection to test server: %s" % ex)
       
    73 
       
    74     def test_response_anon(self):
       
    75         response = self.web_get()
       
    76         self.assertEqual(response.status, http_client.OK)
       
    77 
       
    78     def test_base_url(self):
       
    79         if self.config['base-url'] not in self.web_get().read().decode('ascii'):
       
    80             self.fail('no mention of base url in retrieved page')
       
    81 
       
    82 
       
    83 class WsgiCWIdentTC(CubicWebWsgiTC):
       
    84     test_db_id = 'httptest-cwident'
       
    85     anonymous_allowed = False
       
    86     tags = CubicWebServerTC.tags | Tags(('auth',))
       
    87 
       
    88     def test_response_denied(self):
       
    89         response = self.web_get()
       
    90         self.assertEqual(response.status, http_client.FORBIDDEN)
       
    91 
       
    92     def test_login(self):
       
    93         response = self.web_get()
       
    94         if response.status != http_client.FORBIDDEN:
       
    95             self.skipTest('Already authenticated, "test_response_denied" must have failed')
       
    96         # login
       
    97         self.web_login(self.admlogin, self.admpassword)
       
    98         response = self.web_get()
       
    99         self.assertEqual(response.status, http_client.OK, response.body)
       
   100         # logout
       
   101         self.web_logout()
       
   102         response = self.web_get()
       
   103         self.assertEqual(response.status, http_client.FORBIDDEN, response.body)
    66 
   104 
    67 
   105 
    68 if __name__ == '__main__':
   106 if __name__ == '__main__':
    69     from logilab.common.testlib import unittest_main
   107     from logilab.common.testlib import unittest_main
    70     unittest_main()
   108     unittest_main()