From 882711a31a5767b1535bf15b560d14166a83c387 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Sun, 30 Sep 2018 17:15:31 +0300 Subject: [PATCH] Use right content types in activitypub_object_view decorator --- federation/entities/activitypub/django/views.py | 5 ++++- .../entities/activitypub/django/test_views.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/federation/entities/activitypub/django/views.py b/federation/entities/activitypub/django/views.py index 4ad2935..9f49a53 100644 --- a/federation/entities/activitypub/django/views.py +++ b/federation/entities/activitypub/django/views.py @@ -12,7 +12,10 @@ def activitypub_object_view(func): type doesn't match. """ def inner(request, *args, **kwargs): - if request.content_type not in ('application/json', 'application/activity+json'): + if request.META.get('HTTP_ACCEPT') not in ( + 'application/json', 'application/activity+json', 'application/ld+json', + 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + ): return func(request, *args, **kwargs) get_object_function = get_function_from_config('get_object_function') obj = get_object_function(request.build_absolute_uri()) diff --git a/federation/tests/entities/activitypub/django/test_views.py b/federation/tests/entities/activitypub/django/test_views.py index 129daeb..8b996bb 100644 --- a/federation/tests/entities/activitypub/django/test_views.py +++ b/federation/tests/entities/activitypub/django/test_views.py @@ -21,9 +21,12 @@ class DummyView(View): class TestActivityPubObjectView: - @pytest.mark.parametrize('content_type', ('application/activity+json', 'application/json')) + @pytest.mark.parametrize('content_type', ( + 'application/json', 'application/activity+json', 'application/ld+json', + 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + )) def test_renders_as2(self, content_type): - request = RequestFactory().get("/", CONTENT_TYPE=content_type) + request = RequestFactory().get("/", HTTP_ACCEPT=content_type) response = dummy_view(request=request) assert response.status_code == 200 @@ -31,9 +34,12 @@ class TestActivityPubObjectView: assert content['name'] == 'Bob Bobértson' assert response['Content-Type'] == 'application/activity+json' - @pytest.mark.parametrize('content_type', ('application/activity+json', 'application/json')) + @pytest.mark.parametrize('content_type', ( + 'application/json', 'application/activity+json', 'application/ld+json', + 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + )) def test_renders_as2__cbv(self, content_type): - request = RequestFactory().get("/", CONTENT_TYPE=content_type) + request = RequestFactory().get("/", HTTP_ACCEPT=content_type) view = DummyView.as_view() response = view(request=request)