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


Python DummyRequest.session方法代码示例

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


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

示例1: test_enabled

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
    def test_enabled(self):
        request = DummyRequest()
        request.session = {}
        request.registry = DummyRegistry(google_analytics_code='1234')
        ga = GoogleAnalytics(request)
        self.assertTrue(ga.enabled)

        request = DummyRequest()
        request.session = {}
        request.registry = DummyRegistry(google_analytics_code=None)
        ga = GoogleAnalytics(request)
        self.assertFalse(ga.enabled)
开发者ID:pombredanne,项目名称:yith-library-server,代码行数:14,代码来源:test_analytics.py

示例2: test_clean_session

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
    def test_clean_session(self):
        request = DummyRequest()
        request.session = {}
        request.user = None
        ga = GoogleAnalytics(request)
        ga.clean_session()
        self.assertEqual(request.session, {})

        request = DummyRequest()
        request.session = {USER_ATTR: True}
        request.user = None
        ga = GoogleAnalytics(request)
        ga.clean_session()
        self.assertEqual(request.session, {})
开发者ID:pombredanne,项目名称:yith-library-server,代码行数:16,代码来源:test_analytics.py

示例3: test_show_in_session

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
    def test_show_in_session(self):
        request = DummyRequest()
        request.session = {}
        ga = GoogleAnalytics(request)
        self.assertFalse(ga.show_in_session())

        request = DummyRequest()
        request.session = {USER_ATTR: False}
        ga = GoogleAnalytics(request)
        self.assertFalse(ga.show_in_session())

        request = DummyRequest()
        request.session = {USER_ATTR: True}
        ga = GoogleAnalytics(request)
        self.assertTrue(ga.show_in_session())
开发者ID:pombredanne,项目名称:yith-library-server,代码行数:17,代码来源:test_analytics.py

示例4: make_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def make_request(self, session_language=None):
     from pyramid.testing import DummyRequest
     request = DummyRequest()
     request.session = {}
     if session_language is not None:
         request.session['lang'] = session_language
     return request
开发者ID:cdunklau,项目名称:paildocket,代码行数:9,代码来源:test_i18n.py

示例5: test_oauth2_step2

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
    def test_oauth2_step2(self):
        token_uri = 'http://example.com/oauth2/token'
        client_id = '1234'
        client_secret = 'secret'
        redirect_url = 'http://localhost/oauth2/callback'
        scope = 'scope1 scope2'
        request = DummyRequest()
        response = oauth2_step2(request, token_uri, client_id, client_secret,
                                redirect_url, scope)
        self.assertEqual(response.status, '400 Bad Request')
        self.assertEqual(response.message, 'Missing required code')

        request.params = {'code': 'abcdef'}
        response = oauth2_step2(request, token_uri, client_id, client_secret,
                                redirect_url, scope)
        self.assertEqual(response.status, '400 Bad Request')
        self.assertEqual(response.message, 'Missing required state')

        request.params['state'] = 'random-string'
        response = oauth2_step2(request, token_uri, client_id, client_secret,
                                redirect_url, scope)
        self.assertEqual(response.status, '401 Unauthorized')
        self.assertEqual(response.message, 'Missing internal state. You may be a victim of CSRF')

        request.session = {'state': 'other-string'}
        response = oauth2_step2(request, token_uri, client_id, client_secret,
                                redirect_url, scope)
        self.assertEqual(response.status, '401 Unauthorized')
        self.assertEqual(response.message, 'State parameter does not match internal state. You may be a victim of CSRF')

        with patch('requests.post') as fake:
            fake.return_value.status_code = 401
            fake.return_value.text = 'Unauthorized request'
            request.session['state'] = 'random-string'
            response = oauth2_step2(request, token_uri,
                                    client_id, client_secret,
                                    redirect_url, scope)
            self.assertEqual(response.status, '401 Unauthorized')
            self.assertEqual(response.message, 'Unauthorized request')

        with patch('requests.post') as fake:
            fake.return_value.status_code = 200
            fake.return_value.json = lambda: {
                'access_token': 'qwerty'
                }
            request.session['state'] = 'random-string'
            response = oauth2_step2(request, token_uri,
                                    client_id, client_secret,
                                    redirect_url, scope)
            self.assertEqual(response, 'qwerty')

        with patch('requests.post') as fake:
            fake.return_value.status_code = 200
            fake.return_value.json = lambda: None
            fake.return_value.text = 'access_token=qwerty'
            request.session['state'] = 'random-string'
            response = oauth2_step2(request, token_uri,
                                    client_id, client_secret,
                                    redirect_url, scope)
            self.assertEqual(response, 'qwerty')
开发者ID:Yaco-Sistemas,项目名称:yith-library-server,代码行数:62,代码来源:test_client.py

示例6: test_get_user_attr

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def test_get_user_attr(self):
     request = DummyRequest()
     request.session = {}
     request.user = None
     ga = GoogleAnalytics(request)
     self.assertEqual(ga.get_user_attr(True), {USER_ATTR: True})
     self.assertEqual(ga.get_user_attr(False), {USER_ATTR: False})
