当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.db_session方法代码示例

本文整理汇总了Python中pyramid.testing.DummyRequest.db_session方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.db_session方法的具体用法?Python DummyRequest.db_session怎么用?Python DummyRequest.db_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.testing.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.db_session方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: req

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_session [as 别名]
def req(db_session):
    """
    (Integration Testing) Creates a dummy request

    The request is setup with configuration CSRF values and the expected
    ``db_session`` property, the goal being to be be as close to a real
    database session as possible.

    Note that we must called it "req" as "request" is reserved by pytest.

    :param db_session: The testing database session

    :returns: a configured request object
    """
    import uuid
    import mock
    from pyramid.testing import DummyRequest

    dummy_request = DummyRequest()

    # Configurable csrf token
    csrf_token = str(uuid.uuid4())
    get_csrf_token = mock.Mock(return_value=csrf_token)
    dummy_request.session.get_csrf_token = get_csrf_token
    dummy_request.headers['X-CSRF-Token'] = csrf_token

    # Attach database session for expected behavior
    dummy_request.db_session = db_session
    db_session.info['request'] = dummy_request

    return dummy_request
开发者ID:jkrooskos,项目名称:occams_lims,代码行数:33,代码来源:conftest.py

示例2: test_people_profile_view

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_session [as 别名]
    def test_people_profile_view(self):
        from notaliens.people.views import people_profile_view

        request = DummyRequest()
        request.method = 'GET'
        request.db_session = mock.Mock()
        request.matchdict = mock.MagicMock()

        request.search_settings = {
            'enabled': True
        }

        user = mock.Mock()
        region = mock.Mock()
        users = mock.MagicMock()

        with mock.patch('notaliens.people.views.get_user_by_username') as get_user_by_username:  # nopep8
            with mock.patch('notaliens.people.views.get_region_by_postal') as get_region_by_postal:  # nopep8
                with mock.patch('notaliens.people.views.get_users') as get_users:  # nopep8
                    get_user_by_username.return_value = user
                    get_region_by_postal.return_value = region
                    get_users.return_value = users

                    response = people_profile_view(request)

                    assert response['data']['user'] == user
开发者ID:einSelbst,项目名称:notaliens.com,代码行数:28,代码来源:test_people_views.py

示例3: setUp

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_session [as 别名]
 def setUp(self):
     # For each test, create a new database and populate it with a few
     # things. Then create a context instance to be used by the test.
     engine = create_engine('sqlite://')
     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)
开发者ID:antonygc,项目名称:pyramid_restler,代码行数:24,代码来源:tests.py

示例4: test_get_group

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_session [as 别名]
    def test_get_group(self):
        from pyramid.testing import DummyRequest
        from ez2pay.auth import get_group

        user_model = self.make_user_model()
        group_model = self.make_group_model()
        permission_model = self.make_permission_model()
        
        with transaction.manager:
            user_id1 = user_model.create(
                user_name='tester1',
                email='[email protected]',
                display_name='tester1',
                password='thepass',
            )
            user_id2 = user_model.create(
                user_name='tester2',
                email='[email protected]',
                display_name='tester2',
                password='thepass',
            )
            user_id3 = user_model.create(
                user_name='tester3',
                email='[email protected]',
                display_name='tester3',
                password='thepass',
            )
            group_id1 = group_model.create(
                group_name='super_users',
                display_name='Super user',
            )
            group_id2 = group_model.create(
                group_name='guest',
                display_name='Guest group',
            )
            permission_id1 = permission_model.create(
                permission_name='admin',
                description='Admin',
            )
            permission_id2 = permission_model.create(
                permission_name='manager',
                description='Manager',
            )
            permission_id3 = permission_model.create(
                permission_name='guest',
                description='Guest',
            )

            # + group1 super_users
            #     + permission1 admin 
            #     + permission2 manager 
            group_model.update_permissions(
                group_id1, 
                [permission_id1, permission_id2]
            )
            # + group2 guest
            #     + permission3 guest
            group_model.update_permissions(group_id2, [permission_id3])

            # user1
            #     + group1 super_users
            #         + permission1 admin 
            #         + permission2 manager 
            user_model.update_groups(user_id1, [group_id1])
            # user2
            #     + group2 guest
            #         + permission3 guest 
            user_model.update_groups(user_id2, [group_id2])
            # user3
            #     (nothing)

        mock_request = DummyRequest()
        mock_request.db_session = self.session

        def assert_group(user_id, expected):
            group = get_group(user_id, mock_request)
            self.assertEqual(group, set(expected))

        assert_group(
            user_id1, 
            [
                'user', 
                'user:tester1',
                'group:super_users',
                'permission:admin',
                'permission:manager',
            ]
        )
        assert_group(
            user_id2, 
            [
                'user', 
                'user:tester2',
                'group:guest',
                'permission:guest',
            ]
        )
        assert_group(
            user_id3, 
            [
#.........这里部分代码省略.........
开发者ID:victorlin,项目名称:ez2pay,代码行数:103,代码来源:test_auth.py


注:本文中的pyramid.testing.DummyRequest.db_session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。