Add a test to verify that all important blueprints have all their methods decorated
This ensures that we don't accidentally add a blueprint method without either explicitly blacklisting or whitelisting anonymous access
This commit is contained in:
parent
075c75d031
commit
477a3fdcdc
6 changed files with 57 additions and 4 deletions
33
test/test_anon_checked.py
Normal file
33
test/test_anon_checked.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import unittest
|
||||
|
||||
from endpoints.tags import tags
|
||||
from endpoints.registry import registry
|
||||
from endpoints.index import index
|
||||
from endpoints.verbs import verbs
|
||||
|
||||
|
||||
class TestAnonymousAccessChecked(unittest.TestCase):
|
||||
def verifyBlueprint(self, blueprint):
|
||||
class Checker(object):
|
||||
def __init__(self, test_case):
|
||||
self.test_case = test_case
|
||||
|
||||
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(tags)
|
||||
self.verifyBlueprint(registry)
|
||||
self.verifyBlueprint(index)
|
||||
self.verifyBlueprint(verbs)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in a new issue