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


Python TestApp.get方法代码示例

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


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

示例1: ViewsFunctionalTest

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
class ViewsFunctionalTest(unittest.TestCase):

    def setUp(self):
        from adhocracy_frontend import main
        from webtest import TestApp
        app = main({})
        self.testapp = TestApp(app)

    @mark.xfail(reason='asset build:/stylesheets/a3.css must exists')
    def test_static_view(self):
        resp = self.testapp.get('/static/root.html', status=200)
        assert '200' in resp.status

    def test_config_json_view(self):
        resp = self.testapp.get('/config.json', status=200)
        assert '200' in resp.status

    @mark.xfail(reason='asset build:/stylesheets/a3.css must exists')
    def test_embed_view(self):
        resp = self.testapp.get('/embed/XX', status=200)
        assert '200' in resp.status

    @mark.xfail(reason='asset build:/stylesheets/a3.css must exists')
    def test_register_view(self):
        resp = self.testapp.get('/register', status=200)
        assert '200' in resp.status
开发者ID:fhartwig,项目名称:adhocracy3.mercator,代码行数:28,代码来源:test_init_.py

示例2: TestResource

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
class TestResource(unittest.TestCase):
    def setUp(self):
        from pyramid.renderers import JSONP

        self.config = testing.setUp()
        self.config.add_renderer("jsonp", JSONP(param_name="callback"))
        self.config.include("cornice")
        self.config.scan("cornice.tests.test_resource")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()

    def test_basic_resource(self):

        self.assertEquals(self.app.get("/users").json, {"status": "ok", "result": {"users": [1, 2]}})

        self.assertEquals(self.app.get("/users/1").json, {"status": "ok", "result": {"name": "gawel"}})
        resp = self.app.get("/users/1?callback=test")
        self.assertEquals(resp.body, 'test({"status": "ok", "result": {"name": "gawel"}})', resp.body)

    def test_accept_headers(self):
        # the accept headers should work even in case they're specified in a
        # resource method
        self.assertEquals(
            self.app.post("/users", headers={"Accept": "text/json"}, params=json.dumps({"test": "yeah"})).json,
            {"status": "ok", "result": {"test": "yeah"}},
        )
开发者ID:gulp-swe,项目名称:cornice,代码行数:30,代码来源:test_resource.py

示例3: test_enforce_https_wrong

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
 def test_enforce_https_wrong(self):
     config = copy.deepcopy(SHARED_DEFAULTS)
     config["enforce_https"] = True
     application = RoutingApplication(config)
     app = TestApp(application, extra_environ={"REMOTE_ADDR": "127.0.0.1"})
     app.get("/", status=406)
     app.post("/connect", status=406)
开发者ID:AppEnlight,项目名称:channelstream,代码行数:9,代码来源:tests_integration.py

示例4: test_404_with_lookup

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
    def test_404_with_lookup(self):

        class LookupController(RestController):

            def __init__(self, _id):
                self._id = _id

            @expose()
            def get_all(self):
                return 'ID: %s' % self._id

        class ThingsController(RestController):

            @expose()
            def _lookup(self, _id, *remainder):
                return LookupController(_id), remainder

        class RootController(object):
            things = ThingsController()

        # create the app
        app = TestApp(make_app(RootController()))

        # these should 404
        for path in ('/things', '/things/'):
            r = app.get(path, expect_errors=True)
            assert r.status_int == 404

        r = app.get('/things/foo')
        assert r.status_int == 200
        assert r.body == b_('ID: foo')
开发者ID:alex-devops,项目名称:pecan,代码行数:33,代码来源:test_rest.py

示例5: test_pull_task

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
    def test_pull_task():
        test_app = TestApp(app)

        session = create_session()
        task1 = Task()
        task1.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546018'
        task1.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546018'
        task1.claimed = datetime.utcnow()
        task1.data = json.dumps({'wait_time': 123})
        session.add(task1)

        task2 = Task()
        task2.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546019'
        task2.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546019'
        task2.claimed = datetime.utcnow()
        task2.completed = datetime.utcnow()
        task2.result_data = json.dumps({'result': 'epic success'})
        session.add(task2)

        task3 = Task()
        task3.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546020'
        task3.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546020'
        task3.claimed = datetime.utcnow()
        task3.failed = datetime.utcnow()
        task3.error = 'unknown error'
        session.add(task3)

        session.commit()

        test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546018')
        test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546019')
        test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546020')
开发者ID:SLAMon,项目名称:SLAMon,代码行数:34,代码来源:bpms_routes_tests.py

示例6: test_link_for_none_means_no_parameter

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
def test_link_for_none_means_no_parameter():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, id):
            self.id = id

    @app.path(model=Model, path='')
    def get_model(id):
        return Model(id)

    @app.view(model=Model)
    def default(self, request):
        return "View: %s" % self.id

    @app.view(model=Model, name='link')
    def link(self, request):
        return request.link(self)

    config.commit()

    c = Client(app())

    response = c.get('/')
    assert response.body == b"View: None"

    response = c.get('/link')
    assert response.body == b'http://localhost/'
