mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-14 19:25:30 +00:00
small change and test to get_user_from_username
This commit is contained in:
parent
747167c579
commit
48f002727a
2 changed files with 16 additions and 4 deletions
|
@ -23,6 +23,18 @@ class Views(TestCase):
|
||||||
connector_file='self_connector',
|
connector_file='self_connector',
|
||||||
local=True
|
local=True
|
||||||
)
|
)
|
||||||
|
self.local_user = models.User.objects.create_user(
|
||||||
|
'mouse', 'mouse@mouse.mouse', 'password', local=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_user_from_username(self):
|
||||||
|
''' works for either localname or username '''
|
||||||
|
self.assertEqual(
|
||||||
|
views.get_user_from_username('mouse'), self.local_user)
|
||||||
|
self.assertEqual(
|
||||||
|
views.get_user_from_username('mouse@%s' % DOMAIN), self.local_user)
|
||||||
|
with self.assertRaises(models.User.DoesNotExist):
|
||||||
|
views.get_user_from_username('mojfse@example.com')
|
||||||
|
|
||||||
|
|
||||||
def test_search_json_response(self):
|
def test_search_json_response(self):
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.decorators.http import require_GET
|
from django.views.decorators.http import require_GET
|
||||||
|
|
||||||
from bookwyrm import outgoing
|
from bookwyrm import outgoing
|
||||||
from bookwyrm.activitypub import ActivityEncoder, ActivitypubResponse
|
from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from bookwyrm import forms, models, books_manager
|
from bookwyrm import forms, models, books_manager
|
||||||
from bookwyrm import goodreads_import
|
from bookwyrm import goodreads_import
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
|
@ -23,11 +23,11 @@ from bookwyrm.utils import regex
|
||||||
|
|
||||||
def get_user_from_username(username):
|
def get_user_from_username(username):
|
||||||
''' helper function to resolve a localname or a username to a user '''
|
''' helper function to resolve a localname or a username to a user '''
|
||||||
|
# raises DoesNotExist if user is now found
|
||||||
try:
|
try:
|
||||||
user = models.User.objects.get(localname=username)
|
return models.User.objects.get(localname=username)
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
user = models.User.objects.get(username=username)
|
return models.User.objects.get(username=username)
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
def is_api_request(request):
|
def is_api_request(request):
|
||||||
|
|
Loading…
Reference in a new issue