mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-22 08:07:14 +00:00
tests status class view
This commit is contained in:
parent
6c80b128a4
commit
5596277d29
5 changed files with 43 additions and 24 deletions
|
@ -9,8 +9,7 @@ from django.test import TestCase
|
|||
from django.test.client import RequestFactory
|
||||
import responses
|
||||
|
||||
from bookwyrm import forms, models, outgoing
|
||||
from bookwyrm.settings import DOMAIN
|
||||
from bookwyrm import models, outgoing
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.http import JsonResponse
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
|
|
|
@ -15,8 +15,25 @@ class StatusViews(TestCase):
|
|||
''' we need basic test data and mocks '''
|
||||
self.factory = RequestFactory()
|
||||
self.local_user = models.User.objects.create_user(
|
||||
'mouse@local.com', 'mouse@mouse.mouse', 'password',
|
||||
local=True, localname='mouse')
|
||||
'mouse@local.com', 'mouse@mouse.com', 'mouseword',
|
||||
local=True, localname='mouse',
|
||||
remote_id='https://example.com/users/mouse',
|
||||
)
|
||||
with patch('bookwyrm.models.user.set_remote_server'):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
'rat', 'rat@email.com', 'ratword',
|
||||
local=False,
|
||||
remote_id='https://example.com/users/rat',
|
||||
inbox='https://example.com/users/rat/inbox',
|
||||
outbox='https://example.com/users/rat/outbox',
|
||||
)
|
||||
|
||||
work = models.Work.objects.create(title='Test Work')
|
||||
self.book = models.Edition.objects.create(
|
||||
title='Example Edition',
|
||||
remote_id='https://example.com/book/1',
|
||||
parent_work=work
|
||||
)
|
||||
|
||||
|
||||
def test_status_page(self):
|
||||
|
@ -70,7 +87,7 @@ class StatusViews(TestCase):
|
|||
'book': self.book.id,
|
||||
'privacy': 'public',
|
||||
})
|
||||
request = self.factory.get('', form.data)
|
||||
request = self.factory.post('', form.data)
|
||||
request.user = self.local_user
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
view(request, 'comment')
|
||||
|
@ -92,8 +109,8 @@ class StatusViews(TestCase):
|
|||
'reply_parent': parent.id,
|
||||
'privacy': 'public',
|
||||
})
|
||||
request = self.factory.get('', form.data)
|
||||
request.user = self.local_user
|
||||
request = self.factory.post('', form.data)
|
||||
request.user = user
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
view(request, 'reply')
|
||||
status = models.Status.objects.get(user=user)
|
||||
|
@ -114,7 +131,7 @@ class StatusViews(TestCase):
|
|||
'book': self.book.id,
|
||||
'privacy': 'public',
|
||||
})
|
||||
request = self.factory.get('', form.data)
|
||||
request = self.factory.post('', form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
|
@ -138,7 +155,7 @@ class StatusViews(TestCase):
|
|||
'book': self.book.id,
|
||||
'privacy': 'public',
|
||||
})
|
||||
request = self.factory.get('', form.data)
|
||||
request = self.factory.post('', form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
|
@ -147,14 +164,14 @@ class StatusViews(TestCase):
|
|||
|
||||
form = forms.ReplyForm({
|
||||
'content': 'right',
|
||||
'user': user,
|
||||
'user': user.id,
|
||||
'privacy': 'public',
|
||||
'reply_parent': status.id
|
||||
})
|
||||
request = self.factory.get('', form.data)
|
||||
request.user = self.local_user
|
||||
request = self.factory.post('', form.data)
|
||||
request.user = user
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
view(request, 'comment')
|
||||
view(request, 'reply')
|
||||
|
||||
reply = models.Status.replies(status).first()
|
||||
self.assertEqual(reply.content, '<p>right</p>')
|
||||
|
|
|
@ -81,21 +81,19 @@ urlpatterns = [
|
|||
re_path(r'^delete-status/(?P<status_id>\d+)/?$',
|
||||
views.DeleteStatus.as_view()),
|
||||
|
||||
|
||||
re_path(r'^tag/?$', actions.tag),
|
||||
re_path(r'^untag/?$', actions.untag),
|
||||
# books
|
||||
re_path(r'%s(.json)?/?$' % book_path, vviews.book_page),
|
||||
re_path(r'%s/edit/?$' % book_path, vviews.edit_book_page),
|
||||
re_path(r'^author/(?P<author_id>[\w\-]+)/edit/?$', vviews.edit_author_page),
|
||||
re_path(r'%s/editions(.json)?/?$' % book_path, vviews.editions_page),
|
||||
|
||||
# interact
|
||||
re_path(r'^favorite/(?P<status_id>\d+)/?$', actions.favorite),
|
||||
re_path(r'^unfavorite/(?P<status_id>\d+)/?$', actions.unfavorite),
|
||||
re_path(r'^boost/(?P<status_id>\d+)/?$', actions.boost),
|
||||
re_path(r'^unboost/(?P<status_id>\d+)/?$', actions.unboost),
|
||||
|
||||
# books
|
||||
re_path(r'%s(.json)?/?$' % book_path, vviews.book_page),
|
||||
re_path(r'%s/edit/?$' % book_path, vviews.edit_book_page),
|
||||
re_path(r'^author/(?P<author_id>[\w\-]+)/edit/?$', vviews.edit_author_page),
|
||||
re_path(r'%s/editions(.json)?/?$' % book_path, vviews.editions_page),
|
||||
re_path(r'^tag/?$', actions.tag),
|
||||
re_path(r'^untag/?$', actions.untag),
|
||||
|
||||
re_path(r'^author/(?P<author_id>[\w\-]+)(.json)?/?$', vviews.author_page),
|
||||
re_path(r'^tag/(?P<tag_id>.+)\.json/?$', vviews.tag_page),
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
''' helper functions used in various views '''
|
||||
import re
|
||||
from requests import HTTPError
|
||||
from django.db.models import Q
|
||||
from bookwyrm import models
|
||||
|
||||
from bookwyrm import activitypub, models
|
||||
from bookwyrm.connectors import ConnectorException, get_data
|
||||
from bookwyrm.utils import regex
|
||||
|
||||
|
||||
def get_user_from_username(username):
|
||||
''' helper function to resolve a localname or a username to a user '''
|
||||
|
|
Loading…
Reference in a new issue