How to use pyramid - 10 common examples

To help you get started, we’ve selected a few pyramid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eucalyptus / eucaconsole / tests / stacks / test_aws_convert.py View on Github external
def test_url_for_resource(self):
        from eucaconsole.views.stacks import StackStateView
        _register_routes(self.config)
        request = testing.DummyRequest()
        
        url = StackStateView.get_url_for_resource(request, 'AWS::ElasticLoadBalancing::LoadBalancer', 'lb-1234')
        self.assertEqual(url, '/elbs/lb-1234')

        url = StackStateView.get_url_for_resource(request, 'AWS::EC2::SecurityGroup', 'sg-1234')
        self.assertEqual(url, '/securitygroups/sg-1234')

        url = StackStateView.get_url_for_resource(request, 'AWS::EC2::EIP', '1.2.3.4')
        self.assertEqual(url, '/ipaddresses/1.2.3.4')

        url = StackStateView.get_url_for_resource(request, 'AWS::EC2::Instance', 'i-1234')
        self.assertEqual(url, '/instances/i-1234')

        url = StackStateView.get_url_for_resource(request, 'AWS::EC2::Volume', 'vol-1234')
        self.assertEqual(url, '/volumes/vol-1234')
github wylee / pyramid_restler / pyramid_restler / tests.py View on Github external
session = Session(bind=engine)
        Base = declarative_base()
        class Entity(Base):
            __tablename__ = 'entity'
            id = Column(Integer, primary_key=True)
            value = Column(String)
        Base.metadata.create_all(bind=engine)
        session.add_all([
            Entity(id=1, value='one'),
            Entity(id=2, value='two'),
            Entity(id=3, value='three'),
        ])
        session.commit()
        class ContextFactory(SQLAlchemyORMContext):
            entity = Entity
        request = DummyRequest()
        request.db_session = session
        self.context = ContextFactory(request)
github fizyk / pyramid_fullauth / tests / views / test_login_social.py View on Github external
def test_logged_social_connect_used_account(social_config, facebook_user, db_session):
    """Try to connect facebook account to logged in user used by other user."""
    # this user will be logged and trying to connect facebook's user account.
    fresh_user = User(
        email=text_type('new@user.pl'),
        password=text_type('somepassword'),
        address_ip=text_type('127.0.0.1')
    )
    db_session.add(fresh_user)
    transaction.commit()
    user = db_session.merge(facebook_user)
    fresh_user = db_session.merge(fresh_user)

    # mock request
    profile = {
        'accounts':
        [{'domain': text_type('facebook.com'), 'userid': user.provider_id('facebook')}],
        'displayName':
        text_type('teddy'),
        'preferredUsername':
        text_type('teddy'),
        'emails':
        [{'value': text_type('aasd@basd.pl')}],
github fizyk / pyramid_fullauth / tests / cases / test_unit / test_validators.py View on Github external
import pytest
from pyramid.compat import text_type
from pyramid_fullauth.models import User
from pyramid_fullauth.exceptions import EmptyError, EmailValidationError


class TestUserValidates(object):

    user_data = {'password': text_type('password1'),
                 'email': text_type('test@example.com'),
                 'address_ip': text_type('32.32.32.32')}

    def create_user(self, session, **user_data):
        '''method to create basic user'''
        user = User()

        for key in self.user_data:
            if not key in user_data:
                user_data[key] = self.user_data[key]

        for key in user_data:
            setattr(user, key, user_data[key])

        session.add(user)
        session.commit()

    @pytest.mark.parametrize('email', [
github fizyk / pyramid_fullauth / tests / cases / test_models.py View on Github external
def test_delete_admin(self):
        '''Admin user soft delete'''

        user = self.session.query(User).filter(User.email == text_type('test@example.com')).one()
        self.create_user(email=text_type('test2@example.com'), is_admin=True)

        user.is_admin = True
        self.session.commit()

        user.delete()

        self.assertNotEqual(user.deleted_at, None)
github Pylons / substanced / substanced / dump / tests.py View on Github external
def test_load(self):
        context = testing.DummyResource()
        resource = testing.DummyResource()
        context.exists = lambda *arg: True
        def _p_activate():
            pass # this will not be covered if not run
        context.resource = resource
        resource._p_activate = _p_activate
        def load_yaml(fn):
            self.assertEqual(fn, 'name.yaml')
            return {'a':1}
        context.load_yaml = load_yaml
        inst = self._makeOne('name', None)
        inst.load(context)
        self.assertTrue(resource._p_changed)
        self.assertEqual(resource.a, 1)
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / schema / test_init.py View on Github external
def test_deserialize_value_url_valid_path(self, context, request_, node, rest_url):
        inst = self.make_one()
        context['child'] = testing.DummyResource()
        node = node.bind(request=request_,
                         context=context)
        result = inst.deserialize(node, rest_url + '/child')
        assert result == context['child']
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / schema / test_init.py View on Github external
def setUp(self):
        self.context = testing.DummyResource()
        self.target = testing.DummyResource()
        self.child = testing.DummyResource()
        request = testing.DummyRequest()
        request.root = self.context
        self.request = request
github Pylons / substanced / substanced / util / tests.py View on Github external
def test_one_found(self):
        from ..interfaces import IFolder
        from ..interfaces import IService
        site = testing.DummyResource(__provides__=IFolder)
        catalog = testing.DummyResource(__provides__=IService)
        site['catalog'] = catalog
        self.assertEqual(self._callFUT(site, 'catalog'), [catalog])
github Pylons / substanced / substanced / jsonapi / tests.py View on Github external
def test_call_function(self):
        decorator = self._makeOne()
        venusian = DummyVenusian()
        decorator.venusian = venusian
        def foo(): pass
        wrapped = decorator(foo)
        self.assertTrue(wrapped is foo)
        context = testing.DummyResource()
        context.config = DummyConfigurator()
        venusian.callback(context, None, 'abc')
        self.assertEqual(context.config.view, 'abc')