mirror of https://github.com/scrapy/scrapy.git
Support case-insensitive policy names in settings
This commit is contained in:
parent
e72b6e3361
commit
0344f57fef
|
|
@ -229,7 +229,7 @@ class RefererMiddleware(object):
|
|||
self.default_policy = load_object(policy)
|
||||
except ValueError:
|
||||
try:
|
||||
self.default_policy = _policy_classes[policy]
|
||||
self.default_policy = _policy_classes[policy.lower()]
|
||||
except:
|
||||
raise NotConfigured("Unknown referrer policy name %r" % policy)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -310,6 +310,20 @@ class TestRefererMiddlewareSettingsPolicyByName(TestCase):
|
|||
mw = RefererMiddleware(settings)
|
||||
self.assertEquals(mw.default_policy, p)
|
||||
|
||||
def test_valid_name_casevariants(self):
|
||||
for s, p in [
|
||||
(POLICY_SCRAPY_DEFAULT, DefaultReferrerPolicy),
|
||||
(POLICY_NO_REFERRER, NoReferrerPolicy),
|
||||
(POLICY_NO_REFERRER_WHEN_DOWNGRADE, NoReferrerWhenDowngradePolicy),
|
||||
(POLICY_SAME_ORIGIN, SameOriginPolicy),
|
||||
(POLICY_ORIGIN, OriginPolicy),
|
||||
(POLICY_ORIGIN_WHEN_CROSS_ORIGIN, OriginWhenCrossOriginPolicy),
|
||||
(POLICY_UNSAFE_URL, UnsafeUrlPolicy),
|
||||
]:
|
||||
settings = Settings({'REFERER_POLICY': s.upper()})
|
||||
mw = RefererMiddleware(settings)
|
||||
self.assertEquals(mw.default_policy, p)
|
||||
|
||||
def test_invalid_name(self):
|
||||
settings = Settings({'REFERER_POLICY': 'some-custom-unknown-policy'})
|
||||
with self.assertRaises(NotConfigured):
|
||||
|
|
|
|||
Loading…
Reference in New Issue