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


Python testing.DummyRequest类代码示例

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


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

示例1: test_PUT_using_header

 def test_PUT_using_header(self):
     app = self._make_app()
     request = DummyRequest(method='POST')
     request.headers['X-HTTP-Method-Override'] = 'PUT'
     self._assert_before(request)
     app.registry.notify(NewRequest(request))
     self._assert_after(request, 'PUT')
开发者ID:antonygc,项目名称:pyramid_restler,代码行数:7,代码来源:tests.py

示例2: test_forbidden

    def test_forbidden(self):
        from ptahcrowd.forbidden import Forbidden

        class Context(object):
            """ """

        request = DummyRequest()
        request.url = 'http://example.com'
        request.application_url = 'http://example.com'
        request.root = Context()

        excview = Forbidden(HTTPForbidden(), request)
        excview.update()

        res = request.response

        self.assertIs(excview.__parent__, request.root)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(
            text_(res.headers['location']),
            'http://example.com/login.html?came_from=http%3A%2F%2Fexample.com')

        excview = Forbidden(HTTPForbidden(), request)
        res = excview()
        self.assertEqual(res.status, '302 Found')
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:25,代码来源:test_forbidden.py

示例3: test__get_child_layers_info_without_scalehint

    def test__get_child_layers_info_without_scalehint(self):
        from pyramid.testing import DummyRequest
        from c2cgeoportal.views.entry import Entry

        request = DummyRequest()
        request.user = None
        entry = Entry(request)

        class Layer(object):
            pass

        child_layer_1 = Layer()
        child_layer_1.name = 'layer_1'
        child_layer_1.scaleHint = None
        child_layer_1.layers = []

        child_layer_2 = Layer()
        child_layer_2.name = 'layer_2'
        child_layer_2.scaleHint = None
        child_layer_2.layers = []

        layer = Layer()
        layer.layers = [child_layer_1, child_layer_2]

        child_layers_info = entry._get_child_layers_info(layer)

        expected = [{
            'name': 'layer_1'
        }, {
            'name': 'layer_2',
        }]
        self.assertEqual(child_layers_info, expected)
开发者ID:kailIII,项目名称:c2cgeoportal,代码行数:32,代码来源:test_entry.py

示例4: test_profile_csv

    def test_profile_csv(self):
        from pyramid.testing import DummyRequest
        from c2cgeoportal.views.profile import Profile

        request = DummyRequest()
        request.registry.settings = {
            "raster": {
                "dem": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 1},
                "dem2": {"file": "c2cgeoportal/tests/data/dem.shp", "round": 1}
            }
        }
        profile = Profile(request)

        request.params["nbPoints"] = "3"
        request.params["geom"] = '{"type":"LineString",' \
            '"coordinates":[[548009.5,215990],[547990,216009.5]]}'
        response = profile.csv()
        self.assertEqual(response.body, """distance,dem2,dem,x,y
0.0,1166,1166,548009,215990
9.2,1181,1181,548003,215996
18.4,1181,1181,547996,216003""")

        request.params["layers"] = "dem"
        response = profile.csv()
        self.assertEqual(response.body, """distance,dem,x,y
0.0,1166,548009,215990
9.2,1181,548003,215996
18.4,1181,547996,216003""")
开发者ID:eleu,项目名称:c2cgeoportal,代码行数:28,代码来源:test_raster.py

示例5: dummy_request

 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,代码行数:7,代码来源:testing.py

示例6: _makeRequest

    def _makeRequest(self, db, fs):
        from pyramid.testing import DummyRequest

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

示例7: test_websocket_good_origin

def test_websocket_good_origin(config):
    config.registry.settings.update({'origins': 'http://good'})
    config.include('h.streamer')
    req = DummyRequest(headers={'Origin': 'http://good'})
    req.get_response = MagicMock()
    res = websocket(req)
    assert res.code != 403
开发者ID:coolcool21,项目名称:h,代码行数:7,代码来源:streamer_test.py

示例8: test_remember_me_with_bad_endpoint

    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,代码行数:25,代码来源:test_generic.py

示例9: test_get_current_page

 def test_get_current_page(self):
     request = DummyRequest()
     page = get_current_page(request)
     self.assertEqual(page, 1)
     request.GET['page'] = 5
     page = get_current_page(request)
     self.assertEqual(page, 5)
开发者ID:cjltsod,项目名称:pyramid_sacrud,代码行数:7,代码来源:test_common_paginator.py

