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


Python DummyRequest.matchdict方法代码示例

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


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

示例1: test_shortener

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
    def test_shortener(self):
        from pyramid.testing import DummyRequest
        from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest
        from c2cgeoportal.views.shortener import Shortener

        def route_url(name, *elements, **kw):
            return "https://example.com/short/" + kw["ref"]

        request = DummyRequest()
        request.user = None
        request.host = "example.com:443"
        request.server_name = "example.com"
        request.route_url = route_url
        request.registry.settings["shortener"] = {
            "base_url": "https://example.com/s/"
        }
        shortener = Shortener(request)

        request.params = {}
        request.matchdict = {
            "ref": "AAAAAA"
        }
        self.assertRaises(HTTPNotFound, shortener.get)

        request.params = {}
        request.matchdict = {}
        self.assertRaises(HTTPBadRequest, shortener.create)

        request.params = {
            "url": "https://other-site.com/hi"
        }
        self.assertRaises(HTTPBadRequest, shortener.create)
开发者ID:camptocamp,项目名称:c2cgeoportal,代码行数:34,代码来源:test_shortener.py

示例2: test_rest_api_auth

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
    def test_rest_api_auth(self):
        from ptah.rest import Api, Login
        from ptah import authentication
        self._init_ptah()

        config.get_cfg_storage(
            authentication.AUTH_PROVIDER_ID)['test'] = Provider()

        request = DummyRequest(params = {'login': 'admin', 'password': '12345'})

        login = Login(request)
        info = simplejson.loads(login.render())

        request = DummyRequest(environ = {'HTTP_X_AUTH_TOKEN': 'unknown'})
        request.matchdict = {'service': 'cms', 'subpath': ()}

        api = Api(request)
        api.render()
        self.assertEqual(ptah.authService.get_userid(), None)

        token = info['auth-token']

        request = DummyRequest(environ = {'HTTP_X_AUTH_TOKEN': token})
        request.matchdict = {'service': 'cms', 'subpath': ()}

        api = Api(request)
        api.render()
        self.assertEqual(ptah.authService.get_userid(), 'testprincipal:1')
开发者ID:WouterVH,项目名称:ptah,代码行数:30,代码来源:test_rest.py

示例3: test_shortener

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
    def test_shortener(self):
        from pyramid.testing import DummyRequest
        from pyramid.httpexceptions import HTTPFound, HTTPNotFound, \
            HTTPBadRequest
        from c2cgeoportal.views.shortener import Shortener

        def route_url(name, *elements, **kw):
            return "https://example.com/s/" + kw["ref"]

        request = DummyRequest()
        request.user = None
        request.host = "example.com:443"
        request.server_name = "example.com"
        request.route_url = route_url
        shortener = Shortener(request)

        request.params = {
            "url": "https://example.com/hi"
        }
        result = shortener.create()
        index = result["short_url"].rfind("/")
        self.assertEqual(
            result["short_url"][:index],
            "https://example.com/s"
        )

        request.params = {}
        request.matchdict = {
            "ref": result["short_url"][index + 1:]
        }
        result = shortener.get()
        self.assertEqual(type(result), HTTPFound)
        self.assertEqual(result.location, "https://example.com/hi")

        request.params = {}
        request.matchdict = {
            "ref": "AAAAAA"
        }
        self.assertRaises(HTTPNotFound, shortener.get)

        request.params = {
            "url": "https://example.com/short/truite"
        }
        result = shortener.create()
        self.assertEqual(result["short_url"], "https://example.com/s/truite")

        request.params = {}
        request.matchdict = {}
        self.assertRaises(HTTPBadRequest, shortener.create)

        request.params = {
            "url": "https://other-site.com/hi"
        }
        self.assertRaises(HTTPBadRequest, shortener.create)
开发者ID:DavMerca007,项目名称:c2cgeoportal,代码行数:56,代码来源:test_shortener.py

示例4: test_shortener

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
    def test_shortener(self):
        from pyramid.testing import DummyRequest
        from pyramid.httpexceptions import HTTPFound, HTTPNotFound, \
            HTTPBadRequest
        from c2cgeoportal.views.shortener import shortener

        def route_url(name, *elements, **kw):
            return 'https://example.com/s/' + kw['ref']

        request = DummyRequest()
        request.user = None
        request.host = 'example.com:443'
        request.server_name = 'example.com'
        request.route_url = route_url
        shortener = shortener(request)

        request.params = {
            'url': 'https://example.com/hi'
        }
        result = shortener.create()
        index = result['short_url'].rfind('/')
        self.assertEqual(
            result['short_url'][:index],
            'https://example.com/s'
        )

        request.params = {}
        request.matchdict = {
            'ref': result['short_url'][index + 1:]
        }
        result = shortener.get()
        self.assertEqual(type(result), HTTPFound)
        self.assertEqual(result.location, 'https://example.com/hi')

        request.params = {}
        request.matchdict = {
            'ref': 'AAAAAA'
        }
        self.assertRaises(HTTPNotFound, shortener.get)

        request.params = {
            'url': 'https://example.com/short/truite'
        }
        result = shortener.create()
        self.assertEqual(result['short_url'], 'https://example.com/s/truite')

        request.params = {}
        request.matchdict = {}
        self.assertRaises(HTTPBadRequest, shortener.create)

        request.params = {
            'url': 'https://other-site.com/hi'
        }
        self.assertRaises(HTTPBadRequest, shortener.create)
开发者ID:CDTRH,项目名称:c2cgeoportal,代码行数:56,代码来源:test_shortener.py

