def multifolder_config(request): """Test with two ways of setting many locations for config.""" return factories.pyramid_config({ 'env': 'prod', 'yaml.location': request.param, 'pyramid.includes': ['tzf.pyramid_yml'] })(request)
def prod_config(request): """Basic with env set parametrized for different configuration location.""" return factories.pyramid_config({ 'env': 'prod', 'yaml.location': request.param, 'pyramid.includes': ['tzf.pyramid_yml'] })(request)
"""Tests conftest module.""" from pytest_pyramid import factories # pylint:disable=invalid-name clean_config = factories.pyramid_config({}) simplerouting_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing', 'pyramid.includes': ['tzf.pyramid_routing'] }) moduled_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing_moduled', 'pyramid.includes': ['tzf.pyramid_routing'] }) two_moduled_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing_two_moduled', 'pyramid.includes': ['tzf.pyramid_routing'] }) prefixed_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing_prefixed', 'pyramid.includes': ['tzf.pyramid_routing'] })
"""pyramid_decoy's main test.""" from pytest_pyramid import factories decoy_config = factories.pyramid_config({ 'pyramid.includes': ['pyramid_decoy'], 'decoy.url': 'http://www.example.com/', }) decoy_app = factories.pyramid_app('decoy_config')
# This module is part of pytest_pyramid and is released under # the MIT License (MIT): http://opensource.org/licenses/MIT """Plugin's definition and basic fixtures.""" from pytest_pyramid import factories _help_config = "Path to default config ini for tests" def pytest_addoption(parser): """Pytest option configurator.""" parser.addini( 'pyramid_config', default=None, help=_help_config, ) parser.addoption( '--pc', action='store', default=None, metavar='path', dest='pyramid_config', help=_help_config, ) # fixtures (made out of factories) pyramid_config = factories.pyramid_config() pyramid_app = factories.pyramid_app('pyramid_config')
# (quoted strings must be dot separated, or the only element making up the local-part) text_type('just"not"*****@*****.**'), # (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash) text_type('this is"not\[email protected]'), # (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes) text_type('this\ still\"not\\[email protected]'), text_type('bad-mail'), ]) def invalid_email(request): """Parametrized fixture with all the incorrect emails.""" return request.param default_config = factories.pyramid_config({ 'pyramid.includes': [ 'pyramid_tm', 'pyramid_fullauth' ] }) extended_config = factories.pyramid_config({ 'pyramid.includes': [ 'pyramid_tm', 'pyramid_fullauth', 'tests.tools.include_views' ] }) short_config = factories.pyramid_config({ 'yml.location': 'tests:config/short_memory.yaml',
"""pyramid_decoy's main test.""" from pytest_pyramid import factories decoy_config = factories.pyramid_config({ # pylint:disable=invalid-name 'pyramid.includes': [ 'pyramid_decoy' ], 'decoy.url': 'http://www.example.com/', }) decoy_app = factories.pyramid_app('decoy_config') # pylint:disable=invalid-name
def test_pyramid_app(pyramid_app): """ Make sure we have everything needed for pyramid integration tests running. Check if: - app is instance of TestApp - we get proper status code from not defined route """ assert isinstance(pyramid_app, TestApp) res = pyramid_app.get('/', status=404) assert res.status_code == 404 pyramid_config_path = factories.pyramid_config( config_path='tests/pyramid.test.ini' ) pyramid_config_inheritance = factories.pyramid_config( config_path='tests/pyramid.use.test.ini' ) pyramid_config_settings = factories.pyramid_config(settings={'env': 'pytest'}) def test_pyramid_config(pyramid_config, pyramid_config_path): """Test whether both fixtures are generated correctly.""" assert isinstance(pyramid_config, Configurator) assert isinstance(pyramid_config_path, Configurator) assert pyramid_config_path != pyramid_config assert pyramid_config_path.registry.settings ==\ pyramid_config.registry.settings
AfterEmailChange, AfterEmailChangeActivation, BeforeReset, AfterResetRequest, AfterReset, AfterSocialRegister, AfterSocialLogIn, SocialAccountAlreadyConnected, AfterActivate, BeforeRegister, AfterRegister) from tests.tools import authenticate, is_user_logged, DEFAULT_USER from tests.conftest import py2only from tests.views.conftest import mock_translate EVENT_PATH = '/event?event={0.__name__}' EVENT_URL = 'http://localhost' + EVENT_PATH evented_config = factories.pyramid_config({ 'yml.location': 'tests:config', 'env': 'login', 'pyramid.includes': [ 'pyramid_tm', 'pyramid_fullauth', 'tests.tools.include_views', 'tests.views.test_events.include_views' ] }) def include_views(config): """Dummy pyramid plugin including events.""" config.add_route('event', '/event') config.scan('tests.views.test_events') # config.add_subscriber(raise_attribute_error, BeforeLogIn) @view_config(route_name="event", renderer='json') def event_view(request):
# (quoted strings must be dot separated, or the only element making up the local-part) 'just"not"*****@*****.**', # (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash) 'this is"not\\[email protected]', # (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes) 'this\\ still"not\\[email protected]', "bad-mail", ]) def invalid_email(request): """Parametrized fixture with all the incorrect emails.""" return request.param # pylint:disable=invalid-name default_config = factories.pyramid_config(settings={ "pyramid.includes": ["pyramid_tm", "pyramid_fullauth", "tests.tools.csrf"] }) default_app = factories.pyramid_app("default_config") extended_config = factories.pyramid_config( settings={ "pyramid.includes": [ "pyramid_tm", "pyramid_fullauth", "tests.tools.include_views", "tests.tools.csrf", ] }) extended_app = factories.pyramid_app("extended_config")
def base_config(request): """Basic config parametrized for different configuration location.""" return factories.pyramid_config({ 'yaml.location': request.param, 'pyramid.includes': ['tzf.pyramid_yml'] })(request)
def unregister_subscriber(config, event): """Unregister subscribers from given events.""" # pylint:disable=protected-access for key in config.registry.adapters._subscribers[1].keys(): if key.implementedBy(event): del config.registry.adapters._subscribers[1][key] break evented_config = factories.pyramid_config({ # pylint:disable=invalid-name 'yml.location': 'tests:config', 'env': 'login', 'pyramid.includes': [ 'pyramid_tm', 'pyramid_fullauth', 'tests.tools.include_views', 'tests.views.test_events.include_views' ] }) def include_views(config): """Configure pyramid to include test view and it's path.""" config.add_route('event', '/event') config.scan('tests.views.test_events') @view_config(route_name="event", renderer='json') def event_view(request): """Return exactly received value."""
# Copyright (c) 2013 by pytest_pyramid authors and contributors # <see AUTHORS file> # # This module is part of pytest_pyramid and is released under # the MIT License (MIT): http://opensource.org/licenses/MIT """Plugin's definition and basic fixtures.""" from pytest_pyramid import factories def pytest_addoption(parser): """Pytest option configurator.""" parser.addoption( '--pc', action='store', default=None, metavar='path', dest='pyramid_config', ) # fixtures (made out of factories) pyramid_config = factories.pyramid_config() pyramid_app = factories.pyramid_app('pyramid_config')
# (none of the special characters in this local part is allowed outside quotation marks) text_type('a"b(c)d,e:f;g<h>i[j\k][email protected]'), # (quoted strings must be dot separated, or the only element making up the local-part) text_type('just"not"*****@*****.**'), # (spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash) text_type('this is"not\[email protected]'), # (even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes) text_type('this\ still\"not\\[email protected]'), text_type('bad-mail'), ]) def invalid_email(request): """Parametrized fixture with all the incorrect emails.""" return request.param default_config = factories.pyramid_config( {'pyramid.includes': ['pyramid_tm', 'pyramid_fullauth']}) extended_config = factories.pyramid_config({ 'pyramid.includes': ['pyramid_tm', 'pyramid_fullauth', 'tests.tools.include_views'] }) short_config = factories.pyramid_config({ 'yml.location': 'tests:config/short_memory.yaml', 'pyramid.includes': [ 'pyramid_tm', 'tzf.pyramid_yml', 'pyramid_fullauth', 'tests.tools.include_views' ] })
"""Unregister subscribers from given events.""" # pylint:disable=protected-access for key in config.registry.adapters._subscribers[1].keys(): if key.implementedBy(event): del config.registry.adapters._subscribers[1][key] break evented_config = factories.pyramid_config( settings={ # pylint:disable=invalid-name "env": "login", "fullauth.authtkt.timeout": 2, "fullauth.authtkt.reissue_time": 0.2, "fullauth.register.password.require": True, "fullauth.register.password.length_min": 8, "fullauth.register.password.confirm": True, "pyramid.includes": [ "pyramid_tm", "pyramid_fullauth", "tests.tools.include_views", "tests.views.test_events.include_views", ], } ) def include_views(config): """Configure pyramid to include test view and it's path.""" config.add_route("event", "/event") config.scan("tests.views.test_events")
"""Tests conftest module.""" from pytest_pyramid import factories clean_config = factories.pyramid_config({}) simplerouting_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing', 'pyramid.includes': ['tzf.pyramid_routing'] }) moduled_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing_moduled', 'pyramid.includes': ['tzf.pyramid_routing'] }) two_moduled_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing_two_moduled', 'pyramid.includes': ['tzf.pyramid_routing'] }) prefixed_config = factories.pyramid_config({ 'routing_package': 'tests.routes_definitions.routing_prefixed', 'pyramid.includes': ['tzf.pyramid_routing'] })