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
Jason Robinson 2018-10-09 22:46:23 +03:00
rodzic 331421c216
commit aff1a8e59e
4 zmienionych plików z 5 dodań i 6 usunięć

Wyświetl plik

@ -14,7 +14,7 @@
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`.
* `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

Wyświetl plik

@ -139,7 +139,7 @@ Some settings need to be set in Django settings. An example is below:
}
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="
Protocols

Wyświetl plik

@ -38,8 +38,7 @@ def activitypub_object_view(func):
def post(request, *args, **kwargs):
process_payload_function = get_function_from_config('process_payload_function')
payload = json.loads(request.body)
result = process_payload_function(payload)
result = process_payload_function(request.body, request)
if result:
return JsonResponse({}, content_type='application/json', status=202)
else:

Wyświetl plik

@ -47,7 +47,7 @@ class TestActivityPubObjectView:
response = dummy_view(request=request)
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")
def test_receives_messages_to_inbox__cbv(self, mock_get_config):
@ -58,7 +58,7 @@ class TestActivityPubObjectView:
response = view(request=request)
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', (
'application/json', 'application/activity+json', 'application/ld+json',