예제 #1
0
# 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')
예제 #2
0
"""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')
예제 #3
0
"""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
예제 #4
0
    'yml.location': 'tests:config/no_password_confirm.yaml',
    'env': 'login',
    'pyramid.includes': [
        'pyramid_tm',
        'tzf.pyramid_yml',
        'pyramid_fullauth',
        'tests.tools.include_views'
    ]
})


nopassregister_config = factories.pyramid_config({
    'yml.location': 'tests:config/no_password_register.yaml',
    'env': 'login',
    'pyramid.includes': [
        'pyramid_tm',
        'tzf.pyramid_yml',
        'pyramid_fullauth',
        'tests.tools.include_views'
    ]
})


default_app = factories.pyramid_app('default_config')
extended_app = factories.pyramid_app('extended_config')
short_app = factories.pyramid_app('short_config')
social_app = factories.pyramid_app('social_config')
authable_app = factories.pyramid_app('authable_config')
nopassconfirm_app = factories.pyramid_app('nopassconfirm_config')
nopassregister_app = factories.pyramid_app('nopassregister_config')
예제 #5
0
    '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")

short_config = factories.pyramid_config(
    settings={
예제 #6
0

def raise_attribute_error(event):
    """Raise attribute error with message being the event class name."""
    if event.user:
        raise AttributeError(event.__class__.__name__)


@pytest.fixture
def alreadyloggedin_config(evented_config):
    """Add AlreadyLoggedIn event subscriber that redirects to event page."""
    evented_config.add_subscriber(redirect_to_secret, AlreadyLoggedIn)
    return evented_config


alreadyloggedin_app = factories.pyramid_app('alreadyloggedin_config')


def test_default_login_redirect_from_event(active_user, alreadyloggedin_app):
    """After successful login, access to login page should result in redirect."""
    authenticate(alreadyloggedin_app)
    res = alreadyloggedin_app.get('/login', status=302)
    assert res.location == EVENT_URL.format(AlreadyLoggedIn)


@pytest.fixture
def beforelogin_config(evented_config):
    """Add BeforeLogIn event that raises AttributeError with event class name."""
    evented_config.add_subscriber(raise_attribute_error, BeforeLogIn)
    return evented_config
예제 #7
0
def raise_attribute_error(event):
    """Raise attribute error with message being the event class name."""
    if event.user:
        raise AttributeError(event.__class__.__name__)


@pytest.fixture
def alreadyloggedin_config(evented_config):  # pylint:disable=redefined-outer-name
    """Add AlreadyLoggedIn event subscriber that redirects to event page."""
    evented_config.add_subscriber(redirect_to_secret, AlreadyLoggedIn)
    evented_config.commit()
    yield evented_config
    unregister_subscriber(evented_config, AlreadyLoggedIn)


alreadyloggedin_app = factories.pyramid_app('alreadyloggedin_config')  # pylint:disable=invalid-name


@pytest.mark.usefixtures('active_user')
def test_default_login_redirect_from_event(alreadyloggedin_app):  # pylint:disable=redefined-outer-name
    """After successful login, access to login page should result in redirect."""
    authenticate(alreadyloggedin_app)
    res = alreadyloggedin_app.get('/login', status=302)
    assert res.location == EVENT_URL.format(AlreadyLoggedIn)


@pytest.fixture
def beforelogin_config(evented_config):  # pylint:disable=redefined-outer-name
    """Add BeforeLogIn event that raises AttributeError with event class name."""
    evented_config.add_subscriber(raise_attribute_error, BeforeLogIn)
    evented_config.commit()
예제 #8
0
        ))


def raise_attribute_error(event):
    """Raise attribute error with message being the event class name."""
    if event.user:
        raise AttributeError(event.__class__.__name__)


@pytest.fixture
def alreadyloggedin_config(evented_config):
    """Add AlreadyLoggedIn event subscriber that redirects to event page."""
    evented_config.add_subscriber(redirect_to_secret, AlreadyLoggedIn)
    return evented_config

alreadyloggedin_app = factories.pyramid_app('alreadyloggedin_config')


def test_default_login_redirect_from_event(active_user, alreadyloggedin_app):
    """After successful login, access to login page should result in redirect."""
    authenticate(alreadyloggedin_app)
    res = alreadyloggedin_app.get('/login', status=302)
    assert res.location == EVENT_URL.format(AlreadyLoggedIn)


@pytest.fixture
def beforelogin_config(evented_config):
    """Add BeforeLogIn event that raises AttributeError with event class name."""
    evented_config.add_subscriber(raise_attribute_error, BeforeLogIn)
    return evented_config
예제 #9
0
# 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')
예제 #10
0
nopassconfirm_config = factories.pyramid_config({
    'yml.location':
    'tests:config/no_password_confirm.yaml',
    'env':
    'login',
    'pyramid.includes': [
        'pyramid_tm', 'tzf.pyramid_yml', 'pyramid_fullauth',
        'tests.tools.include_views'
    ]
})

nopassregister_config = factories.pyramid_config({
    'yml.location':
    'tests:config/no_password_register.yaml',
    'env':
    'login',
    'pyramid.includes': [
        'pyramid_tm', 'tzf.pyramid_yml', 'pyramid_fullauth',
        'tests.tools.include_views'
    ]
})

default_app = factories.pyramid_app('default_config')
extended_app = factories.pyramid_app('extended_config')
short_app = factories.pyramid_app('short_config')
social_app = factories.pyramid_app('social_config')
authable_app = factories.pyramid_app('authable_config')
nopassconfirm_app = factories.pyramid_app('nopassconfirm_config')
nopassregister_app = factories.pyramid_app('nopassregister_config')
예제 #11
0
def raise_attribute_error(event):
    """Raise attribute error with message being the event class name."""
    if event.user:
        raise AttributeError(event.__class__.__name__)


@pytest.fixture
def alreadyloggedin_config(evented_config):  # pylint:disable=redefined-outer-name
    """Add AlreadyLoggedIn event subscriber that redirects to event page."""
    evented_config.add_subscriber(redirect_to_secret, AlreadyLoggedIn)
    evented_config.commit()
    yield evented_config
    unregister_subscriber(evented_config, AlreadyLoggedIn)


alreadyloggedin_app = factories.pyramid_app("alreadyloggedin_config")  # pylint:disable=invalid-name


@pytest.mark.usefixtures("active_user")
def test_default_login_redirect_from_event(alreadyloggedin_app, ):  # pylint:disable=redefined-outer-name
    """After successful login, access to login page should result in redirect."""
    authenticate(alreadyloggedin_app)
    res = alreadyloggedin_app.get("/login", status=302)
    assert res.location == EVENT_URL.format(AlreadyLoggedIn)


@pytest.fixture
def beforelogin_config(evented_config):  # pylint:disable=redefined-outer-name
    """Add BeforeLogIn event that raises AttributeError with event class name."""
    evented_config.add_subscriber(raise_attribute_error, BeforeLogIn)
    evented_config.commit()