kopia lustrzana https://gitlab.com/jaywink/federation
Use right content types in activitypub_object_view decorator
rodzic
ceb5d0446e
commit
882711a31a
|
@ -12,7 +12,10 @@ def activitypub_object_view(func):
|
||||||
type doesn't match.
|
type doesn't match.
|
||||||
"""
|
"""
|
||||||
def inner(request, *args, **kwargs):
|
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)
|
return func(request, *args, **kwargs)
|
||||||
get_object_function = get_function_from_config('get_object_function')
|
get_object_function = get_function_from_config('get_object_function')
|
||||||
obj = get_object_function(request.build_absolute_uri())
|
obj = get_object_function(request.build_absolute_uri())
|
||||||
|
|
|
@ -21,9 +21,12 @@ class DummyView(View):
|
||||||
|
|
||||||
|
|
||||||
class TestActivityPubObjectView:
|
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):
|
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)
|
response = dummy_view(request=request)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -31,9 +34,12 @@ class TestActivityPubObjectView:
|
||||||
assert content['name'] == 'Bob Bobértson'
|
assert content['name'] == 'Bob Bobértson'
|
||||||
assert response['Content-Type'] == 'application/activity+json'
|
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):
|
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()
|
view = DummyView.as_view()
|
||||||
response = view(request=request)
|
response = view(request=request)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue