Use right content types in activitypub_object_view decorator

merge-requests/132/head
Jason Robinson 2018-09-30 17:15:31 +03:00
rodzic ceb5d0446e
commit 882711a31a
2 zmienionych plików z 14 dodań i 5 usunięć

Wyświetl plik

@ -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())

Wyświetl plik

@ -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)