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

Python tests.http函数代码示例

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

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



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

示例1: test_session_read_only

    def test_session_read_only(self):
        # Get a response from the original session.
        r2 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
        assert HTTP_OK in r2

        # Make a request modifying the session data but
        # with --session-read-only.
        r3 = http('--follow', '--session-read-only=test',
                  '--auth=username:password2', 'GET',
                  httpbin('/cookies/set?hello=world2'), 'Hello:World2',
                  env=self.env())
        assert HTTP_OK in r3

        # Get a response from the updated session.
        r4 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
        assert HTTP_OK in r4

        # Origin can differ on Travis.
        del r2.json['origin'], r4.json['origin']
        # Different for each request.
        del r2.json['headers']['X-Request-Id']
        del r4.json['headers']['X-Request-Id']

        # Should be the same as before r3.
        assert r2.json == r4.json
开发者ID:alfred82santa,项目名称:httpie,代码行数:25,代码来源:test_sessions.py


示例2: test_session_by_path

    def test_session_by_path(self):
        session_path = os.path.join(self.config_dir, 'session-by-path.json')
        r1 = http('--session=' + session_path, 'GET', httpbin('/get'),
                  'Foo:Bar', env=self.env())
        assert HTTP_OK in r1

        r2 = http('--session=' + session_path, 'GET', httpbin('/get'),
                  env=self.env())
        assert HTTP_OK in r2
        assert r2.json['headers']['Foo'] == 'Bar'
开发者ID:alfred82santa,项目名称:httpie,代码行数:10,代码来源:test_sessions.py


示例3: test_session_ignored_header_prefixes

    def test_session_ignored_header_prefixes(self):
        r1 = http('--session=test', 'GET', httpbin('/get'),
                  'Content-Type: text/plain',
                  'If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT',
                  env=self.env())
        assert HTTP_OK in r1

        r2 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
        assert HTTP_OK in r2
        assert 'Content-Type' not in r2.json['headers']
        assert 'If-Unmodified-Since' not in r2.json['headers']
开发者ID:alfred82santa,项目名称:httpie,代码行数:11,代码来源:test_sessions.py


示例4: test_session_unicode

    def test_session_unicode(self):
        UNICODE = u'太陽'
        r1 = http('--session=test', '--auth', u'test:' + UNICODE,
                  'GET', httpbin('/get'),
                  u'Test:%s' % UNICODE,
                  env=self.env())
        assert HTTP_OK in r1

        r2 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
        assert HTTP_OK in r2
        assert (r2.json['headers']['Authorization']
                == HTTPBasicAuth.make_header(u'test', UNICODE))
        assert r2.json['headers']['Test'] == UNICODE
开发者ID:lawrenceakka,项目名称:httpie,代码行数:13,代码来源:test_sessions.py


示例5: test_credentials_in_url

 def test_credentials_in_url(self):
     url = httpbin('/basic-auth/user/password')
     url = 'http://user:[email protected]' + url.split('http://', 1)[1]
     r = http('GET', url)
     assert HTTP_OK in r
     assert '"authenticated": true' in r
     assert '"user": "user"' in r
开发者ID:lawrenceakka,项目名称:httpie,代码行数:7,代码来源:test_auth.py


示例6: test_POST_explicit_JSON_auto_JSON_accept

 def test_POST_explicit_JSON_auto_JSON_accept(self):
     r = http('--json', 'POST', httpbin('/post'))
     assert HTTP_OK in r
     assert r.json['headers']['Accept'] == 'application/json'
     # Make sure Content-Type gets set even with no data.
     # https://github.com/jkbr/httpie/issues/137
     assert 'application/json' in r.json['headers']['Content-Type']
开发者ID:lawrenceakka,项目名称:httpie,代码行数:7,代码来源:test_defaults.py


