def run(self): """Sets up test server and database and loops over handling http requests.""" try: handler = basehttp.AdminMediaHandler(WSGIHandler()) server_address = (self.address, self.port) httpd = basehttp.StoppableWSGIServer(server_address, basehttp.WSGIRequestHandler) httpd.set_app(handler) self.started.set() except basehttp.WSGIServerException, e: self.error = e self.started.set() return
def run(self): """Sets up test server and loops over handling http requests.""" try: handler = basehttp.AdminMediaHandler(WSGIHandler()) httpd = StoppableWSGIServer(self.server_addr, basehttp.WSGIRequestHandler) httpd.application = handler self.started.set() except basehttp.WSGIServerException, err: self.error = err self.started.set() return
def run(self): """ Sets up test server and database and loops over handling http requests. """ # Idea taken from: http://djangosnippets.org/snippets/2050/ class QuietWSGIRequestHandler(basehttp.WSGIRequestHandler): def log_message(self, format, *args): if verbose: return basehttp.WSGIRequestHandler.log_message( self, format, *args) try: handler = basehttp.AdminMediaHandler(WSGIHandler()) server_address = (self.address, self.port) httpd = basehttp.WSGIServer(server_address, QuietWSGIRequestHandler) httpd.set_app(handler) except basehttp.WSGIServerException, e: self._error = e
def run(self): try: handler = basehttp.AdminMediaHandler(WSGIHandler()) def test_app(environ, start_response): if environ['REQUEST_METHOD'] == 'HEAD': start_response('200 OK', []) return '' if environ['PATH_INFO'] == '/favicon.ico': start_response('404 Not Found', []) return '' return handler(environ, start_response) server_address = (self.address, self.port) httpd = StoppableWSGIServer(server_address, basehttp.WSGIRequestHandler) httpd.set_app(test_app) self._start_event.set() except basehttp.WSGIServerException, e: self.error = e self._start_event.set() return
def run(self): """ Sets up test server and database and loops over handling http requests. """ try: handler = basehttp.AdminMediaHandler(WSGIHandler()) server_address = (self.address, self.port) httpd = StoppableWSGIServer(server_address, WSGIRequestHandler) httpd.set_app(handler) self.started.set() except basehttp.WSGIServerException as e: self.error = e self.started.set() return # Must do database stuff in this new thread if database in memory. from django.conf import settings if hasattr(settings, 'DATABASES'): db_engine = settings.DATABASES['default']['ENGINE'] test_db_name = settings.DATABASES['default']['TEST_NAME'] else: db_engine = settings.DATABASE_ENGINE test_db_name = settings.TEST_DATABASE_NAME if (db_engine.endswith('sqlite3') and (not test_db_name or test_db_name == ':memory:')): # Import the fixture data into the test database. if hasattr(self, 'fixtures'): # We have to use this slightly awkward syntax due to the fact # that we're using *args and **kwargs together. testcases.call_command('loaddata', verbosity=0, *self.fixtures) # Loop until we get a stop event. while not self._stopevent.isSet(): httpd.handle_request()