From 251f558428f785669b8cd694058175b2e2855df1 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Sat, 29 Sep 2018 12:12:34 +0300 Subject: [PATCH] Move test settings and utils for Django to tests root Fix first AS2 view decorator test. --- .../entities/activitypub/django/views.py | 3 ++- federation/tests/django/__init__.py | 2 ++ federation/tests/django/settings.py | 10 +++++++++ federation/tests/django/utils.py | 22 +++++++++++++++++++ .../entities/activitypub/django/test_views.py | 7 ------ federation/tests/hostmeta/django/settings.py | 9 -------- federation/tests/hostmeta/django/utils.py | 11 ---------- pytest.ini | 2 +- 8 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 federation/tests/django/__init__.py create mode 100644 federation/tests/django/settings.py create mode 100644 federation/tests/django/utils.py delete mode 100644 federation/tests/hostmeta/django/settings.py delete mode 100644 federation/tests/hostmeta/django/utils.py diff --git a/federation/entities/activitypub/django/views.py b/federation/entities/activitypub/django/views.py index a86aa30..ace6b46 100644 --- a/federation/entities/activitypub/django/views.py +++ b/federation/entities/activitypub/django/views.py @@ -23,6 +23,7 @@ def activitypub_object_view(request, *args, **kwargs): if not obj: raise Http404 - return JsonResponse(obj.to_as2()) + as2_obj = obj.as_protocol('activitypub') + return JsonResponse(as2_obj.to_as2()) return inner return decorator diff --git a/federation/tests/django/__init__.py b/federation/tests/django/__init__.py new file mode 100644 index 0000000..a2b5079 --- /dev/null +++ b/federation/tests/django/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals diff --git a/federation/tests/django/settings.py b/federation/tests/django/settings.py new file mode 100644 index 0000000..6453c3b --- /dev/null +++ b/federation/tests/django/settings.py @@ -0,0 +1,10 @@ +SECRET_KEY = "foobar" + +INSTALLED_APPS = tuple() + +FEDERATION = { + "base_url": "https://example.com", + "get_object_function": "federation.tests.django.utils.get_object_function", + "get_profile_function": "federation.tests.django.utils.get_profile", + "search_path": "/search?q=", +} diff --git a/federation/tests/django/utils.py b/federation/tests/django/utils.py new file mode 100644 index 0000000..e47c970 --- /dev/null +++ b/federation/tests/django/utils.py @@ -0,0 +1,22 @@ +from federation.entities.base import Profile + + +def get_object_function(object_id): + return Profile( + url=f"https://example.com/profile/1234/", + atom_url=f"https://example.com/profile/1234/atom.xml", + id=f"https://example.com/profile/1234/", + handle="foobar@example.com", + guid="1234", + name="Bob Bobértson", + ) + + +def get_profile(handle=None, request=None): + return Profile( + url=f"https://example.com/profile/1234/", + atom_url=f"https://example.com/profile/1234/atom.xml", + id=f"https://example.com/profile/1234/", + handle="foobar@example.com", + guid="1234", + ) diff --git a/federation/tests/entities/activitypub/django/test_views.py b/federation/tests/entities/activitypub/django/test_views.py index 1d3ca0b..8ca8b47 100644 --- a/federation/tests/entities/activitypub/django/test_views.py +++ b/federation/tests/entities/activitypub/django/test_views.py @@ -14,13 +14,6 @@ def dummy_view(request, *args, **kwargs): class TestActivityPubObjectView: def test_renders_as2(self): - entity = ActivitypubProfile( - raw_content="foobar", name="Bob Bobértson", public=True, - tag_list=["socialfederation", "federation"], image_urls={ - "large": "urllarge", "medium": "urlmedium", "small": "urlsmall" - }, - id="https://127.0.0.1", - ) # TODO test with real content type, but also json request = RequestFactory().get("/", CONTENT_TYPE='application/json') response = dummy_view(request)(request=request) diff --git a/federation/tests/hostmeta/django/settings.py b/federation/tests/hostmeta/django/settings.py deleted file mode 100644 index 6207fb5..0000000 --- a/federation/tests/hostmeta/django/settings.py +++ /dev/null @@ -1,9 +0,0 @@ -SECRET_KEY = "foobar" - -INSTALLED_APPS = tuple() - -FEDERATION = { - "base_url": "https://example.com", - "get_profile_function": "federation.tests.hostmeta.django.utils.get_profile", - "search_path": "/search?q=", -} diff --git a/federation/tests/hostmeta/django/utils.py b/federation/tests/hostmeta/django/utils.py deleted file mode 100644 index 0c980b3..0000000 --- a/federation/tests/hostmeta/django/utils.py +++ /dev/null @@ -1,11 +0,0 @@ -from federation.entities.base import Profile - - -def get_profile(handle=None, request=None): - return Profile( - url=f"https://example.com/profile/1234/", - atom_url=f"https://example.com/profile/1234/atom.xml", - id=f"diaspora://{handle}/profile/1234", - handle=handle, - guid="1234", - ) diff --git a/pytest.ini b/pytest.ini index c4ec3d6..db3c70f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,3 @@ [pytest] testpaths = federation -DJANGO_SETTINGS_MODULE = federation.tests.hostmeta.django.settings +DJANGO_SETTINGS_MODULE = federation.tests.django.settings