From c918edb622a3b9708bbec08c2e46be3bf406976d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 7 Jan 2022 09:56:29 -0800 Subject: [PATCH 1/2] Fixes searching for users in get started view --- bookwyrm/views/get_started.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/get_started.py b/bookwyrm/views/get_started.py index 709b3754a..48423b118 100644 --- a/bookwyrm/views/get_started.py +++ b/bookwyrm/views/get_started.py @@ -113,13 +113,16 @@ class GetStartedUsers(View): .filter( similarity__gt=0.5, ) + .exclude( + id=request.user.id, + ) .order_by("-similarity")[:5] ) data = {"no_results": not user_results} if user_results.count() < 5: - user_results = list(user_results) + suggested_users.get_suggestions( - request.user + user_results = list(user_results) + list( + suggested_users.get_suggestions(request.user) ) data["suggested_users"] = user_results From e91947afbf90b88370b3fc3194dc4ac541d80f83 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 7 Jan 2022 10:06:11 -0800 Subject: [PATCH 2/2] Adds meaningful test mock --- bookwyrm/tests/views/test_get_started.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 9d0222054..84ad966db 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -25,6 +25,13 @@ class GetStartedViews(TestCase): local=True, localname="mouse", ) + self.local_user = models.User.objects.create_user( + "rat@local.com", + "rat@rat.rat", + "password", + local=True, + localname="rat", + ) self.book = models.Edition.objects.create( parent_work=models.Work.objects.create(title="hi"), title="Example Edition", @@ -121,14 +128,15 @@ class GetStartedViews(TestCase): validate_html(result.render()) self.assertEqual(result.status_code, 200) - @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") def test_users_view_with_query(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedUsers.as_view() request = self.factory.get("?query=rat") request.user = self.local_user - result = view(request) + with patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") as mock: + mock.return_value = models.User.objects.all() + result = view(request) self.assertIsInstance(result, TemplateResponse) validate_html(result.render())