mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Updates unit tests
This commit is contained in:
parent
f9c1ecfabe
commit
64b54510d9
1 changed files with 35 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
|||
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
|
||||
|
@ -52,7 +53,7 @@ class ShelfViews(TestCase):
|
|||
self.assertEqual(data[0]["title"], "Test Book")
|
||||
self.assertEqual(data[0]["key"], "https://%s/book/%d" % (DOMAIN, self.book.id))
|
||||
|
||||
def test_search_html_response(self):
|
||||
def test_search_books(self):
|
||||
"""searches remote connectors"""
|
||||
view = views.Search.as_view()
|
||||
|
||||
|
@ -92,7 +93,7 @@ class ShelfViews(TestCase):
|
|||
connector=connector,
|
||||
)
|
||||
|
||||
request = self.factory.get("", {"q": "Test Book"})
|
||||
request = self.factory.get("", {"q": "Test Book", "remote": True})
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.search.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
|
@ -101,19 +102,41 @@ class ShelfViews(TestCase):
|
|||
response = view(request)
|
||||
self.assertIsInstance(response, TemplateResponse)
|
||||
response.render()
|
||||
self.assertEqual(
|
||||
response.context_data["book_results"][0].title, "Gideon the Ninth"
|
||||
)
|
||||
self.assertEqual(response.context_data["results"][0].title, "Gideon the Ninth")
|
||||
|
||||
def test_search_html_response_users(self):
|
||||
def test_search_users(self):
|
||||
"""searches remote connectors"""
|
||||
view = views.Search.as_view()
|
||||
request = self.factory.get("", {"q": "mouse"})
|
||||
request = self.factory.get("", {"q": "mouse", "type": "user"})
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.search.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
with patch("bookwyrm.connectors.connector_manager.search"):
|
||||
response = view(request)
|
||||
response = view(request)
|
||||
|
||||
self.assertIsInstance(response, TemplateResponse)
|
||||
response.render()
|
||||
self.assertEqual(response.context_data["user_results"][0], self.local_user)
|
||||
self.assertEqual(response.context_data["results"][0], self.local_user)
|
||||
|
||||
def test_search_users_logged_out(self):
|
||||
"""searches remote connectors"""
|
||||
view = views.Search.as_view()
|
||||
request = self.factory.get("", {"q": "mouse", "type": "user"})
|
||||
|
||||
anonymous_user = AnonymousUser
|
||||
anonymous_user.is_authenticated = False
|
||||
request.user = anonymous_user
|
||||
|
||||
response = view(request)
|
||||
|
||||
response.render()
|
||||
self.assertEqual(response.context_data["results"], {})
|
||||
|
||||
def test_search_lists(self):
|
||||
"""searches remote connectors"""
|
||||
booklist = models.List.objects.create(user=self.local_user, name="test list")
|
||||
view = views.Search.as_view()
|
||||
request = self.factory.get("", {"q": "test", "type": "list"})
|
||||
request.user = self.local_user
|
||||
response = view(request)
|
||||
|
||||
self.assertIsInstance(response, TemplateResponse)
|
||||
response.render()
|
||||
self.assertEqual(response.context_data["results"][0], booklist)
|
||||
|
|
Loading…
Reference in a new issue