mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +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
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -52,7 +53,7 @@ class ShelfViews(TestCase):
|
||||||
self.assertEqual(data[0]["title"], "Test Book")
|
self.assertEqual(data[0]["title"], "Test Book")
|
||||||
self.assertEqual(data[0]["key"], "https://%s/book/%d" % (DOMAIN, self.book.id))
|
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"""
|
"""searches remote connectors"""
|
||||||
view = views.Search.as_view()
|
view = views.Search.as_view()
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ class ShelfViews(TestCase):
|
||||||
connector=connector,
|
connector=connector,
|
||||||
)
|
)
|
||||||
|
|
||||||
request = self.factory.get("", {"q": "Test Book"})
|
request = self.factory.get("", {"q": "Test Book", "remote": True})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.views.search.is_api_request") as is_api:
|
with patch("bookwyrm.views.search.is_api_request") as is_api:
|
||||||
is_api.return_value = False
|
is_api.return_value = False
|
||||||
|
@ -101,19 +102,41 @@ class ShelfViews(TestCase):
|
||||||
response = view(request)
|
response = view(request)
|
||||||
self.assertIsInstance(response, TemplateResponse)
|
self.assertIsInstance(response, TemplateResponse)
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual(
|
self.assertEqual(response.context_data["results"][0].title, "Gideon the Ninth")
|
||||||
response.context_data["book_results"][0].title, "Gideon the Ninth"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_search_html_response_users(self):
|
def test_search_users(self):
|
||||||
"""searches remote connectors"""
|
"""searches remote connectors"""
|
||||||
view = views.Search.as_view()
|
view = views.Search.as_view()
|
||||||
request = self.factory.get("", {"q": "mouse"})
|
request = self.factory.get("", {"q": "mouse", "type": "user"})
|
||||||
request.user = self.local_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)
|
self.assertIsInstance(response, TemplateResponse)
|
||||||
response.render()
|
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