devtools/httptest.py
brancholdstable
changeset 7074 e4580e5f0703
parent 7071 db7608cb32bc
child 7075 4751d77394b1
equal deleted inserted replaced
6749:48f468f33704 7074:e4580e5f0703
    87 
    87 
    88 class CubicWebServerTC(CubicWebTC):
    88 class CubicWebServerTC(CubicWebTC):
    89     """Class for running test web server. See :class:`CubicWebServerConfig`.
    89     """Class for running test web server. See :class:`CubicWebServerConfig`.
    90 
    90 
    91     Class attributes:
    91     Class attributes:
    92     * ` anonymous_logged`: flag telling ifs anonymous user should be log logged
    92     * `anonymous_allowed`: flag telling if anonymous browsing should be allowed
    93       by default (True by default)
       
    94     """
    93     """
    95     configcls = CubicWebServerConfig
    94     configcls = CubicWebServerConfig
    96     # anonymous is logged by default in cubicweb test cases
    95     # anonymous is logged by default in cubicweb test cases
    97     anonymous_logged = True
    96     anonymous_allowed = True
    98 
    97 
    99     def start_server(self):
    98     def start_server(self):
   100         # use a semaphore to avoid starting test while the http server isn't
    99         # use a semaphore to avoid starting test while the http server isn't
   101         # fully initilialized
   100         # fully initilialized
   102         semaphore = threading.Semaphore(0)
   101         semaphore = threading.Semaphore(0)
   174         response.body = response.read() # to chain request
   173         response.body = response.read() # to chain request
   175         response.read = lambda : response.body
   174         response.read = lambda : response.body
   176         return response
   175         return response
   177 
   176 
   178     def setUp(self):
   177     def setUp(self):
   179         CubicWebTC.setUp(self)
   178         super(CubicWebServerTC, self).setUp()
   180         self.start_server()
   179         self.start_server()
   181 
   180 
   182     def tearDown(self):
   181     def tearDown(self):
   183         try:
   182         try:
   184             self.stop_server()
   183             self.stop_server()
   185         except error.ReactorNotRunning, err:
   184         except error.ReactorNotRunning, err:
   186             # Server could be launched manually
   185             # Server could be launched manually
   187             print err
   186             print err
   188         CubicWebTC.tearDown(self)
   187         super(CubicWebServerTC, self).tearDown()
   189 
   188 
   190     @classmethod
   189     @classmethod
   191     def init_config(cls, config):
   190     def init_config(cls, config):
       
   191         config.set_anonymous_allowed(cls.anonymous_allowed)
   192         super(CubicWebServerTC, cls).init_config(config)
   192         super(CubicWebServerTC, cls).init_config(config)
   193         if not cls.anonymous_logged:
       
   194             config.global_set_option('anonymous-user', None)
       
   195         else:
       
   196             config.global_set_option('anonymous-user', 'anon')
       
   197             config.global_set_option('anonymous-password', 'anon')