Browse Source

added tests for root resource and security module

rework
Holger Frey 7 years ago
parent
commit
3b9246633a
  1. 2
      ordr/models/meta.py
  2. 2
      ordr/models/mymodel.py
  3. 5
      ordr/security.py
  4. 1
      ordr/tests/_functional/__init__.py
  5. 4
      ordr/tests/_functional/errors.py
  6. 6
      ordr/tests/_functional/pages.py
  7. 1
      ordr/tests/resources/__init__.py
  8. 14
      ordr/tests/resources/root_resource.py
  9. 17
      ordr/tests/security.py
  10. 1
      ordr/tests/views/__init__.py
  11. 1
      ordr/tests/views/errors.py
  12. 2
      ordr/tests/views/pages.py

2
ordr/models/meta.py

@ -10,7 +10,7 @@ NAMING_CONVENTION = { @@ -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)

2
ordr/models/mymodel.py

@ -3,7 +3,7 @@ from sqlalchemy import ( @@ -3,7 +3,7 @@ from sqlalchemy import (
Index,
Integer,
Text,
)
)
from .meta import Base

5
ordr/security.py

@ -16,14 +16,13 @@ def crypt_context_settings_to_string(settings, prefix='passlib.'): @@ -16,14 +16,13 @@ def crypt_context_settings_to_string(settings, prefix='passlib.'):
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
# 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.'): @@ -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()

1
ordr/tests/_functional/__init__.py

@ -15,7 +15,6 @@ class CustomTestApp(webtest.TestApp): @@ -15,7 +15,6 @@ class CustomTestApp(webtest.TestApp):
pass
@pytest.fixture(scope='module')
def testapp():
''' fixture for using webtest '''

4
ordr/tests/_functional/errors.py

@ -1,8 +1,8 @@ @@ -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

6
ordr/tests/_functional/pages.py

@ -1,13 +1,13 @@ @@ -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

1
ordr/tests/resources/__init__.py

@ -0,0 +1 @@ @@ -0,0 +1 @@

14
ordr/tests/resources/root_resource.py

@ -0,0 +1,14 @@ @@ -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]

17
ordr/tests/security.py

@ -0,0 +1,17 @@ @@ -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

1
ordr/tests/views/__init__.py

@ -0,0 +1 @@ @@ -0,0 +1 @@

1
ordr/tests/views/errors.py

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
from pyramid.testing import DummyRequest
def test_welcome():
from ordr.views.errors import notfound_view
request = DummyRequest()

2
ordr/tests/views/pages.py

@ -10,5 +10,3 @@ def test_faq(): @@ -10,5 +10,3 @@ def test_faq():
from ordr.views.pages import faq
result = faq(None, None)
assert result == {}