kopia lustrzana https://gitlab.com/jaywink/federation
Tweak activitypub_object_view process_payload call signature
Now passes `response.content` as is and also passes in the request object.merge-requests/135/head
rodzic
331421c216
commit
aff1a8e59e
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
When used, a few extra settings must be given in the Django `FEDERATION` configuration dictionary.
|
When used, a few extra settings must be given in the Django `FEDERATION` configuration dictionary.
|
||||||
* `get_object_function` should contain the Python path to a function that takes an ActivityPub ID and returns an object matching the ID or `None`.
|
* `get_object_function` should contain the Python path to a function that takes an ActivityPub ID and returns an object matching the ID or `None`.
|
||||||
* `process_payload_function` should contain the Python path to a function that takes in a federation payload and processes it. It should return `True` if successful (or placed in queue for processing later) or `False` in case of any errors.
|
* `process_payload_function` should contain the Python path to a function that takes in a federation payload and request object. It should return `True` if successful (or placed in queue for processing later) or `False` in case of any errors.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ Some settings need to be set in Django settings. An example is below:
|
||||||
}
|
}
|
||||||
openRegistrations
|
openRegistrations
|
||||||
|
|
||||||
* ``process_payload_function`` (optional) function that takes in a federation payload and processes it. It should return ``True`` if successful (or placed in queue for processing later) or ``False`` in case of any errors.
|
* ``process_payload_function`` (optional) function that takes in a federation payload and request object. It should return ``True`` if successful (or placed in queue for processing later) or ``False`` in case of any errors.
|
||||||
* ``search_path`` (optional) site search path which ends in a parameter for search input, for example "/search?q="
|
* ``search_path`` (optional) site search path which ends in a parameter for search input, for example "/search?q="
|
||||||
|
|
||||||
Protocols
|
Protocols
|
||||||
|
|
|
@ -38,8 +38,7 @@ def activitypub_object_view(func):
|
||||||
|
|
||||||
def post(request, *args, **kwargs):
|
def post(request, *args, **kwargs):
|
||||||
process_payload_function = get_function_from_config('process_payload_function')
|
process_payload_function = get_function_from_config('process_payload_function')
|
||||||
payload = json.loads(request.body)
|
result = process_payload_function(request.body, request)
|
||||||
result = process_payload_function(payload)
|
|
||||||
if result:
|
if result:
|
||||||
return JsonResponse({}, content_type='application/json', status=202)
|
return JsonResponse({}, content_type='application/json', status=202)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TestActivityPubObjectView:
|
||||||
response = dummy_view(request=request)
|
response = dummy_view(request=request)
|
||||||
|
|
||||||
assert response.status_code == 202
|
assert response.status_code == 202
|
||||||
mock_func.assert_called_once_with({"foo": "bar"})
|
mock_func.assert_called_once_with(b'{"foo": "bar"}', request)
|
||||||
|
|
||||||
@patch("federation.entities.activitypub.django.views.get_function_from_config")
|
@patch("federation.entities.activitypub.django.views.get_function_from_config")
|
||||||
def test_receives_messages_to_inbox__cbv(self, mock_get_config):
|
def test_receives_messages_to_inbox__cbv(self, mock_get_config):
|
||||||
|
@ -58,7 +58,7 @@ class TestActivityPubObjectView:
|
||||||
response = view(request=request)
|
response = view(request=request)
|
||||||
|
|
||||||
assert response.status_code == 202
|
assert response.status_code == 202
|
||||||
mock_func.assert_called_once_with({"foo": "bar"})
|
mock_func.assert_called_once_with(b'{"foo": "bar"}', request)
|
||||||
|
|
||||||
@pytest.mark.parametrize('content_type', (
|
@pytest.mark.parametrize('content_type', (
|
||||||
'application/json', 'application/activity+json', 'application/ld+json',
|
'application/json', 'application/activity+json', 'application/ld+json',
|
||||||
|
|
Ładowanie…
Reference in New Issue