cubicweb/devtools/test/unittest_httptest.py
changeset 12530 9d88e1177c35
parent 11162 d60d181b2b17
child 12567 26744ad37953
equal deleted inserted replaced
12529:7276f1c89ddd 12530:9d88e1177c35
    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, CubicWebWsgiTC
    23 from cubicweb.devtools.httptest import CubicWebServerTC
    24 
    24 
    25 
    25 
    26 class TwistedCWAnonTC(CubicWebServerTC):
    26 class WsgiCWAnonTC(CubicWebServerTC):
    27 
    27 
    28     def test_response(self):
    28     def test_response(self):
    29         try:
    29         try:
    30             response = self.web_get()
    30             response = self.web_get()
    31         except http_client.NotConnected as ex:
    31         except http_client.NotConnected as ex:
    38     def test_base_url(self):
    38     def test_base_url(self):
    39         if self.config['base-url'] not in self.web_get().read().decode('ascii'):
    39         if self.config['base-url'] not in self.web_get().read().decode('ascii'):
    40             self.fail('no mention of base url in retrieved page')
    40             self.fail('no mention of base url in retrieved page')
    41 
    41 
    42 
    42 
    43 class TwistedCWIdentTC(CubicWebServerTC):
    43 class WsgiCWIdentTC(CubicWebServerTC):
    44     test_db_id = 'httptest-cwident'
       
    45     anonymous_allowed = False
       
    46     tags = CubicWebServerTC.tags | Tags(('auth',))
       
    47 
       
    48     def test_response_denied(self):
       
    49         response = self.web_get()
       
    50         self.assertEqual(response.status, http_client.FORBIDDEN)
       
    51 
       
    52     def test_login(self):
       
    53         response = self.web_get()
       
    54         if response.status != http_client.FORBIDDEN:
       
    55             self.skipTest('Already authenticated, "test_response_denied" must have failed')
       
    56         # login
       
    57         self.web_login(self.admlogin, self.admpassword)
       
    58         response = self.web_get()
       
    59         self.assertEqual(response.status, http_client.OK, response.body)
       
    60         # logout
       
    61         self.web_logout()
       
    62         response = self.web_get()
       
    63         self.assertEqual(response.status, http_client.FORBIDDEN, response.body)
       
    64 
       
    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'
    44     test_db_id = 'httptest-cwident'
    85     anonymous_allowed = False
    45     anonymous_allowed = False
    86     tags = CubicWebServerTC.tags | Tags(('auth',))
    46     tags = CubicWebServerTC.tags | Tags(('auth',))
    87 
    47 
    88     def test_response_denied(self):
    48     def test_response_denied(self):