Move anon checked test to pytest
This commit is contained in:
parent
31bfa697f3
commit
d32efc4e17
2 changed files with 27 additions and 31 deletions
27
endpoints/test/test_anon_checked.py
Normal file
27
endpoints/test/test_anon_checked.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app import app
|
||||||
|
from endpoints.v1 import v1_bp
|
||||||
|
from endpoints.v2 import v2_bp
|
||||||
|
from endpoints.verbs import verbs
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('blueprint', [
|
||||||
|
v2_bp,
|
||||||
|
v1_bp,
|
||||||
|
verbs,
|
||||||
|
])
|
||||||
|
def test_verify_blueprint(blueprint):
|
||||||
|
class Checker(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.first_registration = True
|
||||||
|
self.app = app
|
||||||
|
|
||||||
|
def add_url_rule(self, rule, endpoint, view_function, methods=None):
|
||||||
|
result = ('__anon_protected' in dir(view_function) or
|
||||||
|
'__anon_allowed' in dir(view_function))
|
||||||
|
error_message = ('Missing anonymous access protection decorator on function ' +
|
||||||
|
'%s under blueprint %s' % (endpoint, blueprint.name))
|
||||||
|
assert result, error_message
|
||||||
|
|
||||||
|
for deferred_function in blueprint.deferred_functions:
|
||||||
|
deferred_function(Checker())
|
|
@ -1,31 +0,0 @@
|
||||||
import unittest
|
|
||||||
|
|
||||||
from endpoints.v1 import v1_bp
|
|
||||||
from endpoints.verbs import verbs
|
|
||||||
from app import app
|
|
||||||
|
|
||||||
class TestAnonymousAccessChecked(unittest.TestCase):
|
|
||||||
def verifyBlueprint(self, blueprint):
|
|
||||||
class Checker(object):
|
|
||||||
def __init__(self, test_case):
|
|
||||||
self.test_case = test_case
|
|
||||||
self.first_registration = True
|
|
||||||
self.app = app
|
|
||||||
|
|
||||||
def add_url_rule(self, rule, endpoint, view_function, methods=None):
|
|
||||||
if (not '__anon_protected' in dir(view_function) and
|
|
||||||
not '__anon_allowed' in dir(view_function)):
|
|
||||||
error_message = ('Missing anonymous access protection decorator on function ' +
|
|
||||||
'%s under blueprint %s' % (endpoint, blueprint.name))
|
|
||||||
self.test_case.fail(error_message)
|
|
||||||
|
|
||||||
for deferred_function in blueprint.deferred_functions:
|
|
||||||
deferred_function(Checker(self))
|
|
||||||
|
|
||||||
def test_anonymous_access_checked(self):
|
|
||||||
self.verifyBlueprint(v1_bp)
|
|
||||||
self.verifyBlueprint(verbs)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
|
Reference in a new issue