示例10: test_call

    def test_call(self):
        config = testing.setUp()
        config.add_route('some_route', '/')

        pagination_request_writer = PaginationRequestWriterMock()
        param_property_naming = PropertyNamingMock(
            'page-number',
            'page-size',
            'sort-property',
            'sort-direction')
        url_creator_factory = UrlCreatorFactoryMock('http://example.com')
        request = DummyRequest()
        request.registry.pagination = {
            'some_route': {
                'pagination_request_writer': pagination_request_writer,
                'param_property_naming': param_property_naming,
                'url_creator_factory': url_creator_factory,
            }
        }
        request.pagination = Pagination(
            Paging(
                100,
                PagingRequest(3, 12)),
            Sorting('some_property', 'desc'))
        request.matched_route = RouteMock('some_route')
        event = BeforeRenderEventMock()
        event['request'] = request
        subscriber = PaginationBeforeRenderSubscriber()
        subscriber(event)
        self.assertEqual(pagination_request_writer.call_count, 1)

        pagination = event.rendering_val['pagination']
        self.assertEqual('http://example.com', str(pagination.url))
开发者ID:C3S,项目名称:c3sMembership,代码行数:33,代码来源:test_init.py

示例11: test_build_url_forward_headers

 def test_build_url_forward_headers(self):
     request = DummyRequest()
     request.environ = {
         "SERVER_NAME": "example.com"
     }
     request.registry.settings = {
         "checker": {
             "forward_headers": ["Cookie"]
         }
     }
     request.headers["Cookie"] = "test"
     self.assertEqual(
         build_url(
             "Test",
             "https://camptocamp.com/toto?titi#tutu",
             request
         ),
         (
             "https://camptocamp.com/toto?titi#tutu",
             {
                 "Cache-Control": "no-cache",
                 "Cookie": "test",
             }
         )
     )
开发者ID:craxxkid,项目名称:c2cgeoportal,代码行数:25,代码来源:test_checker.py

示例12: test_call_exception

    def test_call_exception(self):

        class ExceptionPaginationReader(object):
            # pylint: disable=too-few-public-methods

            def __init__(self, exception):
                self._exception = exception

            def __call__(self, request, content_size_provider):
                raise self._exception


        content_size_provider_mock = ContentSizeProviderMock(100)

        request = DummyRequest()
        request.registry.pagination = {
            'some_route': {
                'content_size_provider': content_size_provider_mock,
                'pagination_reader': ExceptionPaginationReader(
                    PageNotFoundException()),
            }
        }
        request.matched_route = RouteMock('some_route')

        event = ContextFoundEventMock(request)
        subscriber = PaginationContextFoundSubscriber()
        with self.assertRaises(ParameterValidationException):
            subscriber(event)
开发者ID:C3S,项目名称:c3sMembership,代码行数:28,代码来源:test_init.py

示例13: _undo_delete_column

    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,代码行数:25,代码来源:base.py

示例14: test_websocket_view_same_origin

def test_websocket_view_same_origin(config):
    # example.com is the dummy request default host URL
    config.registry.settings.update({'origins': []})
    req = DummyRequest(headers={'Origin': 'http://example.com'})
    req.get_response = lambda _: mock.sentinel.good_response
    res = views.websocket_view(req)
    assert res == mock.sentinel.good_response
开发者ID:Cinemacloud,项目名称:h,代码行数:7,代码来源:views_test.py

示例15: test_leaders_weekly

 def test_leaders_weekly(self):
     session = self.db_master_session
     for i in range(3):
         user = User(nickname=unicode(i))
         session.add(user)
         session.flush()
         score1 = Score(userid=user.id, value=i)
         score1.name = 'new_cell'
         session.add(score1)
         score2 = Score(userid=user.id, value=i)
         score2.name = 'new_wifi'
         session.add(score2)
     session.commit()
     request = DummyRequest()
     request.db_slave_session = self.db_master_session
     inst = self._make_view(request)
     result = inst.leaders_weekly_view()
     for score_name in ('new_cell', 'new_wifi'):
         self.assertEqual(
             result['scores'][score_name]['leaders1'],
             [{'nickname': u'2', 'num': 2, 'pos': 1},
              {'nickname': u'1', 'num': 1, 'pos': 2}])
         self.assertEqual(
             result['scores'][score_name]['leaders2'],
             [{'nickname': u'0', 'num': 0, 'pos': 3}])
开发者ID:abhi12ravi,项目名称:ichnaea,代码行数:25,代码来源:test_views.py


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