Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from webtest import TestApp
tearDown()
_settings = {
"sqlalchemy.url": testing_db_url(),
"kotti.secret": "secret",
"kotti.site_title": "Website des Kottbusser Tors", # for mailing
"kotti.populators": "kotti.testing._populator",
"mail.default_sender": "kotti@localhost",
"pyramid.includes": "kotti.testing._functional_includeme",
}
_settings.update(settings)
host, port = BASE_URL.split(":")[-2:]
app = main({}, **_settings)
Browser.pyquery = property(_zope_testbrowser_pyquery)
return dict(
Browser=lambda: Browser(
"http://{}:{}/".format(host[2:], int(port)), wsgi_app=app
),
browser=Browser("http://{}:{}/".format(host[2:], int(port)), wsgi_app=app),
test_app=TestApp(app),
)
def setUpFunctional(global_config=None, **settings):
import wsgi_intercept.zope_testbrowser
_settings = {
'sqlalchemy.url': testing_db_url(),
'kotti.secret': 'secret',
'kotti.site_title': 'Website des Kottbusser Tors', # for mailing
'kotti.populators': 'kotti.tests._populator',
'mail.default_sender': 'kotti@localhost',
}
_settings.update(settings)
host, port = BASE_URL.split(':')[-2:]
app = main({}, **_settings)
wsgi_intercept.add_wsgi_intercept(host[2:], int(port), lambda: app)
return dict(Browser=wsgi_intercept.zope_testbrowser.WSGI_Browser)
def test_auth_policies_override(self):
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.interfaces import IAuthorizationPolicy
from pyramid.threadlocal import get_current_registry
settings = self.required_settings()
settings['kotti.authn_policy_factory'] = 'kotti.none_factory'
settings['kotti.authz_policy_factory'] = 'kotti.none_factory'
main({}, **settings)
registry = get_current_registry()
assert registry.queryUtility(IAuthenticationPolicy) == None
assert registry.queryUtility(IAuthorizationPolicy) == None
def test_use_tables(self):
settings = self.required_settings()
settings['kotti.populators'] = ''
settings['kotti.use_tables'] = 'principals'
main({}, **settings)
def test_includes_overrides(self):
settings = self.required_settings()
settings['kotti.includes'] = 'kotti.tests.TestMain._includeme'
main({}, **settings)
def test_root_factory(self):
settings = self.required_settings()
settings['kotti.root_factory'] = 'kotti.tests.TestMain._root_factory'
app = main({}, **settings)
assert get_root() == 'my root object'
assert app.root_factory() == 'my root object'
def test_auth_policies_no_override(self):
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.interfaces import IAuthorizationPolicy
from pyramid.threadlocal import get_current_registry
settings = self.required_settings()
main({}, **settings)
registry = get_current_registry()
assert registry.queryUtility(IAuthenticationPolicy) != None
assert registry.queryUtility(IAuthorizationPolicy) != None
def test_override_settings(self):
class MyType(object):
pass
def my_configurator(conf):
conf['kotti.base_includes'] = ''
conf['kotti.available_types'] = [MyType]
settings = self.required_settings()
settings['kotti.configurators'] = [my_configurator]
main({}, **settings)
self.assertEqual(get_settings()['kotti.base_includes'], [])
self.assertEqual(get_settings()['kotti.available_types'], [MyType])