From 702e5e01437ef11a4d03ceaa6b57aeeb940bd86d Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 6 Mar 2014 18:24:53 -0800 Subject: [PATCH] perms test: moved test perms policy to perms/test/test_perms_policy.py all perms related configs exist within perms package --- pywb/perms/test/__init__.py | 0 pywb/perms/test/test_perms_policy.py | 35 ++++++++++++++++++++++++++++ test_config.yaml | 2 +- tests/fixture.py | 25 -------------------- tests/test_integration.py | 2 -- 5 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 pywb/perms/test/__init__.py create mode 100644 pywb/perms/test/test_perms_policy.py diff --git a/pywb/perms/test/__init__.py b/pywb/perms/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pywb/perms/test/test_perms_policy.py b/pywb/perms/test/test_perms_policy.py new file mode 100644 index 00000000..429291d3 --- /dev/null +++ b/pywb/perms/test/test_perms_policy.py @@ -0,0 +1,35 @@ +""" +An example perms policy used for testing +this policy is enabled by adding the following setting to the +main config.yaml + +perms_policy: !!python/name:pywb.perms.test.test_perms_policy.perms_policy +""" + +from pywb.perms.perms_filter import Perms + + +#================================================================ +class TestExclusionPerms(Perms): + """ + Perm Checker fixture to block a single url for testing + """ + # sample_archive has captures for this URLKEY + URLKEY_EXCLUDED = 'org,iana)/_img/bookmark_icon.ico' + + def allow_url_lookup(self, urlkey): + """ + Return true/false if url (canonicalized url) + should be allowed + """ + if urlkey == self.URLKEY_EXCLUDED: + return False + + return super(TestExclusionPerms, self).allow_url_lookup(urlkey) + + +#================================================================ +def perms_policy(wbrequest): + return TestExclusionPerms() + + diff --git a/test_config.yaml b/test_config.yaml index 8517834f..c955a649 100644 --- a/test_config.yaml +++ b/test_config.yaml @@ -101,4 +101,4 @@ reporter: !!python/object/new:tests.fixture.PrintReporter [] #domain_specific_rules: rules.yaml #perms_checker: !!python/object/new:pywb.cdx.perms.AllowAllPerms [] -perms_policy: !!python/name:tests.fixture.test_exclusion_perms_policy +perms_policy: !!python/name:pywb.perms.test.test_perms_policy.perms_policy diff --git a/tests/fixture.py b/tests/fixture.py index a032d081..e42abfcc 100644 --- a/tests/fixture.py +++ b/tests/fixture.py @@ -3,8 +3,6 @@ import pytest import yaml -from pywb.perms.perms_filter import Perms - @pytest.fixture def testconfig(): config = yaml.load(open('test_config.yaml')) @@ -25,26 +23,3 @@ class PrintReporter: print wbrequest print cdx pass - -#================================================================ -class TestExclusionPerms(Perms): - """ - Perm Checker fixture to block a single url for testing - """ - # sample_archive has captures for this URLKEY - URLKEY_EXCLUDED = 'org,iana)/_img/bookmark_icon.ico' - - def allow_url_lookup(self, urlkey): - """ - Return true/false if url (canonicalized url) - should be allowed - """ - if urlkey == self.URLKEY_EXCLUDED: - return False - - return super(TestExclusionPerms, self).allow_url_lookup(urlkey) - - -#================================================================ -def test_exclusion_perms_policy(wbrequest): - return TestExclusionPerms() diff --git a/tests/test_integration.py b/tests/test_integration.py index c9cd5c68..fe224e9f 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -3,8 +3,6 @@ from pywb.core.pywb_init import create_wb_router from pywb.framework.wsgi_wrappers import init_app from pywb.cdx.cdxobject import CDXObject -from fixture import TestExclusionPerms - class TestWb: TEST_CONFIG = 'test_config.yaml'