示例7: test_GET_explicit_JSON_explicit_headers

 def test_GET_explicit_JSON_explicit_headers(self):
     r = http('--json', 'GET', httpbin('/headers'),
              'Accept:application/xml',
              'Content-Type:application/xml')
     assert HTTP_OK in r
     assert '"Accept": "application/xml"' in r
     assert '"Content-Type": "application/xml"' in r
开发者ID:lawrenceakka,项目名称:httpie,代码行数:7,代码来源:test_defaults.py


示例8: test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected

 def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(self):
     env = TestEnvironment(stdout_isatty=False)
     r = http('--check-status', '--headers', 'GET', httpbin('/status/301'),
              env=env, error_exit_ok=True)
     assert 'HTTP/1.1 301' in r
     assert r.exit_status == ExitStatus.ERROR_HTTP_3XX
     assert '301 moved permanently' in r.stderr.lower()
开发者ID:lawrenceakka,项目名称:httpie,代码行数:7,代码来源:test_exit_status.py


示例9: test_format_option

 def test_format_option(self):
     env = TestEnvironment(colors=256)
     r = http('--print=B', '--pretty=format', 'GET', httpbin('/get'), 'a=b',
              env=env)
     # Tests that the JSON data is formatted.
     assert r.strip().count('\n') == 2
     assert COLOR not in r
开发者ID:alfred82santa,项目名称:httpie,代码行数:7,代码来源:test_output.py


示例10: test_session_created_and_reused

 def test_session_created_and_reused(self):
     # Verify that the session created in setup_method() has been used.
     r2 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
     assert HTTP_OK in r2
     assert r2.json['headers']['Hello'] == 'World'
     assert r2.json['headers']['Cookie'] == 'hello=world'
     assert 'Basic ' in r2.json['headers']['Authorization']
开发者ID:alfred82santa,项目名称:httpie,代码行数:7,代码来源:test_sessions.py


示例11: test_4xx_check_status_exits_4

 def test_4xx_check_status_exits_4(self):
     r = http('--check-status', 'GET', httpbin('/status/401'),
              error_exit_ok=True)
     assert 'HTTP/1.1 401' in r
     assert r.exit_status == ExitStatus.ERROR_HTTP_4XX
     # Also stderr should be empty since stdout isn't redirected.
     assert not r.stderr
开发者ID:lawrenceakka,项目名称:httpie,代码行数:7,代码来源:test_exit_status.py


示例12: test_query_string_params_in_url

 def test_query_string_params_in_url(self):
     r = http('--print=Hhb', 'GET', httpbin('/get?a=1&b=2'))
     path = '/get?a=1&b=2'
     url = httpbin(path)
     assert HTTP_OK in r
     assert 'GET %s HTTP/1.1' % path in r
     assert '"url": "%s"' % url in r
开发者ID:alfred82santa,项目名称:httpie,代码行数:7,代码来源:test_cli.py


示例13: test_ignore_stdin

 def test_ignore_stdin(self):
     with open(FILE_PATH) as f:
         env = TestEnvironment(stdin=f, stdin_isatty=False)
         r = http('--ignore-stdin', '--verbose', httpbin('/get'), env=env)
     assert HTTP_OK in r
     assert 'GET /get HTTP' in r, "Don't default to POST."
     assert FILE_CONTENT not in r, "Don't send stdin data."
开发者ID:alfred82santa,项目名称:httpie,代码行数:7,代码来源:test_cli.py


示例14: test_output_file_pretty_not_allowed_on_windows

 def test_output_file_pretty_not_allowed_on_windows(self):
     env = TestEnvironment(is_windows=True)
     output_file = os.path.join(
         tempfile.gettempdir(), '__httpie_test_output__')
     r = http('--output', output_file,
              '--pretty=all', 'GET', httpbin('/get'), env=env)
     assert 'Only terminal output can be colorized on Windows' in r.stderr
开发者ID:alfred82santa,项目名称:httpie,代码行数:7,代码来源:test_windows.py


