mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
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,
|
local=True,
|
||||||
localname="mouse",
|
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(
|
self.book = models.Edition.objects.create(
|
||||||
parent_work=models.Work.objects.create(title="hi"),
|
parent_work=models.Work.objects.create(title="hi"),
|
||||||
title="Example Edition",
|
title="Example Edition",
|
||||||
|
@ -121,14 +128,15 @@ class GetStartedViews(TestCase):
|
||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
|
|
||||||
def test_users_view_with_query(self, *_):
|
def test_users_view_with_query(self, *_):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
view = views.GetStartedUsers.as_view()
|
view = views.GetStartedUsers.as_view()
|
||||||
request = self.factory.get("?query=rat")
|
request = self.factory.get("?query=rat")
|
||||||
request.user = self.local_user
|
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)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
|
|
|
@ -113,13 +113,16 @@ class GetStartedUsers(View):
|
||||||
.filter(
|
.filter(
|
||||||
similarity__gt=0.5,
|
similarity__gt=0.5,
|
||||||
)
|
)
|
||||||
|
.exclude(
|
||||||
|
id=request.user.id,
|
||||||
|
)
|
||||||
.order_by("-similarity")[:5]
|
.order_by("-similarity")[:5]
|
||||||
)
|
)
|
||||||
data = {"no_results": not user_results}
|
data = {"no_results": not user_results}
|
||||||
|
|
||||||
if user_results.count() < 5:
|
if user_results.count() < 5:
|
||||||
user_results = list(user_results) + suggested_users.get_suggestions(
|
user_results = list(user_results) + list(
|
||||||
request.user
|
suggested_users.get_suggestions(request.user)
|
||||||
)
|
)
|
||||||
|
|
||||||
data["suggested_users"] = user_results
|
data["suggested_users"] = user_results
|
||||||
|
|
Loading…
Reference in a new issue