示例5: test_people_profile_view

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

示例6: test_shortener_create_1

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
    def test_shortener_create_1(self):
        from pyramid.testing import DummyRequest
        from pyramid.httpexceptions import HTTPFound
        from c2cgeoportal.views.shortener import Shortener

        def route_url(name, *elements, **kw):
            return "https://example.com/short/" + kw["ref"]

        request = DummyRequest()
        request.user = None
        request.host = "example.com:443"
        request.server_name = "example.com"
        request.route_url = route_url
        request.registry.settings["shortener"] = {
            "base_url": "https://example.com/s/"
        }
        shortener = Shortener(request)

        request.params = {
            "url": "https://example.com/hi"
        }
        result = shortener.create()
        index = result["short_url"].rfind("/")
        self.assertEqual(
            result["short_url"][:index],
            "https://example.com/s"
        )

        request.params = {}
        request.matchdict = {
            "ref": result["short_url"][index + 1:]
        }
        result = shortener.get()
        self.assertEqual(type(result), HTTPFound)
        self.assertEqual(result.location, "https://example.com/hi")
开发者ID:camptocamp,项目名称:c2cgeoportal,代码行数:37,代码来源:test_shortener.py

示例7: test_get_member_specific_fields

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
 def test_get_member_specific_fields(self):
     request = DummyRequest(path='/thing/1.json', params={'$fields': '["id"]'})
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.get_member()
     member = json.loads(response.body)['results'][0]
     self.assert_(member.keys() == ['id'])
开发者ID:antonygc,项目名称:pyramid_restler,代码行数:9,代码来源:tests.py

示例8: _undo_delete_column

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
    def _undo_delete_column(self, base, old_name, path, results):
        for doc in results:
            if doc.get(old_name, None):
                id_doc=doc['_metadata']['id_doc']

                url='/%s/doc/%d/%s' % (
                    base.metadata.name, 
                    id_doc, "/".join(path)
                )
                params={
                    'value': doc[old_name], 
                    'alter_files': False
                }
                request=DummyRequest(path=url, params=params)
                request.method='PUT'
                request.matchdict={
                    'base': base.metadata.name,
                    'id': str(id_doc),
                    'path': "/".join(path)
                }
                doc_view=DocumentCustomView(
                    DocumentContextFactory(request), 
                    request
                )
                response=doc_view.put_path()
开发者ID:lightbase,项目名称:LBGenerator,代码行数:27,代码来源:base.py

示例9: test_detail_view

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
def test_detail_view(dbtransaction, new_entry):
    """Test that list_view returns a Query of Entries."""
    test_request = DummyRequest()
    test_request.matchdict = {'detail_id': new_entry.id}

    response_dict = detail_view(test_request)
    assert response_dict['entry'] == new_entry
开发者ID:cacizi41,项目名称:learning-journal,代码行数:9,代码来源:test_views.py

示例10: test_get_member

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
 def test_get_member(self):
     request = DummyRequest(path='/thing/1.json')
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.get_member()
     self.assertTrue(isinstance(response, Response))
     self.assertEqual(response.status_int, 200)
开发者ID:antonygc,项目名称:pyramid_restler,代码行数:9,代码来源:tests.py

示例11: test_delete_member

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
 def test_delete_member(self):
     request = DummyRequest(method='DELETE', path='/thing/1',)
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.delete_member()
     self.assertTrue(isinstance(response, Response))
     self.assertEqual(response.status_int, 204)
     self.assertRaises(HTTPNotFound, view.get_member)
开发者ID:antonygc,项目名称:pyramid_restler,代码行数:10,代码来源:tests.py

示例12: test_unwrapped_response

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
 def test_unwrapped_response(self):
     request = DummyRequest(path='/thing/1.json', params={'$wrap': 'false'})
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     self.assertFalse(view.wrap)
     response = view.get_member()
     member = json.loads(response.body)[0]
     self.assert_('id' in member and 'val' in member)
开发者ID:antonygc,项目名称:pyramid_restler,代码行数:10,代码来源:tests.py

示例13: _make_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
 def _make_request(self, matchdict=None, post=None, get=None, cookies=None):
     if post is not None:
         from webob.multidict import MultiDict
         post = MultiDict(post)
     req = DummyRequest(post=post, params=get, cookies=cookies)
     if matchdict:
         req.matchdict = matchdict
     return req
开发者ID:dbaty,项目名称:Lasco,代码行数:10,代码来源:test_views.py

示例14: test_view_detail

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
def test_view_detail(session, create_entry):
    from journalapp.views import detail
    test_request = DummyRequest(path='/entry/{pkey:\d+}')
    test_request.matchdict = {'title': create_entry.title}

    response = detail(test_request)
    post = response['post']
    assert post['posts'].title == create_entry.title
开发者ID:ksgifford,项目名称:learning-journal,代码行数:10,代码来源:test_views.py

示例15: test_get_breadcrumbs_2

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matchdict [as 别名]
 def test_get_breadcrumbs_2(self):
     request = DummyRequest()
     request.matched_route = MatchedRoute()
     request.matched_route.name = 'p1_project'
     request.matchdict = {'project_name': 'ENCODE'}
     p = page.Page(request)
     breadcrumbs = [{'url': 'http://example.com/',
                     'title': 'Projects'}]
     self.failUnless(p.get_breadcrumbs(request) == breadcrumbs)
开发者ID:rna-seq,项目名称:raisin.restyler,代码行数:11,代码来源:test_page.py


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