def test_kotti_static_needed_merged_to_kotti_fanstatic_needed(self, db_session): from kotti import main settings = self.required_settings() settings["kotti.static.needed"] = "kotti.fanstatic.edit_needed" with patch("kotti.resources.initialize_sql"): app = main({}, **settings) groups = app.registry.settings["kotti.fanstatic.view_needed"] resource_names = [[r.relpath for r in group.resources] for group in groups] resource_names = [name for names in resource_names for name in names] assert "view.css" in resource_names settings = self.required_settings() settings["kotti.fanstatic.view_needed"] = "kotti.fanstatic.view_needed" settings["kotti.static.view_needed"] = " kotti.fanstatic.edit_needed" with warnings.catch_warnings(record=True): with patch("kotti.resources.initialize_sql"): app = main({}, **settings) regsettings = app.registry.settings assert len(regsettings["kotti.fanstatic.view_needed"]) == 2 with raises(KeyError): regsettings["kotti.static.view_needed"] groups = regsettings["kotti.fanstatic.view_needed"] resource_names = [[r.relpath for r in group.resources] for group in groups] resource_names = [name for names in resource_names for name in names] assert "edit.css" in resource_names
def setup(self): from kotti import main settings = {'sqlalchemy.url': testing_db_url(), 'kotti.secret': 'dude'} with patch('kotti.resources.initialize_sql'): main({}, **settings)
def test_kotti_static_needed_merged_to_kotti_fanstatic_needed( self, db_session): from kotti import main settings = self.required_settings() settings['kotti.static.needed'] = 'kotti.fanstatic.edit_needed' with patch('kotti.resources.initialize_sql'): app = main({}, **settings) groups = app.registry.settings['kotti.fanstatic.view_needed'] resource_names = [[r.relpath for r in group.resources] for group in groups] resource_names = [name for names in resource_names for name in names] assert 'view.css' in resource_names settings = self.required_settings() settings['kotti.fanstatic.view_needed'] = 'kotti.fanstatic.view_needed' settings['kotti.static.view_needed'] = ' kotti.fanstatic.edit_needed' with warnings.catch_warnings(record=True): with patch('kotti.resources.initialize_sql'): app = main({}, **settings) regsettings = app.registry.settings assert len(regsettings['kotti.fanstatic.view_needed']) == 2 with raises(KeyError): regsettings['kotti.static.view_needed'] groups = regsettings['kotti.fanstatic.view_needed'] resource_names = [[r.relpath for r in group.resources] for group in groups] resource_names = [name for names in resource_names for name in names] assert 'edit.css' in resource_names
def test_asset_overrides(self, db_session): from kotti import main settings = self.required_settings() settings["kotti.asset_overrides"] = "pyramid:scaffold/ pyramid.fixers" with patch("kotti.resources.initialize_sql"): main({}, **settings)
def test_asset_overrides(self, db_session): from kotti import main settings = self.required_settings() settings['kotti.asset_overrides'] = 'pyramid:scaffold/' with patch('kotti.resources.initialize_sql'): main({}, **settings)
def test_kotti_static_needed_merged_to_kotti_fanstatic_needed(self, db_session): from kotti import main settings = self.required_settings() settings['kotti.static.needed'] = 'kotti.fanstatic.edit_needed' with patch('kotti.resources.initialize_sql'): app = main({}, **settings) groups = app.registry.settings['kotti.fanstatic.view_needed'] resource_names = [[r.relpath for r in group.resources] for group in groups] resource_names = [name for names in resource_names for name in names] assert 'view.css' in resource_names settings = self.required_settings() settings['kotti.fanstatic.view_needed'] = 'kotti.fanstatic.view_needed' settings['kotti.static.view_needed'] = ' kotti.fanstatic.edit_needed' with patch('kotti.resources.initialize_sql'): app = main({}, **settings) regsettings = app.registry.settings assert len(regsettings['kotti.fanstatic.view_needed']) == 2 with raises(KeyError): regsettings['kotti.static.view_needed'] groups = regsettings['kotti.fanstatic.view_needed'] resource_names = [[r.relpath for r in group.resources] for group in groups] resource_names = [name for names in resource_names for name in names] assert 'edit.css' in resource_names
def test_use_tables(self): from kotti import main settings = self.required_settings() settings["kotti.populators"] = "" settings["kotti.use_tables"] = "principals" main({}, **settings)
def test_asset_overrides(self, db_session): from kotti import main settings = self.required_settings() settings['kotti.asset_overrides'] = 'pyramid:scaffold/ pyramid.fixers' with patch('kotti.resources.initialize_sql'): main({}, **settings)
def test_use_tables(self): from kotti import main settings = self.required_settings() settings['kotti.populators'] = '' settings['kotti.use_tables'] = 'principals' main({}, **settings)
def test_use_tables(self, db_session): from kotti import main settings = self.required_settings() settings["kotti.populators"] = "" settings["kotti.use_tables"] = "principals" with patch("kotti.resources.initialize_sql"): main({}, **settings)
def test_search_content(self): from kotti import main from kotti.views.util import search_content settings = self.required_settings() settings['kotti.search_content'] = 'kotti.tests.test_app._dummy_search' main({}, **settings) assert search_content(u"Nuno") == u"Not found. Sorry!"
def test_use_tables(self, db_session): from kotti import main settings = self.required_settings() settings['kotti.populators'] = '' settings['kotti.use_tables'] = 'principals' with patch('kotti.resources.initialize_sql'): main({}, **settings)
def test_asset_overrides(self, db_session): from kotti import main settings = self.required_settings() settings["kotti.asset_overrides"] = "pyramid:scaffold/" with patch("kotti.resources.initialize_sql"): with patch("kotti.filedepot.TweenFactory"): main({}, **settings)
def test_default_filedepot(self, db_session): from kotti import main from depot.manager import DepotManager settings = self.required_settings() with patch('kotti.resources.initialize_sql'): main({}, **settings) assert DepotManager.get().__class__.__name__ == 'DBFileStorage'
def test_use_tables(self, db_session): from kotti import main settings = self.required_settings() settings["kotti.populators"] = "" settings["kotti.use_tables"] = "principals" with patch("kotti.resources.initialize_sql"): with patch("kotti.filedepot.TweenFactory"): main({}, **settings)
def test_search_content(self, db_session): from kotti import main from kotti.views.util import search_content settings = self.required_settings() settings['kotti.search_content'] = 'kotti.testing.dummy_search' with patch('kotti.resources.initialize_sql'): main({}, **settings) assert search_content(u"Nuno") == u"Not found. Sorry!"
def test_setting_values_as_unicode(self): from kotti import get_settings from kotti import main settings = self.required_settings() settings['kotti.site_title'] = 'K\xc3\xb6tti' # Kötti main({}, **settings) self.assertEqual(get_settings()['kotti.site_title'], u'K\xf6tti')
def test_auth_policies_no_override(self): from kotti import main settings = self.required_settings() main({}, **settings) registry = get_current_registry() assert registry.queryUtility(IAuthenticationPolicy) is not None assert registry.queryUtility(IAuthorizationPolicy) is not None
def test_search_content(self, db_session): from kotti import main from kotti.views.util import search_content settings = self.required_settings() settings["kotti.search_content"] = "kotti.testing.dummy_search" with patch("kotti.resources.initialize_sql"): with patch("kotti.filedepot.TweenFactory"): main({}, **settings) assert search_content("Nuno") == "Not found. Sorry!"
def test_auth_policies_no_override(self, db_session): from kotti import main settings = self.required_settings() with patch('kotti.resources.initialize_sql'): main({}, **settings) registry = get_current_registry() assert registry.queryUtility(IAuthenticationPolicy) is not None assert registry.queryUtility(IAuthorizationPolicy) is not None
def test_stamp_heads(self): from kotti import main from kotti import DBSession settings = self.required_settings() main({}, **settings) res = DBSession.execute(select( columns=['version_num'], from_obj=['kotti_alembic_version'])) assert tuple(res) # a version_num should exist
def test_auth_policies_override(self): from kotti import main 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) is None assert registry.queryUtility(IAuthorizationPolicy) is None
def test_kotti_includes_deprecation_warning(self): from kotti import main settings = self.required_settings() settings["kotti.includes"] = "kotti.tests.test_app._includeme_layout" with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") main({}, **settings) assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) msg = str(w[-1].message) assert "The 'kotti.includes' setting has been deprecated" in msg
def test_stamp_heads(self, db_session, connection): from kotti import main settings = self.required_settings() engine = connection.engine engine.table_names = Mock(return_value=[]) with patch("kotti.engine_from_config", return_value=engine): with patch("kotti.resources.metadata"): main({}, **settings) res = db_session.execute(select(columns=["version_num"], from_obj=["kotti_alembic_version"])) assert tuple(res) # a version_num should exist
def test_auth_policies_no_override(self): from pyramid.interfaces import IAuthenticationPolicy from pyramid.interfaces import IAuthorizationPolicy from pyramid.threadlocal import get_current_registry from kotti import main settings = self.required_settings() main({}, **settings) registry = get_current_registry() assert registry.queryUtility(IAuthenticationPolicy) != None assert registry.queryUtility(IAuthorizationPolicy) != None
def test_auth_policies_override(self, db_session): from kotti import main settings = self.required_settings() settings["kotti.authn_policy_factory"] = "kotti.none_factory" settings["kotti.authz_policy_factory"] = "kotti.none_factory" with patch("kotti.resources.initialize_sql"): main({}, **settings) registry = get_current_registry() assert registry.queryUtility(IAuthenticationPolicy) is None assert registry.queryUtility(IAuthorizationPolicy) is None
def test_kotti_static_needed_deprecation_warning(self, db_session): from kotti import main settings = self.required_settings() settings['kotti.static.view_needed'] = (' kotti.fanstatic.view_needed') with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') with patch('kotti.resources.initialize_sql'): main({}, **settings) assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) msg = str(w[-1].message) assert "The 'kotti.static.view_needed' setting has been deprecated" in msg
def test_kotti_includes_deprecation_warning(self): from kotti import main settings = self.required_settings() settings['kotti.includes'] = ( 'kotti.tests.test_app._includeme_layout') with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') main({}, **settings) assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) msg = str(w[-1].message) assert "The 'kotti.includes' setting has been deprecated" in msg
def test_auth_policies_override(self, db_session): from kotti import main settings = self.required_settings() settings['kotti.authn_policy_factory'] = 'kotti.none_factory' settings['kotti.authz_policy_factory'] = 'kotti.none_factory' with patch('kotti.resources.initialize_sql'): with patch('kotti.filedepot.TweenFactory'): main({}, **settings) registry = get_current_registry() assert registry.queryUtility(IAuthenticationPolicy) is None assert registry.queryUtility(IAuthorizationPolicy) is None
def test_setting_values_as_unicode(self): from kotti import get_settings from kotti import main settings = self.required_settings() settings['kotti.site_title'] = 'K\xc3\xb6tti' # Kötti settings['kotti_foo.site_title'] = 'K\xc3\xb6tti' settings['foo.site_title'] = 'K\xc3\xb6tti' main({}, **settings) assert get_settings()['kotti.site_title'] == u'K\xf6tti' assert get_settings()['kotti_foo.site_title'] == u'K\xf6tti' assert get_settings()['foo.site_title'] == 'K\xc3\xb6tti'
def test_setting_values_as_unicode(self, db_session): from kotti import get_settings from kotti import main settings = self.required_settings() settings['kotti.site_title'] = 'K\xc3\xb6tti' # Kötti settings['kotti_foo.site_title'] = 'K\xc3\xb6tti' settings['foo.site_title'] = 'K\xc3\xb6tti' with patch('kotti.resources.initialize_sql'): main({}, **settings) assert get_settings()['kotti.site_title'] == u'K\xf6tti' assert get_settings()['kotti_foo.site_title'] == u'K\xf6tti' assert get_settings()['foo.site_title'] == 'K\xc3\xb6tti'
def test_stamp_heads(self, db_session, connection): from kotti import main settings = self.required_settings() engine = connection.engine engine.table_names = Mock(return_value=[]) with patch('kotti.engine_from_config', return_value=engine): with patch('kotti.resources.metadata'): main({}, **settings) res = db_session.execute( select(columns=['version_num'], from_obj=['kotti_alembic_version'])) assert tuple(res) # a version_num should exist
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])
def test_setting_values_as_unicode(self, db_session): from kotti import get_settings from kotti import main settings = self.required_settings() settings["kotti.site_title"] = "K\xc3\xb6tti" # Kötti settings["kotti_foo.site_title"] = "K\xc3\xb6tti" settings["foo.site_title"] = "K\xc3\xb6tti" with patch("kotti.resources.initialize_sql"): main({}, **settings) assert get_settings()["kotti.site_title"] == u"K\xf6tti" assert get_settings()["kotti_foo.site_title"] == u"K\xf6tti" assert get_settings()["foo.site_title"] == "K\xc3\xb6tti"
def test_setting_values_as_unicode(self, db_session, filedepot): from kotti import get_settings from kotti import main settings = self.required_settings() settings["kotti.site_title"] = b"K\xc3\xb6tti" # Kötti settings["kotti_foo.site_title"] = b"K\xc3\xb6tti" settings["foo.site_title"] = b"K\xc3\xb6tti" with patch("kotti.resources.initialize_sql"): with patch("kotti.filedepot.TweenFactory"): main({}, **settings) assert get_settings()["kotti.site_title"] == "Kötti" assert get_settings()["kotti_foo.site_title"] == "Kötti" assert get_settings()["foo.site_title"] == b"K\xc3\xb6tti"
def setUpFunctional(global_config=None, **settings): from kotti import main from zope.testbrowser.wsgi import Browser 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): from kotti import main from zope.testbrowser.wsgi import Browser 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): from kotti import main import wsgi_intercept.zope_testbrowser 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) wsgi_intercept.add_wsgi_intercept(host[2:], int(port), lambda: app) Browser = wsgi_intercept.zope_testbrowser.WSGI_Browser Browser.pyquery = property(_zope_testbrowser_pyquery) return dict( Browser=Browser, browser=Browser(), test_app=TestApp(app), )
def setUpFunctional(global_config=None, **settings): from kotti import main from zope.testbrowser.wsgi import Browser 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 setup_app(): from mock import patch from kotti import main with patch('kotti.resources.initialize_sql'): with patch('kotti.engine_from_config'): app = main({}, **settings()) return app
def setUpFunctional(global_config=None, **settings): from kotti import main import wsgi_intercept.zope_testbrowser 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', } _settings.update(settings) host, port = BASE_URL.split(':')[-2:] app = main({}, **_settings) wsgi_intercept.add_wsgi_intercept(host[2:], int(port), lambda: app) Browser = wsgi_intercept.zope_testbrowser.WSGI_Browser return dict( Browser=Browser, browser=Browser(), test_app=TestApp(app), )
def setUpFunctional(global_config=None, **settings): from kotti import main import wsgi_intercept.zope_testbrowser from webtest import TestApp tearDown() _settings = { 'sqlalchemy.url': testing_db_url(), 'kotti.secret': 'secret', 'kotti.site_title': 'Test Splash Page', # for mailing 'kotti.populators': 'kotti.testing._populator\nkotti_splashpage.populate', 'mail.default_sender': 'kotti@localhost', 'kotti.includes': 'kotti_splashpage' } _settings.update(settings) host, port = BASE_URL.split(':')[-2:] app = main({}, **_settings) wsgi_intercept.add_wsgi_intercept(host[2:], int(port), lambda: app) Browser = wsgi_intercept.zope_testbrowser.WSGI_Browser return dict( Browser=Browser, browser=Browser(), test_app=TestApp(app), )
def test_override_settings(self): from kotti import main from kotti import get_settings 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])
def test_stamp_heads(self, db_session, connection): from kotti import main settings = self.required_settings() engine = connection.engine engine.table_names = Mock(return_value=[]) with patch("kotti.engine_from_config", return_value=engine): with patch("kotti.resources.metadata"): with patch("kotti.filedepot.TweenFactory"): main({}, **settings) res = db_session.execute( select( columns=[column("version_num")], from_obj=[table("kotti_alembic_version")], )) assert tuple(res) # a version_num should exist
def test_override_settings(self, db_session): from kotti import main from kotti import get_settings 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] with patch('kotti.resources.initialize_sql'): main({}, **settings) assert get_settings()['kotti.base_includes'] == [] assert get_settings()['kotti.available_types'] == [MyType]