def test_plugin_shutdown(mocker, unused_port): # GIVEN port = { 'description': 'Port to listen on', 'type': 'integer', 'default': str(unused_port()), } config_data = copy.deepcopy(config) mocker.patch.dict(config_data, {'port': port}) config_data['port']['value'] = config_data['port']['default'] config_data['host']['value'] = config_data['host']['default'] config_data['uri']['value'] = config_data['uri']['default'] config_data['enableHttp']['value'] = config_data['enableHttp']['default'] log_exception = mocker.patch.object(http_south._LOGGER, "exception") log_info = mocker.patch.object(http_south._LOGGER, "info") # WHEN http_south.plugin_start(config_data) http_south.plugin_shutdown(config_data) # THEN assert 3 == log_info.call_count calls = [ call('Stopping South HTTP plugin.'), call('South HTTP plugin shut down.') ] log_info.assert_has_calls(calls, any_order=True) assert 0 == log_exception.call_count
def test_plugin_shutdown_error(mocker, unused_port, loop): # GIVEN port = { 'description': 'Port to listen on', 'type': 'integer', 'default': str(unused_port()), } config_data = copy.deepcopy(config) mocker.patch.dict(config_data, {'port': port}) config_data['port']['value'] = config_data['port']['default'] config_data['host']['value'] = config_data['host']['default'] config_data['uri']['value'] = config_data['uri']['default'] config_data['enableHttp']['value'] = config_data['enableHttp']['default'] log_exception = mocker.patch.object(http_south._LOGGER, "exception") log_info = mocker.patch.object(http_south._LOGGER, "info") # WHEN http_south.plugin_start(config_data) server = config_data['server'] mocker.patch.object(server, 'wait_closed', side_effect=Exception) with pytest.raises(Exception): http_south.plugin_shutdown(config_data) # THEN assert 2 == log_info.call_count calls = [call('Stopping South HTTP plugin.')] log_info.assert_has_calls(calls, any_order=True) assert 1 == log_exception.call_count
def test_plugin_start_exception(unused_port, mocker): # GIVEN port = { 'description': 'Port to listen on', 'type': 'integer', 'default': str(unused_port()), } config_data = copy.deepcopy(config) mocker.patch.dict(config_data, {'port': port}) log_exception = mocker.patch.object(http_south._LOGGER, "exception") # WHEN http_south.plugin_start(config_data) # THEN assert 1 == log_exception.call_count log_exception.assert_called_with("'value'")
def test_plugin_start(mocker, unused_port): # GIVEN port = { 'description': 'Port to listen on', 'type': 'integer', 'default': str(unused_port()), } config_data = copy.deepcopy(config) mocker.patch.dict(config_data, {'port': port}) config_data['port']['value'] = config_data['port']['default'] config_data['host']['value'] = config_data['host']['default'] config_data['uri']['value'] = config_data['uri']['default'] config_data['enableHttp']['value'] = config_data['enableHttp']['default'] # WHEN http_south.plugin_start(config_data) # THEN assert isinstance(config_data['app'], aiohttp.web.Application) assert isinstance(config_data['handler'], aiohttp.web_server.Server) # assert isinstance(config_data['server'], asyncio.base_events.Server) http_south.loop.stop() http_south.t._delete()