开发者ID:pombredanne,项目名称:yith-library-server,代码行数:9,代码来源:test_analytics.py

示例7: test_oauth2_step1

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
    def test_oauth2_step1(self):
        with patch('uuid.uuid4') as fake:
            fake.return_value = 'random-string'

            request = DummyRequest()
            request.params = {'next_url': 'http://localhost/'}
            request.session = {}
            response = oauth2_step1(
                request=request,
                auth_uri='http://example.com/oauth2/auth',
                client_id='1234',
                redirect_url='http://localhost/oauth2/callback',
                scope='scope1 scope2'
                )
            self.assertEqual(response.status, '302 Found')
            url = urlparse.urlparse(response.location)
            self.assertEqual(url.netloc, 'example.com')
            self.assertEqual(url.path, '/oauth2/auth')
            query = urlparse.parse_qs(url.query)
            self.assertEqual(query, {
                    'scope': ['scope1 scope2'],
                    'state': ['random-string'],
                    'redirect_uri': ['http://localhost/oauth2/callback'],
                    'response_type': ['code'],
                    'client_id': ['1234'],
                    })
            self.assertEqual(request.session['next_url'], 'http://localhost/')
开发者ID:Yaco-Sistemas,项目名称:yith-library-server,代码行数:29,代码来源:test_client.py

示例8: test_remember_me

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [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

示例9: test_show

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
    def test_show(self):
        request = DummyRequest()
        request.session = {}
        request.user = None
        ga = GoogleAnalytics(request)
        self.assertFalse(ga.show)

        request = DummyRequest()
        request.session = {USER_ATTR: True}
        request.user = None
        ga = GoogleAnalytics(request)
        self.assertTrue(ga.show)

        request = DummyRequest()
        request.session = {}
        request.user = {USER_ATTR: True}
        ga = GoogleAnalytics(request)
        self.assertTrue(ga.show)

        request = DummyRequest()
        request.session = {USER_ATTR: True}
        request.user = {USER_ATTR: False}
        ga = GoogleAnalytics(request)
        self.assertFalse(ga.show)
开发者ID:pombredanne,项目名称:yith-library-server,代码行数:26,代码来源:test_analytics.py

示例10: set_logged

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def set_logged(self, email='[email protected]', extra_session_data={}):
     request = self.set_user_cookie(email)
     user_obj = self.userdb.get_user_by_mail(email, raise_on_missing=True)
     if not user_obj:
         logging.error("User {!s} not found in database {!r}. Users:".format(email, self.userdb))
         for this in self.userdb._get_all_userdocs():
             this_user = OldUser(this)
             logging.debug("  User: {!s}".format(this_user))
     # user only exists in eduid-userdb, so need to clear modified-ts to be able
     # to save it to eduid-dashboard.profiles
     user_obj.set_modified_ts(None)
     dummy = DummyRequest()
     dummy.session = {
         'eduPersonAssurance': loa(3),
         'eduPersonIdentityProofing': loa(3),
     }
     store_session_user(dummy, user_obj)
     # XXX ought to set self.user = user_obj
     self.logged_in_user = self.userdb_new.get_user_by_id(user_obj.get_id())
     dummy.session.update(extra_session_data)
     request = self.add_to_session(dummy.session)
     return request
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:24,代码来源:testing.py

示例11: test_is_in_session_empty_session

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def test_is_in_session_empty_session(self):
     request = DummyRequest()
     request.session = {}
     ga = GoogleAnalytics(request)
     self.assertFalse(ga.is_in_session())
开发者ID:ablanco,项目名称:yith-library-server,代码行数:7,代码来源:test_analytics.py

示例12: test_show_empty_session_no_user

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def test_show_empty_session_no_user(self):
     request = DummyRequest()
     request.session = {}
     request.user = None
     ga = GoogleAnalytics(request)
     self.assertFalse(ga.show)
开发者ID:ablanco,项目名称:yith-library-server,代码行数:8,代码来源:test_analytics.py

示例13: test_show_true_session_no_user

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def test_show_true_session_no_user(self):
     request = DummyRequest()
     request.session = {USER_ATTR: True}
     request.user = None
     ga = GoogleAnalytics(request)
     self.assertTrue(ga.show)
开发者ID:ablanco,项目名称:yith-library-server,代码行数:8,代码来源:test_analytics.py

示例14: test_show_empty_session_true_user

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def test_show_empty_session_true_user(self):
     request = DummyRequest()
     request.session = {}
     request.user = User(allow_google_analytics=True)
     ga = GoogleAnalytics(request)
     self.assertTrue(ga.show)
开发者ID:ablanco,项目名称:yith-library-server,代码行数:8,代码来源:test_analytics.py

示例15: test_is_in_session_false_session

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import session [as 别名]
 def test_is_in_session_false_session(self):
     request = DummyRequest()
     request.session = {USER_ATTR: False}
     ga = GoogleAnalytics(request)
     self.assertTrue(ga.is_in_session())
开发者ID:ablanco,项目名称:yith-library-server,代码行数:7,代码来源:test_analytics.py


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