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

Python werkzeug.Client类代码示例

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

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



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

示例1: TestWSLoader

class TestWSLoader(unittest.TestCase):
    def setUp(self):
        app = wsloader.WSLoader(confdir = os.getcwd() + '/conf/')
        self.client = Client(app, BaseResponse)

    def test_service_check(self):
        response = self.client.get("/greeter/service_check")
        print response.data
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, "OK")

    def test_defaults(self):
        response = self.client.get("/greeter/say_hello")
        self.assertEqual(response.status_code, 200)
        body = json.loads(response.data)
        self.assertEqual(body['response'], "Hello World!")

    def test_aliased_class(self):
        response = self.client.get('/helloworld/say_hello?greeting="Hola"&to_whom="Amigos!"')
        try:
            body = json.loads(response.data)
        except Exception, e:
            print e
            print response.data
            return
        self.assertEqual(body['response'], "Hola Amigos!")
开发者ID:codemartial,项目名称:wsloader,代码行数:26,代码来源:test.py


示例2: SessionMiddlewareTestCase

class SessionMiddlewareTestCase(GAETestBase):
  KIND_NAME_UNSWAPPED = False
  USE_PRODUCTION_STUBS = True
  CLEANUP_USED_KIND = True

  def setUp(self):
    s = LazySettings(settings_module='kay.tests.settings')
    app = get_application(settings=s)
    self.client = Client(app, BaseResponse)

  def tearDown(self):
    pass

  def test_countup(self):
    response = self.client.get('/countup')
    self.assertEqual(response.status_code, 200)
    self.assertEqual(response.data, '1')
    response = self.client.get('/countup')
    self.assertEqual(response.data, '2')
    response = self.client.get('/countup')
    self.assertEqual(response.data, '3')
    response = self.client.get('/countup')
    self.assertEqual(response.data, '4')
    response = self.client.get('/countup')
    self.assertEqual(response.data, '5')
开发者ID:IanLewis,项目名称:kay,代码行数:25,代码来源:session_test.py


示例3: TestSession

class TestSession(unittest.TestCase):

    def setUp(self):
        self.app = make_wsgi('Testruns')
        self.client = Client(self.app, BaseResponse)

    def tearDown(self):
        self.client = None
        self.app = None

    def test_session_persist(self):
        r = self.client.get('/sessiontests/setfoo')

        self.assertEqual(r.status, '200 OK')
        self.assertEqual(r.data, b'foo set')

        r = self.client.get('/sessiontests/getfoo')

        self.assertEqual(r.status, '200 OK')
        self.assertEqual(r.data, b'bar')

    def test_session_regen_id(self):
        ta = TestApp(self.app)

        r = ta.get('/sessiontests/setfoo', status=200)
        assert r.session['foo'] == 'bar'
        sid = r.session.id
        assert sid in r.headers['Set-Cookie']

        r = ta.get('/sessiontests/regenid', status=200)
        assert r.session.id != sid
        assert r.session.id in r.headers['Set-Cookie']

        r = ta.get('/sessiontests/getfoo', status=200)
        assert r.body == b'bar'
开发者ID:level12,项目名称:blazeweb,代码行数:35,代码来源:test_session.py


示例4: test_responder

def test_responder():
    """Responder decorator"""
    def foo(environ, start_response):
        return BaseResponse('Test')
    client = Client(responder(foo), BaseResponse)
    response = client.get('/')
    assert response.status_code == 200
    assert response.data == 'Test'
开发者ID:marchon,项目名称:checkinmapper,代码行数:8,代码来源:test_wsgi.py


示例5: test_ie7_unc_path

def test_ie7_unc_path():
    client = Client(form_data_consumer, Response)
    data_file = join(dirname(__file__), 'multipart', 'ie7_full_path_request.txt')
    data = get_contents(data_file)
    boundary = '---------------------------7da36d1b4a0164'
    response = client.post('/?object=cb_file_upload_multiple', data=data, content_type=
                               'multipart/form-data; boundary="%s"' % boundary, content_length=len(data))
    lines = response.data.split('\n', 3)
    assert lines[0] == repr(u'Sellersburg Town Council Meeting 02-22-2010doc.doc'), lines[0]
开发者ID:marchon,项目名称:checkinmapper,代码行数:9,代码来源:test_formparser.py


示例6: TasksViewTest

class TasksViewTest(unittest.TestCase):

    def setUp(self):
        self.c = Client(views.handler, BaseResponse)
        # clear state
        views.TASKS = {}
        views.clients = {}
        views.subscriptions = {}

    def test_POST(self):
        t = models.Task(name='Task1')
        r = self.c.post(path='/tasks/', headers={'Content-Type':tubes.JSON}, data=t.to_json_str())

        # check response
        self.assertEquals(r.status_code, 201)
        task = json.loads(r.data)
        self.assertEquals(task['name'], 'Task1')
        self.assertTrue('/tasks/0' in r.headers.get('Location'))

        # back-end
        task = views.TASKS['0']
        self.assertTrue(task != None)
        self.assertEquals(task.name, 'Task1')

    def test_PUT(self):
        views.TASKS['0'] = models.Task()
        r = self.c.put(path='/tasks/0',
                       headers={'Content-Type':tubes.JSON},
                       data=models.Task(name='Task_0').to_json_str())
        self.assertEquals(r.status_code, 200)

        # check response
        task = json.loads(r.data)
        self.assertEquals(task['name'], 'Task_0')

        # back-end
        task = views.TASKS['0']
        self.assertEquals(task.name, 'Task_0')

    def test_DELETE(self):
        views.TASKS['0'] = models.Task()
        r = self.c.delete(path='/tasks/0')
        self.assertEquals(r.status_code, 204)
        self.assertTrue(views.TASKS.get('0') == None)

    def test_GET_tasks(self):
        views.TASKS['0'] = models.Task(name='foo')
        r = self.c.get(path='/tasks/')
        self.assertTrue('foo' in r.data)

    def test_GET_task(self):
        views.TASKS['0'] = models.Task(name='foo')
        r = self.c.get(path='/tasks/0')
        self.assertTrue('foo' in r.data)
开发者ID:jakobadam,项目名称:letsplantheevent,代码行数:54,代码来源:tests.py


示例7: MaintenanceCheckTestCase

class MaintenanceCheckTestCase(unittest.TestCase):
  
  def setUp(self):
    apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
    stub = datastore_file_stub.DatastoreFileStub('test','/dev/null',
                                                 '/dev/null')
    apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)

    apiproxy_stub_map.apiproxy.RegisterStub(
      'user', user_service_stub.UserServiceStub())

    apiproxy_stub_map.apiproxy.RegisterStub(
      'memcache', memcache_stub.MemcacheServiceStub())

    apiproxy_stub_map.apiproxy.RegisterStub(
      'urlfetch', urlfetch_stub.URLFetchServiceStub())

    s = LazySettings(settings_module='kay.tests.settings')
    app = get_application(settings=s)
    self.client = Client(app, BaseResponse)
    if apiproxy_stub_map.apiproxy\
          ._APIProxyStubMap__stub_map.has_key('capability_service'):
      del(apiproxy_stub_map.apiproxy\
            ._APIProxyStubMap__stub_map['capability_service'])

  def tearDown(self):
    pass

  def test_success(self):
    """Test with normal CapabilityServiceStub"""
    apiproxy_stub_map.apiproxy.RegisterStub(
      'capability_service',
      capability_stub.CapabilityServiceStub())
    response = self.client.get('/')
    self.assertEqual(response.status_code, 200)

  def test_failure(self):
    """Test with DisabledCapabilityServiceStub
    """
    apiproxy_stub_map.apiproxy.RegisterStub(
      'capability_service',
      mocked_capability_stub.DisabledCapabilityServiceStub())
    response = self.client.get('/')
    self.assertEqual(response.status_code, 302)
    self.assertEqual(response.headers['Location'],
                     'http://localhost/maintenance_page')

    response = self.client.get('/index2')
    self.assertEqual(response.status_code, 302)
    self.assertEqual(response.headers['Location'],
                     'http://localhost/no_decorator')
    response = self.client.get('/no_decorator')
    self.assertEqual(response.status_code, 200)
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:53,代码来源:decorator_test.py


示例8: wrapper

 def wrapper(self):
     client = Client(Application(), BaseResponse)
     response = client.get(url, headers={'Accept': accept})
     eq_(response.status_code, status_code)
     if template:
         assert response.template ==template
     f(self, response, response.context, PyQuery(response.data))
     # Validate after other tests so we know everything else works.
     # Hacky piggybacking on --verbose so tests go faster.
     if '--verbose' in sys.argv:
         validator = post_multipart('validator.w3.org', '/check',
                                    {'fragment': response.data})
         assert PyQuery(validator)('#congrats').size() == 1
开发者ID:jbalogh,项目名称:bosley,代码行数:13,代码来源:test_views.py


示例9: AppStatsMiddlewareTestCase

class AppStatsMiddlewareTestCase(GAETestBase):
  KIND_NAME_UNSWAPPED = False
  USE_PRODUCTION_STUBS = True
  CLEANUP_USED_KIND = True

  def setUp(self):
    from google.appengine.api import memcache
    memcache.flush_all()
    s = LazySettings(settings_module='kay.tests.appstats_settings')
    app = get_application(settings=s)
    self.client = Client(app, BaseResponse)

  def tearDown(self):
    pass

  def test_appstats_middleware(self):

    request = Request({})
    middleware = AppStatsMiddleware()

    r = middleware.process_request(request)
    self.assertTrue(r is None)

    r = middleware.process_response(request, BaseResponse("", 200))
    self.assertTrue(isinstance(r, BaseResponse))

    summary = recording.load_summary_protos()
    self.assert_(summary)

  def test_appstats_middleware_request(self):

    response = self.client.get('/no_decorator')
    summary = recording.load_summary_protos()
    self.assert_(summary)
开发者ID:dbordak,项目名称:pyblog,代码行数:34,代码来源:appstats_test.py


示例10: setUp

 def setUp(self):
     self.test_doc_path = mkdtemp()
     self.doc = open_document(path.join(self.test_doc_path, 'test_doc.db'))
     self.doc.create_note({'desc': 'note 1'})
     self.doc.create_note({'desc': 'note 2'})
     self.app = server.CorkApp(self.doc)
     self.client = Client(self.app, BaseResponse)
开发者ID:mgax,项目名称:notespace,代码行数:7,代码来源:webapi.py


示例11: DownloadicsTest

class DownloadicsTest(GAETestBase):

    def setUp(self):
        app = get_application()
        self.client = Client(app, BaseResponse)

        self.test_values = {
            'date': datetime.datetime(2016, 5, 20, 15, 0),
            'title': 'THIS IS TITLE',
            'description': 'THIS IS TITLE',
        }

        eve = Event(
            event_date=self.test_values['date'],
            title=self.test_values['title'],
            description=self.test_values['description'],
        )
        eve.put()
        events = Event.all().fetch(100)
        self.assertEquals(len(events), 1)
        self.assertEquals(events[0].title, 'THIS IS TITLE')
        self.event_key = str(events[0].key())

    def test_download_individual_icsfile(self):
        target_url = urlparse.urljoin('/ical/', self.event_key)
        res = self.client.get(target_url)
        self.assertEquals(res.status_code, 200)

        downloaded = res.get_data()
        reparsed = icalendar.Calendar.from_ical(downloaded)
        reparsed_eve = reparsed.walk('VEVENT')[0]
        stringfied = self.test_values['date'].strftime('%Y%m%dT%H%M%S')
        self.assertEquals(reparsed_eve['summary'].to_ical(), self.test_values['title'])
        self.assertEquals(reparsed_eve['dtstart'].to_ical(), stringfied)
        self.assertEquals(reparsed_eve['description'].to_ical(), self.test_values['description'])
开发者ID:yosukesuzuki,项目名称:calendar-app,代码行数:35,代码来源:test_views.py


示例12: open

    def open(self, *args, **kwargs):
        if self.context_preserved:
            _request_ctx_stack.pop()
            self.context_preserved = False
        kwargs.setdefault('environ_overrides', {}) \
            ['flask._preserve_context'] = self.preserve_context

        as_tuple = kwargs.pop('as_tuple', False)
        buffered = kwargs.pop('buffered', False)
        follow_redirects = kwargs.pop('follow_redirects', False)

        builder = EnvironBuilder(*args, **kwargs)

        if self.application.config.get('SERVER_NAME'):
            server_name = self.application.config.get('SERVER_NAME')
            if ':' not in server_name:
                http_host, http_port = server_name, None
            else:
                http_host, http_port = server_name.split(':', 1)
            if builder.base_url == 'http://localhost/':
                # Default Generated Base URL
                if http_port != None:
                    builder.host = http_host + ':' + http_port
                else:
                    builder.host = http_host
        old = _request_ctx_stack.top
        try:
            return Client.open(self, builder,
                               as_tuple=as_tuple,
                               buffered=buffered,
                               follow_redirects=follow_redirects)
        finally:
            self.context_preserved = _request_ctx_stack.top is not old
开发者ID:EkkiD,项目名称:balrog,代码行数:33,代码来源:testing.py


示例13: CronOnlyTestCase

class CronOnlyTestCase(GAETestBase):

  def setUp(self):
    s = LazySettings(settings_module='kay.tests.settings')
    app = get_application(settings=s)
    self.client = Client(app, BaseResponse)

  def test_cron_only(self):
    response = self.client.get("/cron",
            headers=(('X-AppEngine-Cron', 'true'),))
    self.assertEqual(response.status_code, 200)
    self.assertTrue(response.data == "OK")

  def test_cron_only_failure(self):
    response = self.client.get("/cron")
    self.assertEqual(response.status_code, 403)
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:16,代码来源:decorator_test.py


示例14: setUp

 def setUp(self):
   s = LazySettings(settings_module='kay.tests.settings')
   app = get_application(settings=s)
   self.client = Client(app, BaseResponse)
   if apiproxy_stub_map.apiproxy\
         ._APIProxyStubMap__stub_map.has_key('capability_service'):
     del(apiproxy_stub_map.apiproxy\
           ._APIProxyStubMap__stub_map['capability_service'])
开发者ID:bguided,项目名称:synctester,代码行数:8,代码来源:decorator_test.py


示例15: ChannelsViewTest

class ChannelsViewTest(unittest.TestCase):

    def setUp(self):
        self.c = Client(views.handler, BaseResponse)

    def test_POSTing_with_create_client_id_header_should_create_new_channel(self):
        r = self.c.post(path="/channels/", headers={"Create-Client-Id":"1"})
        self.assertEquals(r.status_code, 200)
        self.assertTrue("1" in views.clients)
开发者ID:jakobadam,项目名称:letsplantheevent,代码行数:9,代码来源:tests.py


示例16: test_multipart

def test_multipart():
    """Tests multipart parsing against data collected from webbrowsers"""
    resources = join(dirname(__file__), 'multipart')
    client = Client(form_data_consumer, Response)

    repository = [
        ('firefox3-2png1txt', '---------------------------186454651713519341951581030105', [
            (u'anchor.png', 'file1', 'image/png', 'file1.png'),
            (u'application_edit.png', 'file2', 'image/png', 'file2.png')
        ], u'example text'),
        ('firefox3-2pnglongtext', '---------------------------14904044739787191031754711748', [
            (u'accept.png', 'file1', 'image/png', 'file1.png'),
            (u'add.png', 'file2', 'image/png', 'file2.png')
        ], u'--long text\r\n--with boundary\r\n--lookalikes--'),
        ('opera8-2png1txt', '----------zEO9jQKmLc2Cq88c23Dx19', [
            (u'arrow_branch.png', 'file1', 'image/png', 'file1.png'),
            (u'award_star_bronze_1.png', 'file2', 'image/png', 'file2.png')
        ], u'blafasel öäü'),
        ('webkit3-2png1txt', '----WebKitFormBoundaryjdSFhcARk8fyGNy6', [
            (u'gtk-apply.png', 'file1', 'image/png', 'file1.png'),
            (u'gtk-no.png', 'file2', 'image/png', 'file2.png')
        ], u'this is another text with ümläüts'),
        ('ie6-2png1txt', '---------------------------7d91b03a20128', [
            (u'file1.png', 'file1', 'image/x-png', 'file1.png'),
            (u'file2.png', 'file2', 'image/x-png', 'file2.png')
        ], u'ie6 sucks :-/')
    ]

    for name, boundary, files, text in repository:
        folder = join(resources, name)
        data = get_contents(join(folder, 'request.txt'))
        for filename, field, content_type, fsname in files:
            response = client.post('/?object=' + field, data=data, content_type=
                                   'multipart/form-data; boundary="%s"' % boundary,
                                   content_length=len(data))
            lines = response.data.split('\n', 3)
            assert lines[0] == repr(filename)
            assert lines[1] == repr(field)
            assert lines[2] == repr(content_type)
            assert lines[3] == get_contents(join(folder, fsname))
        response = client.post('/?object=text', data=data, content_type=
                               'multipart/form-data; boundary="%s"' % boundary,
                               content_length=len(data))
        assert response.data == repr(text)
开发者ID:marchon,项目名称:checkinmapper,代码行数:44,代码来源:test_formparser.py


示例17: MaintenanceCheckTestCase

class MaintenanceCheckTestCase(unittest.TestCase):
    def setUp(self):
        apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
        stub = datastore_file_stub.DatastoreFileStub("test", "/dev/null", "/dev/null")
        apiproxy_stub_map.apiproxy.RegisterStub("datastore_v3", stub)

        apiproxy_stub_map.apiproxy.RegisterStub("user", user_service_stub.UserServiceStub())

        apiproxy_stub_map.apiproxy.RegisterStub("memcache", memcache_stub.MemcacheServiceStub())

        apiproxy_stub_map.apiproxy.RegisterStub("urlfetch", urlfetch_stub.URLFetchServiceStub())

        s = LazySettings(settings_module="kay.tests.settings")
        app = get_application(settings=s)
        self.client = Client(app, BaseResponse)
        if apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map.has_key("capability_service"):
            del (apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map["capability_service"])

    def tearDown(self):
        pass

    def test_success(self):
        """Test with normal CapabilityServiceStub"""
        apiproxy_stub_map.apiproxy.RegisterStub("capability_service", capability_stub.CapabilityServiceStub())
        response = self.client.get("/")
        self.assertEqual(response.status_code, 200)

    def test_failure(self):
        """Test with DisabledCapabilityServiceStub
    """
        apiproxy_stub_map.apiproxy.RegisterStub(
            "capability_service", mocked_capability_stub.DisabledCapabilityServiceStub()
        )
        response = self.client.get("/")
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.headers["Location"], "http://localhost/maintenance_page")

        response = self.client.get("/index2")
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.headers["Location"], "http://localhost/no_decorator")
        response = self.client.get("/no_decorator")
        self.assertEqual(response.status_code, 200)
开发者ID:soha,项目名称:BooksGoten,代码行数:42,代码来源:decorator_test.py


示例18: open

 def open(self, *args, **kwargs):
     if self.context_preserved:
         _request_ctx_stack.pop()
         self.context_preserved = False
     kwargs.setdefault('environ_overrides', {}) \
         ['flask._preserve_context'] = self.preserve_context
     old = _request_ctx_stack.top
     try:
         return Client.open(self, *args, **kwargs)
     finally:
         self.context_preserved = _request_ctx_stack.top is not old
开发者ID:1ncnspcuous,项目名称:WebPutty,代码行数:11,代码来源:testing.py


示例19: CronOnlyDebugTestCase

class CronOnlyDebugTestCase(GAETestBase):

  def setUp(self):
    s = LazySettings(settings_module='kay.tests.settings')
    s.DEBUG = True
    app = get_application(settings=s)
    self.client = Client(app, BaseResponse)

  def test_cron_only_failure(self):
    from kay.utils import is_dev_server
    response = self.client.get("/cron")
    if is_dev_server():
      self.assertEqual(response.status_code, 200)
    else:
      self.assertEqual(response.status_code, 403)

  def test_cron_only(self):
    response = self.client.get("/cron",
            headers=(('X-AppEngine-Cron', 'true'),))
    self.assertEqual(response.status_code, 200)
    self.assertTrue(response.data == "OK")
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:21,代码来源:decorator_test.py


示例20: test_View_index

class test_View_index(GAETestBase):
  CLEANUP_USED_KIND = True
  USE_PRODUCTION_STUBS = True

  def setUp(self):
    init_recording()
    app = get_application()
    self.client = Client(app, BaseResponse)

  def tearDown(self):
    disable_recording()

  def test_base(self):
    response = self.client.get('/')
    self.assertEquals(response.status_code, 404)

  def test_client_get(self):
    response = self.client.get('/client')
    self.assertEquals(response.status_code, 301)

  def test_client_head(self):
    self.fail('test_View_index.test_client_head not yet written')

  def test_client_post(self):
    self.fail('test_View_index.test_client_post not yet written')

  def test_client_put(self):
    self.fail('test_View_index.test_client_put not yet written')

  def test_client_delete(self):
    self.fail('test_View_index.test_client_delete not yet written')

  def test_client_options(self):
    self.fail('test_View_index.test_client_options not yet written')

  def test_client_trace(self):
    self.fail('test_View_index.test_client_trace not yet written')

  def test_client_connect(self):
    self.fail('test_View_index.test_client_connect not yet written')
开发者ID:sagallagherstarr,项目名称:OPURL-SERVER,代码行数:40,代码来源:Test_View_index.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python werkzeug.Headers类代码示例发布时间:2022-05-26
下一篇:
Python werkzeug.url_encode函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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