mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 21:11:16 +00:00
Avoid error when request Accept header is not set
This commit is contained in:
parent
18c552d215
commit
662ddf44b9
2 changed files with 6 additions and 1 deletions
|
@ -84,6 +84,11 @@ class ViewsHelpers(TestCase):
|
||||||
request.headers = {"Accept": "Praise"}
|
request.headers = {"Accept": "Praise"}
|
||||||
self.assertFalse(views.helpers.is_api_request(request))
|
self.assertFalse(views.helpers.is_api_request(request))
|
||||||
|
|
||||||
|
def test_is_api_request_no_headers(self, _):
|
||||||
|
""" should it return html or json """
|
||||||
|
request = self.factory.get("/path")
|
||||||
|
self.assertFalse(views.helpers.is_api_request(request))
|
||||||
|
|
||||||
def test_is_bookwyrm_request(self, _):
|
def test_is_bookwyrm_request(self, _):
|
||||||
""" checks if a request came from a bookwyrm instance """
|
""" checks if a request came from a bookwyrm instance """
|
||||||
request = self.factory.get("", {"q": "Test Book"})
|
request = self.factory.get("", {"q": "Test Book"})
|
||||||
|
|
|
@ -21,7 +21,7 @@ def get_user_from_username(viewer, username):
|
||||||
|
|
||||||
def is_api_request(request):
|
def is_api_request(request):
|
||||||
""" check whether a request is asking for html or data """
|
""" check whether a request is asking for html or data """
|
||||||
return "json" in request.headers.get("Accept") or request.path[-5:] == ".json"
|
return "json" in request.headers.get("Accept", "") or request.path[-5:] == ".json"
|
||||||
|
|
||||||
|
|
||||||
def is_bookwyrm_request(request):
|
def is_bookwyrm_request(request):
|
||||||
|
|
Loading…
Reference in a new issue