def test_missing_client(self, bg_system): """Create a Plugin with no client, set it once, but never change""" # Don't use the plugin fixture as it already has a client plug = Plugin(bg_host="localhost", system=bg_system) with pytest.raises(AttributeError): plug.run()
def plugin(client, ez_client, bg_system, bg_instance, admin_processor, request_processor): plugin = Plugin(client, bg_host="localhost", system=bg_system) plugin._instance = bg_instance plugin._admin_processor = admin_processor plugin._request_processor = request_processor return plugin
def plugin(client, bm_client, parser, bg_system, bg_instance): plugin = Plugin(client, bg_host="localhost", system=bg_system, metadata={"foo": "bar"}) plugin.instance = bg_instance plugin.bm_client = bm_client plugin.parser = parser return plugin
def test_system_attributes_from_client(self, client): """Test that @system decorator and client docstring are used""" client._bg_name = "name" client._bg_version = "1.0.0" client.__doc__ = "Description\nSome more stuff" # Don't use plugin fixture as the _system name, version, doc are already set p = Plugin(bg_host="localhost") p.client = client assert p._system.name == "name" assert p._system.version == "1.0.0" assert p._system.description == "Description"
def test_existing_config(self, caplog, bg_system): brewtils.plugin.CONFIG.foo = "bar" with caplog.at_level(logging.WARNING): Plugin(bg_host="localhost", system=bg_system) assert "Global CONFIG" in caplog.messages[0]
def test_unspecified(self, client, ez_client): expected_namespace = "foo" ez_client.get_config.return_value = {"garden_name": expected_namespace} plugin = Plugin(client, bg_host="localhost") self._validate_namespace(plugin, expected_namespace)
def test_from_system(self, client, bg_system): expected_namespace = "foo" bg_system.namespace = expected_namespace plugin = Plugin(client, bg_host="localhost", system=bg_system) self._validate_namespace(plugin, expected_namespace)
def test_from_config(self, client): expected_namespace = "foo" plugin = Plugin(client, bg_host="localhost", namespace=expected_namespace) self._validate_namespace(plugin, expected_namespace)
def test_init_with_instance_name_unique_name_check(self, client, bg_system, instance_name, expected_unique): plugin = Plugin(client, bg_host="localhost", system=bg_system, instance_name=instance_name) assert expected_unique == plugin.unique_name
def test_client_setter(self, client, bg_system): """Create a Plugin with no client, set it once, but never change""" # Don't use the plugin fixture as it already has a client p = Plugin(bg_host="localhost", system=bg_system) assert p.client is None # Can set to None if already None p.client = None assert p.client is None p.client = client assert p.client == client with pytest.raises(AttributeError): p.client = None # Should still be the same client assert p.client == client
def test_deprecation(self, client): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("ignore") warnings.filterwarnings("always", module="brewtils.plugin") Plugin(client, bg_host="localhost") assert issubclass(w[0].category, PendingDeprecationWarning) assert "max_concurrent" in str(w[0].message)
def test_env(self, client, bg_system): os.environ["BG_HOST"] = "remotehost" os.environ["BG_PORT"] = "7332" os.environ["BG_URL_PREFIX"] = "/beer/" os.environ["BG_SSL_ENABLED"] = "False" os.environ["BG_CA_VERIFY"] = "False" plugin = Plugin(client, system=bg_system, max_concurrent=1) assert plugin.bg_host == "remotehost" assert plugin.bg_port == 7332 assert plugin.bg_url_prefix == "/beer/" assert plugin.ssl_enabled is False assert plugin.ca_verify is False
def plugin(client, bm_client, parser, bg_system, bg_instance, admin_consumer, request_consumer): plugin = Plugin( client, bg_host="localhost", system=bg_system, metadata={"foo": "bar"}, max_concurrent=1, ) plugin.instance = bg_instance plugin.bm_client = bm_client plugin.parser = parser plugin.admin_consumer = admin_consumer plugin.request_consumer = request_consumer plugin.queue_connection_params = {} return plugin
def test_default_logger(self, monkeypatch, client): """Test that the default logging configuration is used. This needs to be tested separately because pytest (understandably) does some logging configuration before starting tests. Since we only configure logging if there's no prior configuration we have to fake it a little. """ plugin_logger = logging.getLogger("brewtils.plugin") dict_config = Mock() monkeypatch.setattr(plugin_logger, "root", Mock(handlers=[])) monkeypatch.setattr(logging.config, "dictConfig", dict_config) plugin = Plugin(client, bg_host="localhost", max_concurrent=1) dict_config.assert_called_once_with(DEFAULT_LOGGING_CONFIG) assert logging.getLogger("brewtils.plugin") == plugin.logger
def test_kwargs(self, client, bg_system): logger = Mock() plugin = Plugin( client, bg_host="host1", bg_port=2338, bg_url_prefix="/beer/", system=bg_system, ssl_enabled=False, ca_verify=False, logger=logger, ) assert plugin.bg_host == "host1" assert plugin.bg_port == 2338 assert plugin.bg_url_prefix == "/beer/" assert plugin.ssl_enabled is False assert plugin.ca_verify is False assert plugin.logger == logger
def test_cli(self, client, bg_system): args = [ "--bg-host", "remotehost", "--bg-port", "2338", "--url-prefix", "beer", "--no-ssl-enabled", "--no-ca-verify", ] plugin = Plugin(client, system=bg_system, **get_connection_info(cli_args=args)) assert plugin.bg_host == "remotehost" assert plugin.bg_port == 2338 assert plugin.bg_url_prefix == "/beer/" assert plugin.ssl_enabled is False assert plugin.ca_verify is False
def test_conflicts(self, client, bg_system): os.environ["BG_HOST"] = "remotehost" os.environ["BG_PORT"] = "7332" os.environ["BG_URL_PREFIX"] = "/tea/" os.environ["BG_SSL_ENABLED"] = "False" os.environ["BG_CA_VERIFY"] = "False" plugin = Plugin( client, bg_host="localhost", bg_port=2337, bg_url_prefix="/beer/", system=bg_system, ssl_enabled=True, ca_verify=True, ) assert plugin.bg_host == "localhost" assert plugin.bg_port == 2337 assert plugin.bg_url_prefix == "/beer/" assert plugin.ssl_enabled is True assert plugin.ca_verify is True
def test_no_bg_host(self, client): with pytest.raises(ValidationError): Plugin(client)