开发者ID:binbrain,项目名称:morepath,代码行数:33,代码来源:test_path_directive.py

示例7: test_disconnect_hooks_multiple_listener

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
    def test_disconnect_hooks_multiple_listener(self):
        hook1_has_been_called = []
        def hook1_listener():
            hook1_has_been_called.append(True)

        hook2_has_been_called = []
        def hook2_listener():
            hook2_has_been_called.append(True)

        class RootController(TGController):
            @expose()
            def test(self):
                tg.hooks.notify('custom_hook', controller=RootController.test)
                return 'HI!'

        conf = AppConfig(minimal=True, root_controller=RootController())
        tg.hooks.register('custom_hook', hook1_listener)
        tg.hooks.register('custom_hook', hook2_listener)
        conf.package = PackageWithModel()
        app = conf.make_wsgi_app()
        app = TestApp(app)

        app.get('/test')
        app.get('/test')
        tg.hooks.disconnect('custom_hook', hook2_listener)
        app.get('/test')

        # Disconnecting an unregistered hook should do nothing.
        tg.hooks.disconnect('unregistered', hook1_listener)

        assert len(hook1_has_been_called) == 3, hook1_has_been_called
        assert len(hook2_has_been_called) == 2, hook2_has_been_called
开发者ID:984958198,项目名称:tg2,代码行数:34,代码来源:test_hooks.py

示例8: test_url_parameter_list_but_only_one_allowed

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
def test_url_parameter_list_but_only_one_allowed():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, item):
            self.item = item

    @app.path(model=Model, path='/', converters={'item': int})
    def get_model(item):
        return Model(item)

    @app.view(model=Model)
    def default(self, request):
        return repr(self.item)

    @app.view(model=Model, name='link')
    def link(self, request):
        return request.link(self)

    config.commit()

    c = Client(app())

    c.get('/?item=1&item=2', status=400)

    c.get('/link?item=1&item=2', status=400)
开发者ID:binbrain,项目名称:morepath,代码行数:31,代码来源:test_path_directive.py

示例9: test_extra_parameters

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
def test_extra_parameters():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, extra_parameters):
            self.extra_parameters = extra_parameters

    @app.path(model=Model, path='/')
    def get_model(extra_parameters):
        return Model(extra_parameters)

    @app.view(model=Model)
    def default(self, request):
        return repr(sorted(self.extra_parameters.items()))

    @app.view(model=Model, name='link')
    def link(self, request):
        return request.link(self)

    config.commit()

    c = Client(app())

    response = c.get('/?a=A&b=B')
    assert response.body in \
        (b"[(u'a', u'A'), (u'b', u'B')]", b"[('a', 'A'), ('b', 'B')]")
    response = c.get('/link?a=A&b=B')
    assert sorted(response.body[len('http://localhost/?'):].split(b"&")) == [
        b'a=A', b'b=B']
开发者ID:binbrain,项目名称:morepath,代码行数:34,代码来源:test_path_directive.py

示例10: TestServiceDefinition

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
class TestServiceDefinition(unittest2.TestCase):

    def setUp(self):
        if not metlog:
            raise(unittest2.SkipTest('no metlog'))
        mozconfig = Config(StringIO(dedent("""
        [test1]
        backend = mozsvc.metrics.MetlogPlugin
        sender_class=metlog.senders.DebugCaptureSender
        """)))
        settings = {"config": mozconfig}
        self.plugin = load_from_config("test1", mozconfig)
        self.config = Configurator(settings=settings)
        self.config.include("cornice")
        self.config.scan("mozsvc.tests.test_service_definition")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()

    def test_decorated_view_fn(self):
        # passing a decorator in to the service api call should result in a
        # decorated view callable
        resp = self.app.get("/service3")
        self.assertEquals(resp.json, {'test': 'succeeded', 'wrapped0': 'yes'})

    def test_stacked_decorated_view(self):
        # passing a decorator in to the service api call should result in a
        # decorated view callable, ordering of the particular decorators
        # shouldn't break things
        resp = self.app.get("/service4")
        self.assertEquals(resp.json, {'test': 'succeeded', 'wrapped0': 'yes'})

        resp = self.app.get("/service5")
        self.assertEquals(resp.json, {'test': 'succeeded', 'wrapped0': 'yes'})
开发者ID:ncalexan,项目名称:mozservices,代码行数:37,代码来源:test_service_definition.py

示例11: test_custom_serializer

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
def test_custom_serializer():
    was_used = [False, False]
    class CustomSerializer(object):
        def loads(self, data_string):
            was_used[0] = True
            return json.loads(data_string.decode('utf-8'))

        def dumps(self, data):
            was_used[1] = True
            return json.dumps(data).encode('utf-8')

    serializer = CustomSerializer()
    options = {'session.validate_key':'hoobermas', 'session.type':'cookie', 'data_serializer': serializer}
    app = TestApp(SessionMiddleware(simple_app, **options))

    res = app.get('/')
    assert 'current value is: 1' in res

    res = app.get('/')
    cookie = SignedCookie('hoobermas')
    session_data = cookie.value_decode(app.cookies['beaker.session.id'])[0]
    session_data = b64decode(session_data)
    data = serializer.loads(session_data)
    assert data['value'] == 2

    res = app.get('/')
    assert 'current value is: 3' in res

    assert all(was_used)
开发者ID:ardeois,项目名称:beaker,代码行数:31,代码来源:test_cookie_only.py

示例12: test_200

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
def test_200():
    from pyramid.config import Configurator
    from webtest import TestApp

    mock_metric = mock.Mock()

    def main(global_config, **settings):
        config = Configurator(settings=settings)
        config.include('pyramid_datadog')

        config.configure_metrics(mock_metric)

        def test_view(request):
            return {}

        config.add_route('home', '/')
        config.add_view(test_view, route_name='home', renderer='json')

        return config.make_wsgi_app()

    app = main({})
    app = TestApp(app)
    app.get('/')
    mock_metric.timing.assert_has_calls([
        mock.call('pyramid.request.duration.route_match', mock.ANY),
        mock.call('pyramid.request.duration.traversal', mock.ANY),
        mock.call('pyramid.request.duration.view', mock.ANY, tags=['route:home']),
        mock.call('pyramid.request.duration.template_render', mock.ANY, tags=['route:home']),
        mock.call('pyramid.request.duration.total', mock.ANY, tags=['route:home', 'status_code:200', 'status_type:2xx'])
    ])
开发者ID:SurveyMonkey,项目名称:pyramid_datadog,代码行数:32,代码来源:test_includeme.py

示例13: test_it

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
    def test_it(self):
        from pyramid.config import Configurator
        from pyramid_jinja2 import includeme
        from webtest import TestApp
        import os

        here = os.path.abspath(os.path.dirname(__file__))
        templates_dir = os.path.join(here, 'templates')

        def myview(request):
            return {}

        config1 = Configurator(settings={
                'jinja2.directories': os.path.join(templates_dir, 'foo')})
        includeme(config1)
        config1.add_view(view=myview, renderer='mytemplate.jinja2')
        config2 = Configurator(settings={
                'jinja2.directories': os.path.join(templates_dir, 'bar')})
        includeme(config2)
        config2.add_view(view=myview, renderer='mytemplate.jinja2')
        self.assertNotEqual(config1.registry.settings,
                            config2.registry.settings)

        app1 = config1.make_wsgi_app()
        testapp = TestApp(app1)
        self.assertEqual(testapp.get('/').body, bytes_('foo'))

        app2 = config2.make_wsgi_app()
        testapp = TestApp(app2)
        self.assertEqual(testapp.get('/').body, bytes_('bar'))
开发者ID:Mbosco,项目名称:pyramid_jinja2,代码行数:32,代码来源:test_it.py

示例14: NonAutocommittingConfigurationTestResource

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
class NonAutocommittingConfigurationTestResource(TestCase):
    """
    Test that we don't fail Pyramid's conflict detection when using a manually-
    committing :class:`pyramid.config.Configurator` instance.
    """

    def setUp(self):
        from pyramid.renderers import JSONP
        self.config = testing.setUp(autocommit=False)
        self.config.add_renderer('jsonp', JSONP(param_name='callback'))
        self.config.include("cornice")

        add_view(UserImp.get, renderer='json')
        add_view(UserImp.get, renderer='jsonp')
        add_view(UserImp.collection_post, renderer='json', accept='text/json')
        user_resource = add_resource(
            UserImp, collection_path='/users', path='/users/{id}',
            name='user_service', factory=dummy_factory)

        self.config.add_cornice_resource(user_resource)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()

    def test_get(self):
        self.app.get('/users/1')
开发者ID:joesteeve,项目名称:cornice,代码行数:29,代码来源:test_imperative_resource.py

示例15: test_variable_path_one_step

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import get [as 别名]
def test_variable_path_one_step():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, name):
            self.name = name

    @app.path(model=Model, path='{name}')
    def get_model(name):
        return Model(name)

    @app.view(model=Model)
    def default(self, request):
        return "View: %s" % self.name

    @app.view(model=Model, name='link')
    def link(self, request):
        return request.link(self)

    config.commit()

    c = Client(app())

    response = c.get('/foo')
    assert response.body == b'View: foo'

    response = c.get('/foo/link')
    assert response.body == b'http://localhost/foo'
开发者ID:binbrain,项目名称:morepath,代码行数:33,代码来源:test_path_directive.py


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