示例15: test_encoded_stream

 def test_encoded_stream(self):
     """Test that --stream works with non-prettified
     redirected terminal output."""
     with open(BIN_FILE_PATH, 'rb') as f:
         env = TestEnvironment(stdin=f, stdin_isatty=False)
         r = http('--pretty=none', '--stream', '--verbose', 'GET',
                  httpbin('/get'), env=env)
     assert BINARY_SUPPRESSED_NOTICE.decode() in r
开发者ID:alfred82santa,项目名称:httpie,代码行数:8,代码来源:test_stream.py


示例16: test_query_string_params_in_url_and_items_with_duplicates

 def test_query_string_params_in_url_and_items_with_duplicates(self):
     r = http('--print=Hhb', 'GET', httpbin('/get?a=1&a=1'),
              'a==1', 'a==1', 'b==2')
     path = '/get?a=1&a=1&a=1&a=1&b=2'
     url = httpbin(path)
     assert HTTP_OK in r
     assert 'GET %s HTTP/1.1' % path in r
     assert '"url": "%s"' % url in r
开发者ID:alfred82santa,项目名称:httpie,代码行数:8,代码来源:test_cli.py


示例17: test_pretty_redirected_stream

 def test_pretty_redirected_stream(self):
     """Test that --stream works with prettified redirected output."""
     with open(BIN_FILE_PATH, 'rb') as f:
         env = TestEnvironment(colors=256, stdin=f,
                               stdin_isatty=False,
                               stdout_isatty=False)
         r = http('--verbose', '--pretty=all', '--stream', 'GET',
                  httpbin('/get'), env=env)
     assert BINARY_SUPPRESSED_NOTICE.decode() in r
开发者ID:alfred82santa,项目名称:httpie,代码行数:9,代码来源:test_stream.py


示例18: test_session_update

    def test_session_update(self):
        # Get a response to a request from the original session.
        r2 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
        assert HTTP_OK in r2

        # Make a request modifying the session data.
        r3 = http('--follow', '--session=test', '--auth=username:password2',
                  'GET', httpbin('/cookies/set?hello=world2'), 'Hello:World2',
                  env=self.env())
        assert HTTP_OK in r3

        # Get a response to a request from the updated session.
        r4 = http('--session=test', 'GET', httpbin('/get'), env=self.env())
        assert HTTP_OK in r4
        assert r4.json['headers']['Hello'] == 'World2'
        assert r4.json['headers']['Cookie'] == 'hello=world2'
        assert (r2.json['headers']['Authorization'] !=
                r4.json['headers']['Authorization'])
开发者ID:alfred82santa,项目名称:httpie,代码行数:18,代码来源:test_sessions.py


示例19: test_credentials_in_url_auth_flag_has_priority

 def test_credentials_in_url_auth_flag_has_priority(self):
     """When credentials are passed in URL and via -a at the same time,
      then the ones from -a are used."""
     url = httpbin('/basic-auth/user/password')
     url = 'http://user:[email protected]' + url.split('http://', 1)[1]
     r = http('--auth=user:password', 'GET', url)
     assert HTTP_OK in r
     assert '"authenticated": true' in r
     assert '"user": "user"' in r
开发者ID:lawrenceakka,项目名称:httpie,代码行数:9,代码来源:test_auth.py


示例20: test_actual_download

 def test_actual_download(self):
     url = httpbin('/robots.txt')
     body = urlopen(url).read().decode()
     env = TestEnvironment(stdin_isatty=True, stdout_isatty=False)
     r = http('--download', url, env=env)
     assert 'Downloading' in r.stderr
     assert '[K' in r.stderr
     assert 'Done' in r.stderr
     assert body == r
开发者ID:alfred82santa,项目名称:httpie,代码行数:9,代码来源:test_downloads.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tests.httpbin函数代码示例发布时间:2022-05-27
下一篇:
Python tests.get_testdata函数代码示例发布时间: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