forked from mirrors/bookwyrm
Merge pull request #1782 from bookwyrm-social/get-started-user-search
Fixes searching for users in get started view
This commit is contained in:
commit
5c7cc034d5
2 changed files with 15 additions and 4 deletions
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue