• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python twill.add_wsgi_intercept函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_multirefeed

    def test_multirefeed(self):
        """
        Test playback of multiple requests.
        """
        recorder = scotch.recorder.Recorder(simple_app.post_app)

        # first, record.
        twill.add_wsgi_intercept('localhost', 80, lambda: recorder)
        try:
            twill.commands.go('http://localhost:80/')
            assert simple_app.success()
            simple_app.reset()
            
            twill.commands.fv('1', 'test', 'howdy world')
            twill.commands.submit()
            twill.commands.find("VALUE WAS: howdy world")
            assert simple_app.success()
        finally:
            simple_app.reset()
            twill.remove_wsgi_intercept('localhost', 80)

        # check the length of the recorded bit.
        assert len(recorder.record_holder) == 2

        # play it all back.
        try:
            assert not simple_app.success()
            for record in recorder.record_holder:
                record.refeed(simple_app.post_app)
            assert simple_app.success()
        finally:
            simple_app.reset()
开发者ID:ctb,项目名称:scotch,代码行数:32,代码来源:test-recorder.py


示例2: setUp

    def setUp(self):
        '''Create the app'''
        test_path =  os.path.abspath(os.path.dirname(__file__))
        testpath_command = "setglobal test_path " + test_path
        twill.execute_string(testpath_command)

        fixtures = os.path.join(test_path, 'fixtures')
        for to_delete in [fname for fname in os.listdir(fixtures)
                          if fname.startswith('Data.fs') or fname in ['blobs']]:
            _rm(os.path.join(fixtures, to_delete))
        os.mkdir(os.path.join(fixtures, 'blobs'))
        wsgi_app = get_app(os.path.join(test_path, 'fixtures', 'karl.ini'),
                           'main')

        def build_app():
            return wsgi_app

        twill.add_wsgi_intercept('localhost', 6543, build_app)
        # XXX How do we suppress the annoying "AT LINE: " output?
        twill.set_output(open('/dev/null', 'wb'))
        twill.execute_string("extend_with karl.twillcommands")

        # mostly the same as karl3.conf without extending with flunc
        # and few other adjustments.

        twill.execute_string("runfile '" +
                             os.path.abspath(os.path.dirname(__file__)) +
                             "/test_twill_wsgi_karl3.conf'")
开发者ID:Falmarri,项目名称:karl,代码行数:28,代码来源:test_twill_wsgi.py


示例3: test_middleware_composer

def test_middleware_composer():
    """Middleware stack should alter return in order.."""

    def make_middleware(txt):
        def middleware(app):
            def wrappedapp(environ, start_response):
                res = app(environ, start_response)
                res.append(txt)
                return res
            return wrappedapp
        return middleware

    # Environ predicates
    t = lambda x: True
    f = lambda x: False
    rules = [(t, make_middleware('a')),
             (f, make_middleware('b')),
             (t, make_middleware('c')),
             (f, make_middleware('d')),
             (t, make_middleware('e'))]

    def app(environ, start_response):
        start_response("200 OK", [('Content-type', 'text/plain')])
        return ["ok "]

    composed = selector.MiddlewareComposer(app, rules)
    twill.add_wsgi_intercept('simple-host', 80, lambda: composed)
    browser = twill.get_browser()
    browser.go('http://simple-host/endpoint')
    assert browser.result.page.startswith("ok eca")
    assert browser.result.http_code == 200
开发者ID:cdent,项目名称:selector,代码行数:31,代码来源:test_middleware_composer.py


示例4: test_refeed

    def test_refeed(self):
        """
        Try refeeding the content into the app.
        """
        
        recorder = scotch.recorder.Recorder(simple_app.iter_app)

        # first, record.
        twill.add_wsgi_intercept('localhost', 80, lambda: recorder)
        try:
            twill.commands.go('http://localhost:80/')
            output1 = twill.commands.show()
            assert simple_app.success()
        finally:
            simple_app.reset()
            twill.remove_wsgi_intercept('localhost', 80)

        # get the recorded bit.
        assert len(recorder.record_holder) == 1
        record = recorder.record_holder[0]

        try:
            response = record.refeed(simple_app.iter_app)
            assert simple_app.success()
            output2 = response.get_output()
            assert output1 == output2
        finally:
            simple_app.reset()
开发者ID:ctb,项目名称:scotch,代码行数:28,代码来源:test-recorder.py


示例5: begin

    def begin(self):
        from django.conf import settings
        from django.core.handlers.wsgi import WSGIHandler
        from django.test.simple import TEST_MODULE

        from tddspry.django.settings import IP, PORT

        from twill import add_wsgi_intercept

        log.debug('DjangoPlugin start')

        # Find to Django models in tests modules for each of ``INSTALLED_APPS``
        for label in settings.INSTALLED_APPS:
            tests = label + '.' + TEST_MODULE

            try:
                self.load_tests(tests)
            except (AttributeError, ImportError):
                pass

        # Setup Django test environment and test database
        self.setup_django()

        # Setup Twill for testing with Django
        try:
            from django.contrib.staticfiles.handlers import StaticFilesHandler
            if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
                app = StaticFilesHandler(WSGIHandler())
            else:
                app = WSGIHandler()
        except ImportError:  # django < 1.5
            from django.core.servers.basehttp import AdminMediaHandler
            app = AdminMediaHandler(WSGIHandler())
        add_wsgi_intercept(IP, PORT, lambda: app)
开发者ID:meako689,项目名称:tddspry,代码行数:34,代码来源:djangoplugin.py


示例6: run_server_wsgi_intercept

def run_server_wsgi_intercept(dbfilename):
    host = 'localhost'
    port = 80
    
    from pony_build import server, coordinator, dbsqlite
    from pony_build.web import create_publisher, urls
    
    dbfile = dbsqlite.open_shelf(dbfilename)
    dbfile = coordinator.IntDictWrapper(dbfile)

    ###

    pbs_app = coordinator.PonyBuildCoordinator(db=dbfile)
    wsgi_app = create_publisher(pbs_app)

    #the_server = server.create(host, port, pbs_app, wsgi_app)
    url = urls.calculate_base_url(host, port)
    urls.set_base_url(url)

    twill.add_wsgi_intercept('localhost', port, lambda: wsgi_app)

    global _server_url, _server_host, _server_port
    _server_host = host
    _server_port = port
    _server_url = 'http://%s:%d/' % (host, port)
开发者ID:ctb,项目名称:pony-build,代码行数:25,代码来源:testutil.py


示例7: test_not_found

def test_not_found():
    """The "not found" handler return a 404."""
    twill.add_wsgi_intercept('not-found-host', 80, lambda: not_found)
    browser = twill.get_browser()
    browser.go('http://not-found-host/')
    assert browser.result.page.startswith("404 Not Found")
    assert browser.result.http_code == 404
开发者ID:cdent,项目名称:selector,代码行数:7,代码来源:test_default_handlers.py


示例8: __enter__

 def __enter__(self):
     twill.set_output(StringIO.StringIO())
     twill.commands.clear_cookies()
     twill.add_wsgi_intercept(self.host, 
                              self.port, 
                              lambda: self.app)
 
     return self
开发者ID:gperetin,项目名称:flask-testing,代码行数:8,代码来源:testing.py


示例9: setup

 def setup(self):
     """ setup twill virtual web server and fill db with test data """
     sys.path.insert(0, test_settings.PROJECT_DIR)
     app = AdminMediaHandler(WSGIHandler())
     add_wsgi_intercept(IP, PORT, lambda: app)
     try:
         call_command('syncdb', verbosity=0, interactive=False)
     except SystemExit:
         pass
开发者ID:xaratt,项目名称:andrytest,代码行数:9,代码来源:common.py


示例10: install_twill

 def install_twill(self):
     wsgi_app = self.wsgi_request
     # TODO: we should run all requests through the validator. For now it's
     # disabled because it mysteriously breaks some tests.
     #if wsgiref:
     #    wsgi_app = wsgiref.validate.validator(wsgi_app)
     twill.add_wsgi_intercept('localhost', 80, lambda: wsgi_app)
     self.browser = twill.browser.TwillBrowser()
     self.divert_twill_output()
开发者ID:bogtan,项目名称:Naaya,代码行数:9,代码来源:NaayaFunctionalTestCase.py


示例11: setup

   def setup(self):
       '''
       - setup twill virtual web server
       '''
       from django.core.servers.basehttp import AdminMediaHandler
       from django.core.handlers.wsgi import WSGIHandler

       app = AdminMediaHandler(WSGIHandler())
       twill.add_wsgi_intercept(IP, PORT, lambda: app)
开发者ID:0lejka,项目名称:firstone,代码行数:9,代码来源:TwillMock.py


示例12: _pre_setup

 def _pre_setup(self):
     super(TwillTestCase, self)._pre_setup()
     twill.set_output(StringIO.StringIO())
     twill.commands.clear_cookies()
     twill.add_wsgi_intercept(self.twill_host, 
                              self.twill_port, 
                              lambda: self.app)
 
     self.browser = twill.get_browser()
开发者ID:gperetin,项目名称:flask-testing,代码行数:9,代码来源:testing.py


示例13: test_iter_stuff

def test_iter_stuff():
    twill.add_wsgi_intercept('localhost', 80, iterator_app)
    print 'go'
    twill.commands.go('http://localhost:80/')
    print 'find'
    twill.commands.show()
    twill.commands.find("Hello, world")
    twill.commands.notfind("Hello, worldHello, world")
    print 'remove'
    twill.remove_wsgi_intercept('localhost', 80)
开发者ID:ArtMatt,项目名称:twill-ca,代码行数:10,代码来源:test-wsgi-intercept.py


示例14: setUp

    def setUp(self):
        from django.contrib.auth.models import User

        user = User.objects.create_user("john", "[email protected]", "johnpassword")
        user.save()
        from whosendsignal.who_do import *

        auth = LoggedInUser()
        auth.user = user
        twill.add_wsgi_intercept("twilltest", 80, WSGIHandler)
开发者ID:attichka,项目名称:42-test-atti3,代码行数:10,代码来源:tests.py


示例15: test_method_not_allowed

def test_method_not_allowed():
    """The "method not allowed" handler return a 405."""
    def app(environ, start_response):
        environ['selector.methods'] = ['GET', 'PUT']
        return method_not_allowed(environ, start_response)
    twill.add_wsgi_intercept('not-found-host', 80, lambda: app)
    browser = twill.get_browser()
    browser.go('http://not-found-host/')
    assert browser.result.page.startswith("405 Method Not Allowed")
    assert browser.result.http_code == 405
开发者ID:cdent,项目名称:selector,代码行数:10,代码来源:test_default_handlers.py


示例16: setup

    def setup(self):
        wsgi_app = None

        x = sys.stdout  # Quixote mangles sys.stdout; save.
        try:
            publisher = create_publisher()
            wsgi_app = quixote.get_wsgi_app()
        finally:
            sys.stdout = x  # restore.

        twill.add_wsgi_intercept("localhost", 80, lambda: wsgi_app, "/qx_test")
开发者ID:nascheme,项目名称:quixote,代码行数:11,代码来源:test-wsgi.py


示例17: setup

def setup():
    cpy.config.update("site.conf")
    cpy.config.update("basic.conf")
    wsgi = cpy.tree.mount(blox.BlogRoot(), "/", "basic.conf")
    wsgi = cpy.tree.mount(blox.BlogRoot(), "/", "basic.conf")
    twill.add_wsgi_intercept('localhost', 4444, lambda: wsgi)
    syserr, sys.stderr = sys.stderr, StringIO()
    try:
        cpy.engine.start(blocking=False)
    finally:
        sys.stderr = syserr
开发者ID:llimllib,项目名称:cherry-blossom,代码行数:11,代码来源:test.py


示例18: setup

def setup():
    """
    Set up a wsgi intercept
    """
    import os
    os.environ["DJANGO_SETTINGS_MODULE"] = "simpletest.settings"

    from django.core.servers.basehttp import AdminMediaHandler
    from django.core.handlers.wsgi import WSGIHandler

    app = AdminMediaHandler(WSGIHandler())
    add_wsgi_intercept("127.0.0.1", 9876, lambda: app)
开发者ID:fordexa,项目名称:simpletest,代码行数:12,代码来源:tests.py


示例19: before_all

def before_all(context):
    context.baseurl = 'http://127.0.0.1:8000'
    twill.set_output(StringIO.StringIO())
    twill.commands.clear_cookies()
    context.app = beer_app.create_app()
    context.app.config['TESTING'] = True
    # fn=(lambda : context.app), it help create the WSGI app object only once, 
    # because function passed into wsgi_intercept is called 
    # once for each intercepted connection
    # more here: http://ivory.idyll.org/articles/twill-and-wsgi_intercept.html
    twill.add_wsgi_intercept('127.0.0.1', 8000, lambda : context.app)
    context.browser = twill.get_browser()
开发者ID:DotNetAge,项目名称:lab-ci,代码行数:12,代码来源:environment.py


示例20: setUp

 def setUp(self):
     super(AdminSurveyTwillTest, self).setUp()
     self.old_propagate = settings.DEBUG_PROPAGATE_EXCEPTIONS
     settings.DEBUG_PROPAGATE_EXCEPTIONS = True
     signals.request_finished.disconnect(close_connection)
     twill.set_output(StringIO())
     twill.add_wsgi_intercept(TWILL_TEST_HOST, 80, WSGIHandler)
     self.browser = twill.get_browser()
     self.browser.go(reverse_for_twill('admin:index'))
     twill.commands.formvalue(1, 'username', self.username)
     twill.commands.formvalue(1, 'password', self.pw)
     self.browser.submit()
     twill.commands.find('Welcome')
开发者ID:alexisbellido,项目名称:django-test-debug,代码行数:13,代码来源:admin_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python twill.execute_string函数代码示例发布时间:2022-05-27
下一篇:
Python values.of函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap