mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-28 04:21:07 +00:00
commit
747167c579
3 changed files with 49 additions and 10 deletions
|
@ -111,6 +111,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
queryset = Status.objects.filter(
|
||||
user=self,
|
||||
deleted=False,
|
||||
privacy__in=['public', 'unlisted'],
|
||||
).select_subclasses().order_by('-published_date')
|
||||
return self.to_ordered_collection(queryset, \
|
||||
remote_id=self.outbox, **kwargs)
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
import re
|
||||
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.http import HttpResponseNotFound, JsonResponse
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_GET
|
||||
from markdown import markdown
|
||||
from requests import HTTPError
|
||||
|
||||
|
@ -20,17 +22,11 @@ from bookwyrm.utils import regex
|
|||
|
||||
|
||||
@csrf_exempt
|
||||
@require_GET
|
||||
def outbox(request, username):
|
||||
''' outbox for the requested user '''
|
||||
if request.method != 'GET':
|
||||
return HttpResponseNotFound()
|
||||
user = get_object_or_404(models.User, localname=username)
|
||||
|
||||
try:
|
||||
user = models.User.objects.get(localname=username)
|
||||
except models.User.DoesNotExist:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
# collection overview
|
||||
return JsonResponse(
|
||||
user.to_outbox(**request.GET),
|
||||
encoder=activitypub.ActivityEncoder
|
||||
|
|
|
@ -3,7 +3,9 @@ import json
|
|||
import pathlib
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
import responses
|
||||
|
||||
from bookwyrm import models, outgoing
|
||||
|
@ -14,6 +16,7 @@ class Outgoing(TestCase):
|
|||
''' sends out activities '''
|
||||
def setUp(self):
|
||||
''' we'll need some data '''
|
||||
self.factory = RequestFactory()
|
||||
with patch('bookwyrm.models.user.set_remote_server'):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
'rat', 'rat@rat.com', 'ratword',
|
||||
|
@ -24,7 +27,7 @@ class Outgoing(TestCase):
|
|||
)
|
||||
self.local_user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword', local=True,
|
||||
remote_id='https://example.com/users/mouse',
|
||||
localname='mouse', remote_id='https://example.com/users/mouse',
|
||||
)
|
||||
|
||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||
|
@ -46,6 +49,45 @@ class Outgoing(TestCase):
|
|||
)
|
||||
|
||||
|
||||
def test_outbox(self):
|
||||
''' returns user's statuses '''
|
||||
request = self.factory.get('')
|
||||
result = outgoing.outbox(request, 'mouse')
|
||||
self.assertIsInstance(result, JsonResponse)
|
||||
|
||||
def test_outbox_bad_method(self):
|
||||
''' can't POST to outbox '''
|
||||
request = self.factory.post('')
|
||||
result = outgoing.outbox(request, 'mouse')
|
||||
self.assertEqual(result.status_code, 405)
|
||||
|
||||
def test_outbox_unknown_user(self):
|
||||
''' should 404 for unknown and remote users '''
|
||||
request = self.factory.post('')
|
||||
result = outgoing.outbox(request, 'beepboop')
|
||||
self.assertEqual(result.status_code, 405)
|
||||
result = outgoing.outbox(request, 'rat')
|
||||
self.assertEqual(result.status_code, 405)
|
||||
|
||||
def test_outbox_privacy(self):
|
||||
''' don't show dms et cetera in outbox '''
|
||||
models.Status.objects.create(
|
||||
content='PRIVATE!!', user=self.local_user, privacy='direct')
|
||||
models.Status.objects.create(
|
||||
content='bffs ONLY', user=self.local_user, privacy='followers')
|
||||
models.Status.objects.create(
|
||||
content='unlisted status', user=self.local_user, privacy='unlisted')
|
||||
models.Status.objects.create(
|
||||
content='look at this', user=self.local_user, privacy='public')
|
||||
|
||||
request = self.factory.get('')
|
||||
result = outgoing.outbox(request, 'mouse')
|
||||
self.assertIsInstance(result, JsonResponse)
|
||||
data = json.loads(result.content)
|
||||
self.assertEqual(data['type'], 'OrderedCollection')
|
||||
self.assertEqual(data['totalItems'], 2)
|
||||
|
||||
|
||||
def test_handle_follow(self):
|
||||
''' send a follow request '''
|
||||
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
||||
|
|
Loading…
Reference in a new issue