Use headers dict instead of HTTP_* kwargs or request.META
This commit is contained in:
parent
224fae7a87
commit
624115bf11
5 changed files with 47 additions and 19 deletions
|
@ -134,7 +134,10 @@ class Inbox(TestCase):
|
|||
"""check for blocked servers"""
|
||||
request = self.factory.post(
|
||||
"",
|
||||
HTTP_USER_AGENT="http.rb/4.4.1 (Mastodon/3.3.0; +https://mastodon.social/)",
|
||||
headers={
|
||||
# pylint: disable-next=line-too-long
|
||||
"user-agent": "http.rb/4.4.1 (Mastodon/3.3.0; +https://mastodon.social/)",
|
||||
},
|
||||
)
|
||||
self.assertIsNone(views.inbox.raise_is_blocked_user_agent(request))
|
||||
|
||||
|
|
|
@ -113,11 +113,20 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods
|
|||
request = self.factory.get(
|
||||
"",
|
||||
{"q": "Test Book"},
|
||||
HTTP_USER_AGENT="http.rb/4.4.1 (Mastodon/3.3.0; +https://mastodon.social/)",
|
||||
headers={
|
||||
# pylint: disable-next=line-too-long
|
||||
"user-agent": "http.rb/4.4.1 (Mastodon/3.3.0; +https://mastodon.social/)",
|
||||
},
|
||||
)
|
||||
self.assertFalse(views.helpers.is_bookwyrm_request(request))
|
||||
|
||||
request = self.factory.get("", {"q": "Test Book"}, HTTP_USER_AGENT=USER_AGENT)
|
||||
request = self.factory.get(
|
||||
"",
|
||||
{"q": "Test Book"},
|
||||
headers={
|
||||
"user-agent": USER_AGENT,
|
||||
},
|
||||
)
|
||||
self.assertTrue(views.helpers.is_bookwyrm_request(request))
|
||||
|
||||
def test_handle_remote_webfinger_invalid(self, *_):
|
||||
|
@ -271,8 +280,12 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
def test_redirect_to_referer_outside_domain(self, *_):
|
||||
"""safely send people on their way"""
|
||||
request = self.factory.get("/path")
|
||||
request.META = {"HTTP_REFERER": "http://outside.domain/name"}
|
||||
request = self.factory.get(
|
||||
"/path",
|
||||
headers={
|
||||
"referer": "http://outside.domain/name",
|
||||
},
|
||||
)
|
||||
result = views.helpers.redirect_to_referer(
|
||||
request, "user-feed", self.local_user.localname
|
||||
)
|
||||
|
@ -280,21 +293,33 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
def test_redirect_to_referer_outside_domain_with_fallback(self, *_):
|
||||
"""invalid domain with regular params for the redirect function"""
|
||||
request = self.factory.get("/path")
|
||||
request.META = {"HTTP_REFERER": "https://outside.domain/name"}
|
||||
request = self.factory.get(
|
||||
"/path",
|
||||
headers={
|
||||
"referer": "http://outside.domain/name",
|
||||
},
|
||||
)
|
||||
result = views.helpers.redirect_to_referer(request)
|
||||
self.assertEqual(result.url, "/")
|
||||
|
||||
def test_redirect_to_referer_valid_domain(self, *_):
|
||||
"""redirect to within the app"""
|
||||
request = self.factory.get("/path")
|
||||
request.META = {"HTTP_REFERER": f"{BASE_URL}/and/a/path"}
|
||||
request = self.factory.get(
|
||||
"/path",
|
||||
headers={
|
||||
"referer": f"{BASE_URL}/and/a/path",
|
||||
},
|
||||
)
|
||||
result = views.helpers.redirect_to_referer(request)
|
||||
self.assertEqual(result.url, f"{BASE_URL}/and/a/path")
|
||||
|
||||
def test_redirect_to_referer_with_get_args(self, *_):
|
||||
"""if the path has get params (like sort) they are preserved"""
|
||||
request = self.factory.get("/path")
|
||||
request.META = {"HTTP_REFERER": f"{BASE_URL}/and/a/path?sort=hello"}
|
||||
request = self.factory.get(
|
||||
"/path",
|
||||
headers={
|
||||
"referer": f"{BASE_URL}/and/a/path?sort=hello",
|
||||
},
|
||||
)
|
||||
result = views.helpers.redirect_to_referer(request)
|
||||
self.assertEqual(result.url, f"{BASE_URL}/and/a/path?sort=hello")
|
||||
|
|
|
@ -122,7 +122,7 @@ class OutboxView(TestCase):
|
|||
privacy="public",
|
||||
)
|
||||
|
||||
request = self.factory.get("", {"page": 1}, HTTP_USER_AGENT=USER_AGENT)
|
||||
request = self.factory.get("", {"page": 1}, headers={"user-agent": USER_AGENT})
|
||||
result = views.Outbox.as_view()(request, "mouse")
|
||||
|
||||
data = json.loads(result.content)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue