Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
retribute.me
api
Commits
8d63838b
Verified
Commit
8d63838b
authored
Jun 09, 2019
by
Eliot Berriot
Browse files
Added support for PeerTube activitypub profiles
parent
672a1940
Changes
4
Hide whitespace changes
Inline
Side-by-side
config/routing.py
View file @
8d63838b
...
...
@@ -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
),
...
...
retribute_api/search/activitypub.py
View file @
8d63838b
...
...
@@ -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
)
retribute_api/search/sources.py
View file @
8d63838b
...
...
@@ -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
()
...
...
tests/search/test_consumers.py
View file @
8d63838b
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment