Skip to content

Commit

Permalink
a tiny better test for inbox and another string.
Browse files Browse the repository at this point in the history
have to make a migration and introduce a following view.
  • Loading branch information
andreasofthings authored Aug 7, 2024
1 parent 14cec85 commit e145895
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
11 changes: 8 additions & 3 deletions webapp/tests/activitypub/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ def test_inbox(self):
response = self.client.get("/inbox/")
self.assertEqual(response.status_code, 404)

def test_user_inbox(self):
def test_user_inbox_unauthenticated(self):
"""
Test the user inbox view.
.. :py:meth:webapp.tests.inbox.InboxTest.test_user_inbox
.. todo::
- For authenticated users, this shall return an
`OrderedCollection` with HTPP status 200.
"""
response = self.client.get("/accounts/{self.username}/inbox/")
self.assertEqual(response.status_code, 200)
from django.urls import reverse
response = self.client.get(reverse("actor-inbox", kwargs={'slug': self.username}))
self.assertEqual(response.status_code, 404)


def test_follow_1(self):
Expand Down
8 changes: 8 additions & 0 deletions webapp/views/activitypub/following.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
"totalItems": 0,
}

class FollowForm(forms.ModelForm):
class Meta:
model = Like
fields = ["actor", "object"]
widgets = {
"object": forms.URLInput(attrs={"class": "form-control"}),
}


class FollowingView(ListView):
template_name = "activitypub/following.html"
Expand Down
18 changes: 15 additions & 3 deletions webapp/views/activitypub/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class InboxView(DetailView):
"""
.. py:class:: webapp.views.InboxView
The inbox is discovered through the inbox property of an
:py:class:webapp.models.activitypub.Actor's profile. The
inbox **MUST** be an `OrderedCollection`.
.. seealso::
`ActivityPub Inbox <https://www.w3.org/TR/activitypub/#inbox>_`
Expand Down Expand Up @@ -145,11 +151,17 @@ def get(self, request, *args, **kwargs):
Not sure this is necessary, but
:py:meth:`webapp.tests.inbox.InboxTest.test_user_inbox` tests it.
"""
from urllib.parse import urlparse
actor = self.get_object().actor
assert request.method == "GET"
assert request.path == f"{actor.inbox}"

return JsonResponse({"status": f"{actor.inbox} ok"}, status=200)
logger.error(f"GET request: {request.path}")
logger.error(f"Actor: {actor.inbox}")
assert request.path == urlparse(actor.inbox).path


if request.user.is_authenticated and request.user == actor.profile.user:
return JsonResponse({"status": f"{actor.inbox} ok"}, status=200)
return JsonResponse({"status": "not found"}, status=404)

@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
Expand Down

0 comments on commit e145895

Please sign in to comment.