diff --git a/ordr/models/meta.py b/ordr/models/meta.py index 02285b3..491d497 100644 --- a/ordr/models/meta.py +++ b/ordr/models/meta.py @@ -10,7 +10,7 @@ NAMING_CONVENTION = { "ck": "ck_%(table_name)s_%(constraint_name)s", "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", "pk": "pk_%(table_name)s" -} + } metadata = MetaData(naming_convention=NAMING_CONVENTION) Base = declarative_base(metadata=metadata) diff --git a/ordr/models/mymodel.py b/ordr/models/mymodel.py index d65a01a..8c9d701 100644 --- a/ordr/models/mymodel.py +++ b/ordr/models/mymodel.py @@ -3,7 +3,7 @@ from sqlalchemy import ( Index, Integer, Text, -) + ) from .meta import Base diff --git a/ordr/resources/__init__.py b/ordr/resources/__init__.py index 5c3cec2..65c5e36 100644 --- a/ordr/resources/__init__.py +++ b/ordr/resources/__init__.py @@ -10,7 +10,7 @@ class RootResource: ''' def __init__(self, request): - ''' Create the root resource + ''' Create the root resource :param pyramid.request.Request request: the current request object ''' diff --git a/ordr/security.py b/ordr/security.py index 2545697..e4f66f2 100644 --- a/ordr/security.py +++ b/ordr/security.py @@ -13,17 +13,16 @@ def crypt_context_settings_to_string(settings, prefix='passlib.'): :rtype: (str) config string in INI format for CryptContext.load() This looks at first like a dump hack, but the parsing of all possible - context settings is quite a task. Since passlib has a context parser + context settings is quite a task. Since passlib has a context parser included, this seems the most reliable way to do it. ''' - as_list_keys = {'schemes', 'deprecated'} config_lines = ['[passlib]'] for ini_key, value in settings.items(): if ini_key.startswith(prefix): - context_key = ini_key.replace(prefix, '') - # the pyramid .ini format is different on lists + context_key = ini_key.replace(prefix, '') + # the pyramid .ini format is different on lists # than the .ini format used by passlib. - if context_key in as_list_keys and ',' not in value: + if context_key in {'schemes', 'deprecated'} and ',' not in value: value = ','.join(aslist(value)) config_lines.append(f'{context_key} = {value}') return '\n'.join(config_lines) @@ -32,7 +31,7 @@ def crypt_context_settings_to_string(settings, prefix='passlib.'): def includeme(config): ''' initializing authentication, authorization and password hash settings - Activate this setup using ``config.include('ordr2.security')``. + Activate this setup using ``config.include('ordr.security')``. ''' settings = config.get_settings() diff --git a/ordr/tests/_functional/__init__.py b/ordr/tests/_functional/__init__.py index 4866f56..adb6358 100644 --- a/ordr/tests/_functional/__init__.py +++ b/ordr/tests/_functional/__init__.py @@ -15,7 +15,6 @@ class CustomTestApp(webtest.TestApp): pass - @pytest.fixture(scope='module') def testapp(): ''' fixture for using webtest ''' diff --git a/ordr/tests/_functional/errors.py b/ordr/tests/_functional/errors.py index aa11657..ec4ca19 100644 --- a/ordr/tests/_functional/errors.py +++ b/ordr/tests/_functional/errors.py @@ -1,8 +1,8 @@ ''' functional tests for ordr2.views.errors ''' -from . import testapp +from . import testapp # noqa: F401 -def test_404(testapp): +def test_404(testapp): # noqa: F811 result = testapp.get('/unknown', status=404) assert '404' in result diff --git a/ordr/tests/_functional/pages.py b/ordr/tests/_functional/pages.py index 99b86fc..1901e36 100644 --- a/ordr/tests/_functional/pages.py +++ b/ordr/tests/_functional/pages.py @@ -1,13 +1,13 @@ ''' functional tests for ordr2.views.pages ''' -from . import testapp +from . import testapp # noqa: F401 -def test_welcome(testapp): +def test_welcome(testapp): # noqa: F811 result = testapp.get('/') assert 'Ordr' in result -def test_faq(testapp): +def test_faq(testapp): # noqa: F811 result = testapp.get('/faq') assert 'FAQ' in result diff --git a/ordr/tests/resources/__init__.py b/ordr/tests/resources/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ordr/tests/resources/__init__.py @@ -0,0 +1 @@ + diff --git a/ordr/tests/resources/root_resource.py b/ordr/tests/resources/root_resource.py new file mode 100644 index 0000000..fae6938 --- /dev/null +++ b/ordr/tests/resources/root_resource.py @@ -0,0 +1,14 @@ + +def test_root_init(): + from ordr.resources import RootResource + root = RootResource('request') + assert root.__name__ == None + assert root.__parent__ == None + assert root.request == 'request' + + +def test_root_acl(): + from pyramid.security import Allow, Everyone, DENY_ALL + from ordr.resources import RootResource + root = RootResource(None) + assert root.__acl__() == [(Allow, Everyone, 'view'), DENY_ALL] diff --git a/ordr/tests/security.py b/ordr/tests/security.py new file mode 100644 index 0000000..4b1fdb5 --- /dev/null +++ b/ordr/tests/security.py @@ -0,0 +1,17 @@ + +def test_crypt_context_to_settings(): + from ordr.security import crypt_context_settings_to_string + settings = { + 'no_prefix': 'should not appear', + 'prefix.something': 'left unchanged', + 'prefix.schemes': 'adjust list', + 'prefix.depreceated': 'do, not, adjust, this, list' + } + result = crypt_context_settings_to_string(settings, 'prefix.') + expected_lines = { + '[passlib]', + 'something = left unchanged', + 'schemes = adjust,list', + 'depreceated = do, not, adjust, this, list', + } + assert set(result.split('\n')) == expected_lines diff --git a/ordr/tests/views/__init__.py b/ordr/tests/views/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ordr/tests/views/__init__.py @@ -0,0 +1 @@ + diff --git a/ordr/tests/views/errors.py b/ordr/tests/views/errors.py index 93a5c92..1ea30e4 100644 --- a/ordr/tests/views/errors.py +++ b/ordr/tests/views/errors.py @@ -1,5 +1,6 @@ from pyramid.testing import DummyRequest + def test_welcome(): from ordr.views.errors import notfound_view request = DummyRequest() diff --git a/ordr/tests/views/pages.py b/ordr/tests/views/pages.py index 862061b..82547b5 100644 --- a/ordr/tests/views/pages.py +++ b/ordr/tests/views/pages.py @@ -10,5 +10,3 @@ def test_faq(): from ordr.views.pages import faq result = faq(None, None) assert result == {} - - diff --git a/ordr/views/pages.py b/ordr/views/pages.py index e64237d..61f1c11 100644 --- a/ordr/views/pages.py +++ b/ordr/views/pages.py @@ -2,7 +2,7 @@ from pyramid.view import view_config @view_config( - context='ordr.resources.RootResource', + context='ordr.resources.RootResource', permission='view', renderer='ordr:templates/pages/welcome.jinja2', ) @@ -11,7 +11,7 @@ def welcome(context, request): @view_config( - context='ordr.resources.RootResource', + context='ordr.resources.RootResource', name='faq', permission='view', renderer='ordr:templates/pages/faq.jinja2'