moviewyrm/bookwyrm/tests/views/test_directory.py

73 lines
2.5 KiB
Python
Raw Normal View History

2021-03-21 23:50:03 +00:00
""" test for app action functionality """
2021-08-03 17:25:53 +00:00
from unittest.mock import patch
from django.contrib.auth.models import AnonymousUser
2021-03-21 23:50:03 +00:00
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.client import RequestFactory
from bookwyrm import models, views
# pylint: disable=unused-argument
class DirectoryViews(TestCase):
2021-04-26 16:15:42 +00:00
"""tag views"""
2021-03-21 23:50:03 +00:00
def setUp(self):
2021-04-26 16:15:42 +00:00
"""we need basic test data and mocks"""
2021-03-21 23:50:03 +00:00
self.factory = RequestFactory()
2021-08-03 17:25:53 +00:00
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
"mouseword",
local=True,
localname="mouse",
remote_id="https://example.com/users/mouse",
)
models.SiteSettings.objects.create()
self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
def test_directory_page(self, *_):
"""there are so many views, this just makes sure it LOADS"""
models.User.objects.create_user(
2021-08-02 23:05:40 +00:00
"rat@local.com",
"rat@rat.com",
"ratword",
local=True,
localname="rat",
remote_id="https://example.com/users/rat",
discoverable=True,
)
2021-08-03 17:25:53 +00:00
view = views.Directory.as_view()
request = self.factory.get("")
request.user = self.local_user
2021-08-02 23:05:40 +00:00
2021-08-03 17:25:53 +00:00
result = view(request)
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
2021-03-21 23:50:03 +00:00
2021-08-03 17:25:53 +00:00
def test_directory_page_empty(self):
2021-04-26 16:15:42 +00:00
"""there are so many views, this just makes sure it LOADS"""
2021-03-21 23:50:03 +00:00
view = views.Directory.as_view()
request = self.factory.get("")
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
2021-08-03 17:25:53 +00:00
def test_directory_page_logged_out(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Directory.as_view()
request = self.factory.get("")
request.user = self.anonymous_user
result = view(request)
self.assertEqual(result.status_code, 302)