def test_websockets_queue(self): handler = self._create_handler() message = 'a message' assert handler.queue.empty() self.io_loop.run_sync(partial(handler.on_message, message), get_async_test_timeout()) assert not handler.queue.empty() assert message == self.io_loop.run_sync(handler.recv, get_async_test_timeout()) assert handler.queue.empty()
def gen_test(func=None, timeout=None): ''' An implementation of :func:`tornado.testing.gen_test` for :func:`@greenado.groutine <greenado.concurrent.groutine>` Example:: def something_that_yields(): greenado.gyield(something()) class MyTest(AsyncTestCase): @greenado.testing.gen_test def test_something(self): something_that_yields() ''' if func is None: return functools.partial(gen_test, timeout=timeout) if timeout is None: timeout = get_async_test_timeout() @functools.wraps(func) def wrapper(self, *args, **kwargs): return self.io_loop.run_sync( functools.partial(greenado.gcall, func, self, *args, **kwargs), timeout=timeout) return wrapper
def test_assert_callback_handler_gets_called(self): handler = self._create_handler() handler.subscription_server = MagicMock() handler.subscription_server.handle = MagicMock() handler.subscription_server.handle.assert_not_called() self.io_loop.run_sync(handler.open, get_async_test_timeout()) handler.subscription_server.handle.assert_called_once()
def test_unauthenticated_request_http_403_error(self) -> None: """ When the user is not logged-in, the open function for WebSockets should raise an HTTPError with status code 403. """ handler = self._create_handler(logged_in=False) with self.assertRaises(HTTPError) as cm: self.io_loop.run_sync(handler.open, get_async_test_timeout()) assert 403 == cm.exception.status_code
def fetch_request(self, request): return self.io_loop.run_sync( lambda: self.http_client.fetch(request, raise_error=False), timeout=get_async_test_timeout(), )
import shortuuid from tornado import testing import kiwipy.rmq import plumpy import plumpy.communications from plumpy import process_comms, test_utils from .. import utils from six.moves import range try: import pika except ImportError: pika = None AWAIT_TIMEOUT = testing.get_async_test_timeout() @unittest.skipIf(not pika, "Requires pika library and RabbitMQ") class TestRemoteProcessController(utils.AsyncTestCase): def setUp(self): super(TestRemoteProcessController, self).setUp() self.init_communicator() self.process_controller = process_comms.RemoteProcessController( self.communicator) def tearDown(self): # Close the connector before calling super because it will # close the loop self.communicator.stop()
def tearDown(self): self.http_server.stop() self.io_loop.run_sync(self.http_server.close_all_connections, timeout=get_async_test_timeout()) super(AsyncHTTPTestCase, self).tearDown()
def post(self, url, args): return self.io_loop.run_sync( lambda: self.apost(url, args), timeout=get_async_test_timeout())
def get(self, url): return self.io_loop.run_sync( lambda: self.aget(url), timeout=get_async_test_timeout())
from ssim import compute_ssim from tornado.testing import AsyncHTTPTestCase, get_async_test_timeout from tornado.httpclient import HTTPRequest from thumbor.config import Config from thumbor.context import Context, ServerParameters from thumbor.importer import Importer from thumbor.utils import logger from shutil import which from wikimedia_thumbor.app import App # AsyncHTTPTestCase doesn't set request_timeout HTTPRequest._DEFAULTS['request_timeout'] = get_async_test_timeout() class WikimediaTestCase(AsyncHTTPTestCase): def get_config(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.STORAGE = 'thumbor.storages.no_storage' cfg.LOADER = 'wikimedia_thumbor.loader.file' cfg.LOADER_EXCERPT_LENGTH = 4096 cfg.HTTP_LOADER_REQUEST_TIMEOUT = 60 cfg.HTTP_LOADER_TEMP_FILE_TIMEOUT = 20 cfg.FILE_LOADER_ROOT_PATH = os.path.join( os.path.dirname(__file__),