def test_config_interface_fail_when_neither_tcp_nor_unix(): config = Config(importlib.import_module('tests.settings6'), ArgumentParser()) with pytest.raises(ValueError) as e: _ = config.interfaces assert "Interface MUST listen either on TCP or UNIX socket" in str(e)
def test_config_interfaces_both_tcp_and_unix(): config = Config(importlib.import_module('tests.settings5'), ArgumentParser()) interface = config.interfaces[0] assert interface.name == 'http_both_tcp_and_unix' assert interface.host == '' assert interface.port == 4443 assert interface.unix_socket == '/tmp/tornado.socket'
def test_null_handler(): with mock.patch.object(NullHandler, '__init__', return_value=None), \ mock.patch.object(NullHandler, 'write') as m_write, \ mock.patch.object(NullHandler, 'set_header') as m_set_header: h = NullHandler() h.initialize(context=object(), interface=Config.Interface('foo', '', 1, 0, [])) h.get() m_write.assert_called_once_with("Interface 'foo' works!\n") m_set_header.assert_called_once_with("Content-Type", "text/plain; charset=UTF-8")
def test_config_interfaces(): config = Config(importlib.import_module('tests.settings1'), ArgumentParser()) interfaces = sorted(config.interfaces, key=lambda x: x.name) assert len(interfaces) == 2 assert interfaces[0].name == 'fastrpc' assert interfaces[0].host == '192.168.1.0' assert interfaces[0].port == 4445 assert len(interfaces[0].urls) == 0 assert interfaces[1].name == 'http' assert interfaces[1].host == '' assert interfaces[1].port == 4443 assert len(interfaces[1].urls) == 2
def test_null_handler(): app = tornado.web.Application([], context=object(), interface=Config.Interface(name='foo', host='', port=1, unix_socket=None, processes=0, urls=[])) req = mock.Mock() with mock.patch.object(NullHandler, 'write') as m_write: with mock.patch.object(NullHandler, 'set_header') as m_set_header: h = NullHandler(app, req) h.get() m_write.assert_called_once_with("Interface 'foo' works!\n") m_set_header.assert_called_once_with("Content-Type", "text/plain; charset=UTF-8")
def test_get_tornado_apps(): config = Config( importlib.import_module('tests.settings1'), ArgumentParser() ) context = config.context_class.from_config(config) apps = sorted( get_tornado_apps(context), key=lambda x: x.settings['interface'].name) assert len(apps) == 2 assert isinstance(apps[0].settings['context'], Context) assert isinstance(apps[0].settings['interface'], Config.Interface) assert apps[0].settings['interface'].name == 'fastrpc' assert isinstance(apps[1].settings['context'], Context) assert isinstance(apps[1].settings['interface'], Config.Interface) assert apps[1].settings['interface'].name == 'http'
def test_config_context_class_user(): config = Config(importlib.import_module('tests.settings2'), ArgumentParser()) assert config.context_class is not Context assert config.context_class is ContextTest
def test_config_context_class_default(): config = Config(importlib.import_module('tests.settings1'), ArgumentParser()) assert config.context_class is Context
def test_config_cls(): config = Config(1, 2) assert "<shelter.core.config.Config: 0x" in repr(config) assert config.settings == 1 assert config.args_parser == 2