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


Python DummyRequest.db方法代码示例

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


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

示例1: test_send_passwords

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def test_send_passwords(self):
        preferences_link = 'http://localhost/preferences'
        backups_link = 'http://localhost/backups'
        user_id = self.db.users.insert({
                'first_name': 'John',
                'last_name': 'Doe',
                'email': '[email protected]',
                }, safe=True)
        user = self.db.users.find_one({'_id': user_id})

        request = DummyRequest()
        request.db = self.db
        mailer = get_mailer(request)

        self.assertFalse(send_passwords(request, user,
                                        preferences_link, backups_link))
        self.assertEqual(len(mailer.outbox), 0)

        # add some passwords
        self.db.passwords.insert({
                'owner': user_id,
                'password': 'secret1',
                })
        self.db.passwords.insert({
                'owner': user_id,
                'password': 'secret2',
                })

        request = DummyRequest()
        request.db = self.db
        request.date_service = FakeDateService(request)
        mailer = get_mailer(request)

        os.environ['YITH_FAKE_DATE'] = '2012-1-10'

        self.assertTrue(send_passwords(request, user,
                                       preferences_link, backups_link))
        self.assertEqual(len(mailer.outbox), 1)
        message = mailer.outbox[0]
        self.assertEqual(message.subject, "Your Yith Library's passwords")
        self.assertEqual(message.recipients, ['[email protected]'])
        self.assertTrue(preferences_link in message.body)
        self.assertTrue(backups_link in message.body)
        self.assertEqual(len(message.attachments), 1)
        attachment = message.attachments[0]
        self.assertEqual(attachment.content_type, 'application/yith')
        self.assertEqual(attachment.filename,
                         'yith-library-backup-2012-01-10.yith')

        del os.environ['YITH_FAKE_DATE']
开发者ID:Yaco-Sistemas,项目名称:yith-library-server,代码行数:52,代码来源:test_email.py

示例2: dummy_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
 def dummy_request(self):
     request = DummyRequest()
     request.context = DummyResource()
     request.userdb = self.userdb
     request.db = self.db
     request.registry.settings = self.settings
     return request
开发者ID:enriquepablo,项目名称:eduid-dashboard,代码行数:9,代码来源:testing.py

示例3: _makeRequest

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def _makeRequest(self, db, fs):
        from pyramid.testing import DummyRequest

        request = DummyRequest()
        request.db = db
        request.fs = fs
        return request
开发者ID:reedobrien,项目名称:lumin,代码行数:9,代码来源:test_util.py

示例4: test_remember_me_with_bad_endpoint

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def test_remember_me_with_bad_endpoint(self):
        """Test the post-login hook with a bad openid endpoint"""
        req = DummyRequest(params={
            'openid.op_endpoint': 'bad_endpoint',
        })
        req.db = self.db
        def flash(msg):
            pass
        req.session.flash = flash
        info = {
            'identity_url': 'http://lmacken.id.fedoraproject.org',
            'groups': [u'releng'],
        }
        req.registry.settings = self.app_settings

        try:
            resp = remember_me(None, req, info)
            assert False, 'remember_me should have thrown an exception'
        except Exception:
            # A ComponentLookupError is thrown because we're doing this outside
            # of the webapp
            pass

        # The user should not exist
        self.assertIsNone(User.get(u'lmacken', self.db))
开发者ID:Debjeeti20,项目名称:bodhi,代码行数:27,代码来源:test_generic.py

示例5: mock_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def mock_request(self):
        request = DummyRequest(authenticated_userid='acct:[email protected]')

        request.registry.notify = mock.Mock(spec=lambda event: None)

        class DBSpec(object):
            def add(self, annotation):
                pass
            def flush():
                pass
        request.db = mock.Mock(spec=DBSpec)

        return request
开发者ID:ficolo,项目名称:h,代码行数:15,代码来源:storage_test.py

示例6: mock_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def mock_request(self):
        request = DummyRequest(
            feature=mock.Mock(
                side_effect=lambda flag: flag == "postgres_write"),
            authenticated_userid='acct:[email protected]'
        )

        request.registry.notify = mock.Mock(spec=lambda event: None)

        class DBSpec(object):
            def add(self, annotation):
                pass
            def flush():
                pass
        request.db = mock.Mock(spec=DBSpec)

        return request
开发者ID:Cinemacloud,项目名称:h,代码行数:19,代码来源:storage_test.py

示例7: dummy_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def dummy_request(self, cookies={}):
        request = DummyRequest()
        request.context = DummyResource()
        request.userdb = self.userdb
        request.userdb_new = self.userdb_new
        request.db = self.db
        request.registry.settings = self.settings

        def propagate_user_changes(user):
            """
            Make sure there is a request.context.propagate_user_changes in testing too.
            """
            logger.debug('FREDRIK: Testing dummy_request.context propagate_user_changes')
            return self.request.amrelay.request_sync(user)

        request.context.propagate_user_changes = propagate_user_changes

        return request
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:20,代码来源:testing.py

示例8: test_cors_headers_app_origins_access_denied

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def test_cors_headers_app_origins_access_denied(self):
        cm = CORSManager('')

        self.db.applications.insert({
                'name': 'test-app',
                'client_id': 'client1',
                'authorized_origins': ['http://localhost'],
                }, safe=True)

        request = DummyRequest(headers={'Origin': 'http://localhost'},
                               params={'client_id': 'client2'})
        request.db = self.db
        response = request.response

        cm.add_cors_header(request, response)

        self.assertEqual(response.headers, {
                'Content-Type': 'text/html; charset=UTF-8',
                'Content-Length': '0',
                })
开发者ID:Yaco-Sistemas,项目名称:yith-library-server,代码行数:22,代码来源:test_cors.py

示例9: test_remember_me

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
    def test_remember_me(self):
        """Test the post-login hook"""
        db = DBSession()
        req = DummyRequest(params={
            'openid.op_endpoint': self.app_settings['openid.provider'],
        })
        req.db = db
        req.session = {'came_from': '/'}
        info = {
            'identity_url': 'http://lmacken.id.fedoraproject.org',
            'groups': [u'releng'],
            'sreg': {'email': u'[email protected]'},
        }
        req.registry.settings = self.app_settings

        # Ensure the user doesn't exist yet
        self.assertIsNone(User.get(u'lmacken', db))
        self.assertIsNone(Group.get(u'releng', db))

        resp = remember_me(None, req, info)

        # The user should now exist, and be a member of the releng group
        user = User.get(u'lmacken', db)
        self.assertEquals(user.name, u'lmacken')
        self.assertEquals(user.email, u'[email protected]')
        self.assertEquals(len(user.groups), 1)
        self.assertEquals(user.groups[0].name, u'releng')

        # Pretend the user has been removed from the releng group
        info['groups'] = []
        req.session = {'came_from': '/'}

        resp = remember_me(None, req, info)

        user = User.get(u'lmacken', db)
        self.assertEquals(len(user.groups), 0)
        self.assertEquals(len(Group.get(u'releng', db).users), 0)
开发者ID:remicollet,项目名称:bodhi,代码行数:39,代码来源:test_generic.py

示例10: mock_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db [as 别名]
 def mock_request(self):
     request = DummyRequest()
     request.feature = mock.Mock(return_value=True)
     request.db = mock.Mock(spec=db.Session)
     return request
开发者ID:fchasen,项目名称:h,代码行数:7,代码来源:storage_test.py


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