Skip to content
Snippets Groups Projects
Verified Commit 8d63838b authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added support for PeerTube activitypub profiles

parent 672a1940
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ application = ProtocolTypeRouter(
url(r"^v1/providers$", consumers.ProvidersConsumer),
url(r"^v1/search/$", consumers.SearchMultipleConsumer),
url(
r"^v1/search/(?P<lookup_type>.+):(?P<lookup>.+)$",
r"^v1/search/(?P<lookup_type>[^:]+):(?P<lookup>.+)$",
consumers.SearchSingleConsumer,
),
url(r"", AsgiHandler),
......
......@@ -64,4 +64,4 @@ class ActorSerializer(serializers.Serializer):
attachment = serializers.ListField(
child=AttachmentSerializer(), min_length=0, required=False
)
tag = serializers.ListField(child=TagSerializer(), min_length=0)
tag = serializers.ListField(child=TagSerializer(), min_length=0, required=False)
......@@ -53,7 +53,7 @@ class Activitypub(Source):
await cache.set("activitypub:profile:{}".format(lookup), actor_data)
serializer = activitypub.ActorSerializer(data=actor_data)
serializer.is_valid(raise_exception=True)
for tag in serializer.validated_data["tag"]:
for tag in serializer.validated_data.get("tag", []):
if tag["name"].lower() in self.excluded_tags:
raise exceptions.SkippedProfile()
......
......@@ -34,6 +34,31 @@ async def test_search_consumer_success(
assert response["body"] == json.dumps(expected, indent=2, sort_keys=True).encode()
async def test_search_consumer_activitypub(
loop, application, mocker, coroutine_mock, dummycache
):
get = mocker.patch.object(sources.Activitypub, "get", coroutine_mock())
expected = {"dummy": "json"}
get_profile = mocker.patch.object(
sources, "result_to_retribute_profile", return_value=expected
)
communicator = HttpCommunicator(
application, "GET", "/v1/search/activitypub:https://test.domain"
)
response = await communicator.get_response()
assert get.call_args[0][0] == "https://test.domain"
assert get.call_args[1]["cache"] == dummycache
get_profile.assert_called_once_with(
"activitypub", "https://test.domain", get.return_value
)
assert response["status"] == 200
assert response["headers"] == [
(b"Content-Type", b"application/json"),
(b"Access-Control-Allow-Origin", b"*"),
]
assert response["body"] == json.dumps(expected, indent=2, sort_keys=True).encode()
async def test_search_consumer_no_cache(
loop, application, mocker, coroutine_mock, dummycache
):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment