3
0
Fork 0

fix: workaround error when 'fanstatic.needed' missing from environ

apparently the previous fix doesn't actually get us past the error;
this one should do a better job although it's still not perfect
either.  for some reason the redirect to 'home' route is confused such
that it the new URL drops the ending filename but the rest remains, so
it's not really the home URL..  oh well at least this is better than
before
This commit is contained in:
Lance Edgar 2025-12-13 21:30:02 -06:00
parent 75b8de7ce3
commit 824889dfe0
4 changed files with 27 additions and 24 deletions

View file

@ -38,14 +38,6 @@ class TestWebHandler(WebTestCase):
url = handler.get_fanstatic_url(self.request, static.logo)
self.assertEqual(url, "/testing/fanstatic/wuttaweb_img/logo.png")
# error if environ missing config/data
environ = dict(self.request.environ)
del environ["fanstatic.needed"]
with patch.object(self.request, "environ", new=environ):
self.assertRaises(
KeyError, handler.get_fanstatic_url, self.request, static.logo
)
def test_get_favicon_url(self):
handler = self.make_handler()
@ -53,12 +45,6 @@ class TestWebHandler(WebTestCase):
url = handler.get_favicon_url(self.request)
self.assertEqual(url, "/fanstatic/wuttaweb_img/favicon.ico")
# returns empty if environ missing config/data
environ = dict(self.request.environ)
del environ["fanstatic.needed"]
with patch.object(self.request, "environ", new=environ):
self.assertEqual(handler.get_favicon_url(self.request), "")
# config override
self.config.setdefault("wuttaweb.favicon_url", "/testing/other.ico")
url = handler.get_favicon_url(self.request)

View file

@ -7,6 +7,7 @@ from unittest.mock import MagicMock, patch
from wuttjamaican.conf import WuttaConfig
from pyramid import testing
from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember
from wuttaweb import subscribers
@ -14,6 +15,10 @@ from wuttaweb import helpers
from wuttaweb.auth import WuttaSecurityPolicy
# TODO: change import above
mod = subscribers
class TestNewRequest(TestCase):
def setUp(self):
@ -34,6 +39,14 @@ class TestNewRequest(TestCase):
# request.registry.settings = {'wutta_config': self.config}
return request
def test_missing_fanstatic_needed(self):
self.pyramid_config.add_route("home", "/")
event = MagicMock(request=self.request)
# should redirect if 'fanstatic.needed' missing from environ
with patch.object(self.request, "environ", new={"foo": "bar"}):
self.assertRaises(HTTPFound, mod.new_request, event)
def test_wutta_config(self):
event = MagicMock(request=self.request)