예제 #1
0
def test_serialize_plugin_user(factories):
    user = factories["users.User"]()
    plugin = plugins.get_plugin_config(
        name="test_plugin",
        description="Hello world",
        conf=[{
            "name": "foo",
            "type": "boolean"
        }],
        user=True,
    )

    expected = {
        "name": "test_plugin",
        "enabled": False,
        "description": "Hello world",
        "conf": [{
            "name": "foo",
            "type": "boolean"
        }],
        "user": True,
        "source": False,
        "label": "test_plugin",
        "values": None,
        "homepage": None,
    }

    assert plugins.serialize_plugin(plugin,
                                    plugins.get_confs(user)) == expected
예제 #2
0
파일: views.py 프로젝트: mayhem/funkwhale
    def list(self, request, *args, **kwargs):
        user = request.user
        user_plugins = [
            p for p in plugins._plugins.values() if p["user"] is True
        ]

        return response.Response([
            plugins.serialize_plugin(p, confs=plugins.get_confs(user=user))
            for p in user_plugins
        ])
예제 #3
0
파일: views.py 프로젝트: mayhem/funkwhale
    def retrieve(self, request, *args, **kwargs):
        user = request.user
        user_plugin = [
            p for p in plugins._plugins.values()
            if p["user"] is True and p["name"] == kwargs["pk"]
        ]
        if not user_plugin:
            return response.Response(status=404)

        return response.Response(
            plugins.serialize_plugin(user_plugin[0],
                                     confs=plugins.get_confs(user=user)))
예제 #4
0
파일: views.py 프로젝트: mayhem/funkwhale
    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)))
예제 #5
0
def test_can_update_user_plugin(logged_in_api_client):
    plugin = plugins.get_plugin_config(
        name="test_plugin",
        description="Hello world",
        conf=[{
            "name": "foo",
            "type": "boolean"
        }],
        user=True,
    )
    plugins.get_plugin_config(name="test_plugin2", user=False)
    url = reverse("api:v1:plugins-detail", kwargs={"pk": "test_plugin"})
    response = logged_in_api_client.post(url, {"foo": True})
    assert response.status_code == 200
    assert logged_in_api_client.user.plugins.latest("id").conf == {"foo": True}
    assert response.data == plugins.serialize_plugin(
        plugin, plugins.get_confs(logged_in_api_client.user))
예제 #6
0
def test_can_list_user_plugins(logged_in_api_client):
    plugin = plugins.get_plugin_config(
        name="test_plugin",
        description="Hello world",
        conf=[{
            "name": "foo",
            "type": "boolean"
        }],
        user=True,
    )
    plugins.get_plugin_config(name="test_plugin2", user=False)
    url = reverse("api:v1:plugins-list")
    response = logged_in_api_client.get(url)

    assert response.status_code == 200
    assert response.data == [
        plugins.serialize_plugin(plugin,
                                 plugins.get_confs(logged_in_api_client.user))
    ]
예제 #7
0
def test_serialize_plugin_user_enabled(factories):
    user = factories["users.User"]()
    plugin = plugins.get_plugin_config(
        name="test_plugin",
        description="Hello world",
        conf=[{
            "name": "foo",
            "type": "boolean"
        }],
        user=True,
        homepage="https://example.com",
    )

    factories["common.PluginConfiguration"](code="test_plugin",
                                            user=user,
                                            enabled=True,
                                            conf={
                                                "foo": "bar"
                                            })
    expected = {
        "name": "test_plugin",
        "enabled": True,
        "description": "Hello world",
        "conf": [{
            "name": "foo",
            "type": "boolean"
        }],
        "user": True,
        "source": False,
        "label": "test_plugin",
        "values": {
            "foo": "bar"
        },
        "homepage": "https://example.com",
    }

    assert plugins.serialize_plugin(plugin,
                                    plugins.get_confs(user)) == expected