forked from mirrors/bookwyrm
Fixes more tests for moved-around views
This commit is contained in:
parent
bae54b6847
commit
640db7e9e3
3 changed files with 100 additions and 43 deletions
99
bookwyrm/tests/views/test_feed.py
Normal file
99
bookwyrm/tests/views/test_feed.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
''' test for app action functionality '''
|
||||
from unittest.mock import patch
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm import views
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
|
||||
|
||||
class FeedMessageViews(TestCase):
|
||||
''' dms '''
|
||||
def setUp(self):
|
||||
''' 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')
|
||||
self.book = models.Edition.objects.create(
|
||||
title='Example Edition',
|
||||
remote_id='https://example.com/book/1',
|
||||
)
|
||||
|
||||
|
||||
def test_feed(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
view = views.Feed.as_view()
|
||||
request = self.factory.get('')
|
||||
request.user = self.local_user
|
||||
result = view(request, 'local')
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/feed.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
def test_status_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
view = views.Status.as_view()
|
||||
status = models.Status.objects.create(
|
||||
content='hi', user=self.local_user)
|
||||
request = self.factory.get('')
|
||||
request.user = self.local_user
|
||||
with patch('bookwyrm.views.feed.is_api_request') as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/status.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.feed.is_api_request') as is_api:
|
||||
is_api.return_value = True
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
def test_replies_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
view = views.Replies.as_view()
|
||||
status = models.Status.objects.create(
|
||||
content='hi', user=self.local_user)
|
||||
request = self.factory.get('')
|
||||
request.user = self.local_user
|
||||
with patch('bookwyrm.views.feed.is_api_request') as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/status.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.feed.is_api_request') as is_api:
|
||||
is_api.return_value = True
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
def test_direct_messages_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
view = views.DirectMessage.as_view()
|
||||
request = self.factory.get('')
|
||||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/direct_messages.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
def test_get_suggested_book(self):
|
||||
''' gets books the ~*~ algorithm ~*~ thinks you want to post about '''
|
||||
models.ShelfBook.objects.create(
|
||||
book=self.book,
|
||||
added_by=self.local_user,
|
||||
shelf=self.local_user.shelf_set.get(identifier='reading')
|
||||
)
|
||||
suggestions = views.feed.get_suggested_books(self.local_user)
|
||||
self.assertEqual(suggestions[0]['name'], 'Currently Reading')
|
||||
self.assertEqual(suggestions[0]['books'][0], self.book)
|
|
@ -106,7 +106,7 @@ class PasswordViews(TestCase):
|
|||
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'change_password.html')
|
||||
self.assertEqual(result.template_name, 'preferences/change_password.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
|
|
@ -36,48 +36,6 @@ class StatusViews(TestCase):
|
|||
)
|
||||
|
||||
|
||||
def test_status_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
view = views.Status.as_view()
|
||||
status = models.Status.objects.create(
|
||||
content='hi', user=self.local_user)
|
||||
request = self.factory.get('')
|
||||
request.user = self.local_user
|
||||
with patch('bookwyrm.views.status.is_api_request') as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/status.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.status.is_api_request') as is_api:
|
||||
is_api.return_value = True
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
def test_replies_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
view = views.Replies.as_view()
|
||||
status = models.Status.objects.create(
|
||||
content='hi', user=self.local_user)
|
||||
request = self.factory.get('')
|
||||
request.user = self.local_user
|
||||
with patch('bookwyrm.views.status.is_api_request') as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/status.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.status.is_api_request') as is_api:
|
||||
is_api.return_value = True
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
def test_handle_status(self):
|
||||
''' create a status '''
|
||||
view = views.CreateStatus.as_view()
|
||||
|
|
Loading…
Reference in a new issue