コード例 #1
0
    def test_can_run_main(
        self,
        ioloop_mock,
        get_server_parameters_mock,
        server_mock,
        setup_signal_handler_mock,
    ):
        server_parameters = mock.Mock(
            config_path="./tests/fixtures/thumbor_config_server_test.conf",
            log_level="DEBUG",
            debug=False,
            security_key="sec",
            app_class="thumbor.app.ThumborServiceApp",
            fd=None,
            ip="0.0.0.0",
            port=1234,
        )
        get_server_parameters_mock.return_value = server_parameters

        ioloop_instance_mock = mock.Mock()
        ioloop_mock.return_value = ioloop_instance_mock
        main()
        ioloop_instance_mock.start.assert_any_call()
        self.assertTrue(setup_signal_handler_mock.called)
        self.assertTrue(server_mock.called)
コード例 #2
0
ファイル: test_server.py プロジェクト: damaestro/thumbor
    def test_main_exits_on_keyboard_interrupt(self, stdout_mock, ioloop_mock, get_server_parameters_mock, server_mock):
        server_parameters = mock.Mock(
            config_path='./tests/fixtures/thumbor_config_server_test.conf',
            log_level='DEBUG',
            security_key='sec',
            app_class='thumbor.app.ThumborServiceApp',
            fd=None,
            ip='0.0.0.0',
            port=1234,
        )
        get_server_parameters_mock.return_value = server_parameters

        old_cleanup = BaseEngine.cleanup
        BaseEngine.cleanup = self.cleanup
        ServerTestCase.cleanup_called = False

        ioloop_instance_mock = mock.Mock()
        ioloop_mock.return_value = ioloop_instance_mock
        ioloop_instance_mock.start.side_effect = KeyboardInterrupt()

        main()

        stdout_mock.write.assert_called_with('-- thumbor closed by user interruption --\n')
        self.assertTrue(ServerTestCase.cleanup_called)

        BaseEngine.cleanup = old_cleanup
コード例 #3
0
ファイル: test_server.py プロジェクト: thewhit/thumbor
    def test_main_exits_on_keyboard_interrupt(self, stdout_mock, ioloop_mock,
                                              get_server_parameters_mock,
                                              server_mock):
        server_parameters = mock.Mock(
            config_path='./tests/fixtures/thumbor_config_server_test.conf',
            log_level='DEBUG',
            security_key='sec',
            app_class='thumbor.app.ThumborServiceApp',
            fd=None,
            ip='0.0.0.0',
            port=1234,
        )
        get_server_parameters_mock.return_value = server_parameters

        old_cleanup = BaseEngine.cleanup
        BaseEngine.cleanup = self.cleanup
        ServerTestCase.cleanup_called = False

        ioloop_instance_mock = mock.Mock()
        ioloop_mock.return_value = ioloop_instance_mock
        ioloop_instance_mock.start.side_effect = KeyboardInterrupt()

        main()

        stdout_mock.write.assert_called_with(
            '-- thumbor closed by user interruption --\n')
        self.assertTrue(ServerTestCase.cleanup_called)

        BaseEngine.cleanup = old_cleanup
コード例 #4
0
ファイル: test_server.py プロジェクト: damaestro/thumbor
    def test_can_run_main(self, ioloop_mock, get_server_parameters_mock, server_mock):
        server_parameters = mock.Mock(
            config_path='./tests/fixtures/thumbor_config_server_test.conf',
            log_level='DEBUG',
            security_key='sec',
            app_class='thumbor.app.ThumborServiceApp',
            fd=None,
            ip='0.0.0.0',
            port=1234,
        )
        get_server_parameters_mock.return_value = server_parameters

        ioloop_instance_mock = mock.Mock()
        ioloop_mock.return_value = ioloop_instance_mock
        main()
        ioloop_instance_mock.start.assert_any_call()
コード例 #5
0
    def test_can_run_main(self, ioloop_mock, get_server_parameters_mock, server_mock):
        server_parameters = mock.Mock(
            config_path='./tests/fixtures/thumbor_config_server_test.conf',
            log_level='DEBUG',
            security_key='sec',
            app_class='thumbor.app.ThumborServiceApp',
            fd=None,
            ip='0.0.0.0',
            port=1234,
        )
        get_server_parameters_mock.return_value = server_parameters

        ioloop_instance_mock = mock.Mock()
        ioloop_mock.return_value = ioloop_instance_mock
        main()
        ioloop_instance_mock.start.assert_any_call()
コード例 #6
0
@tornado.gen.coroutine
def on_after_upload(sender, **kwargs):
    location_header = kwargs['location_header']
    print('async call due to after_upload event')
    method = u'POST'  # TODO support PUT and DELETE
    # TODO ensure Redis client uses a connection pool that survives network issues
    try:
        redisclient = Redis(host=redis_config['host'],
                            port=redis_config['port'],
                            db=redis_config['db'],
                            password=redis_config['password'])
        msg = {'method': method, 'location': location_header}
        json_msg = json.dumps(msg)
        redisclient.publish(redis_config['channelName'], json_msg)
        print('Published event to Redis: %s' % str(json_msg))
    except Exception:
        print('Failed to publish event to Redis')


def on_after_server_run(sender, **kwargs):
    print('sync call after server is running')


Events.subscribe(Events.Engine.resize, on_resize)
Events.subscribe(Events.Imaging.before_upload_image, on_before_upload)
Events.subscribe(Events.Imaging.after_upload_image, on_after_upload)
Events.subscribe(Events.Server.after_server_run, on_after_server_run)

server.main()