def test_set_plugin_source_conf_valid(factories): library = factories["music.Library"](actor__local=True) _plugins = {} plugins.get_plugin_config( "test", source=True, registry=_plugins, conf=[{ "name": "foo", "type": "boolean" }], ) plugins.set_conf( "test", { "foo": True, "library": library.uuid }, user=library.actor.user, registry=_plugins, ) conf = models.PluginConfiguration.objects.latest("id") assert conf.code == "test" assert conf.conf == {"foo": True, "library": str(library.uuid)} assert conf.user == library.actor.user
def test_set_plugin_conf_validates(): _plugins = {} plugins.get_plugin_config("test", registry=_plugins, conf=[{ "name": "foo", "type": "boolean" }]) with pytest.raises(serializers.ValidationError): plugins.set_conf("test", {"foo": "noop"}, registry=_plugins)
def create(self, request, *args, **kwargs): user = request.user confs = plugins.get_confs(user=user) user_plugin = [ p for p in plugins._plugins.values() if p["user"] is True and p["name"] == kwargs["pk"] ] if kwargs["pk"] not in confs: return response.Response(status=404) plugins.set_conf(kwargs["pk"], request.data, user) return response.Response( plugins.serialize_plugin(user_plugin[0], confs=plugins.get_confs(user=user)))
def test_set_plugin_conf_valid(): _plugins = {} plugins.get_plugin_config("test", registry=_plugins, conf=[{ "name": "foo", "type": "boolean" }]) plugins.set_conf("test", {"foo": True}, registry=_plugins) conf = models.PluginConfiguration.objects.latest("id") assert conf.code == "test" assert conf.conf == {"foo": True} assert conf.user is None
def test_set_plugin_source_conf_invalid(factories): user = factories["users.User"]() _plugins = {} plugins.get_plugin_config( "test", source=True, registry=_plugins, conf=[{ "name": "foo", "type": "boolean" }], ) with pytest.raises(serializers.ValidationError): plugins.set_conf("test", {"foo": True}, user=user, registry=_plugins)
def test_set_plugin_conf_valid_user(factories): user = factories["users.User"]() _plugins = {} plugins.get_plugin_config("test", registry=_plugins, conf=[{ "name": "foo", "type": "boolean" }]) plugins.set_conf("test", {"foo": True}, user=user, registry=_plugins) conf = models.PluginConfiguration.objects.latest("id") assert conf.code == "test" assert conf.conf == {"foo": True} assert conf.user == user
def test_can_disable_user_plugin(logged_in_api_client): plugins.get_plugin_config( name="test_plugin", description="Hello world", conf=[{ "name": "foo", "type": "boolean" }], user=True, ) plugins.set_conf("test_plugin", {"foo": True}, user=logged_in_api_client.user) url = reverse("api:v1:plugins-disable", kwargs={"pk": "test_plugin"}) response = logged_in_api_client.post(url) assert response.status_code == 200 assert logged_in_api_client.user.plugins.latest("id").enabled is False
def test_can_destroy_user_plugin(logged_in_api_client): plugins.get_plugin_config( name="test_plugin", description="Hello world", conf=[{ "name": "foo", "type": "boolean" }], user=True, ) plugins.set_conf("test_plugin", {"foo": True}, user=logged_in_api_client.user) plugins.get_plugin_config(name="test_plugin2", user=False) url = reverse("api:v1:plugins-detail", kwargs={"pk": "test_plugin"}) response = logged_in_api_client.delete(url, {"enabled": True}) assert response.status_code == 204 with pytest.raises(models.PluginConfiguration.DoesNotExist): assert logged_in_api_client.user.plugins.latest("id")
def test_can_trigger_scan(logged_in_api_client, mocker, factories): library = factories["music.Library"]( actor=logged_in_api_client.user.create_actor()) plugin = plugins.get_plugin_config( name="test_plugin", description="Hello world", conf=[], source=True, ) handler = mocker.Mock() plugins.register_hook(plugins.SCAN, plugin)(handler) plugins.set_conf("test_plugin", {"library": library.uuid}, user=logged_in_api_client.user) url = reverse("api:v1:plugins-scan", kwargs={"pk": "test_plugin"}) plugins.enable_conf("test_plugin", True, logged_in_api_client.user) response = logged_in_api_client.post(url) assert response.status_code == 200 handler.assert_called_once_with(library=library, conf={"library": str(library.uuid)})