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


Python utils.http函数代码示例

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


在下文中一共展示了http函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:konoshogo,项目名称:httpie,代码行数:30,代码来源:test_sessions.py

示例2: test_session_read_only

    def test_session_read_only(self, httpbin):
        self.start_session(httpbin)
        # Get a response from the original session.
        r2 = http('--session=test', 'GET', httpbin.url + '/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.url + '/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.url + '/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.

        # Should be the same as before r3.
        assert r2.json == r4.json
开发者ID:JJCL2432,项目名称:d01-p07-cerna-vazquex,代码行数:26,代码来源:test_sessions.py

示例3: 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:konoshogo,项目名称:httpie,代码行数:8,代码来源:test_sessions.py

示例4: test_session_default_header_value_overwritten

    def test_session_default_header_value_overwritten(self):
        # https://github.com/jakubroztocil/httpie/issues/180
        r1 = http("--session=test", httpbin("/headers"), "User-Agent:custom", env=self.env())
        assert HTTP_OK in r1
        assert r1.json["headers"]["User-Agent"] == "custom"

        r2 = http("--session=test", httpbin("/headers"), env=self.env())
        assert HTTP_OK in r2
        assert r2.json["headers"]["User-Agent"] == "custom"
开发者ID:konoshogo,项目名称:httpie,代码行数:9,代码来源:test_sessions.py

示例5: 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:AmyWeiner,项目名称:httpie,代码行数:10,代码来源:test_sessions.py

示例6: test_session_default_header_value_overwritten

    def test_session_default_header_value_overwritten(self):
        # https://github.com/jakubroztocil/httpie/issues/180
        r1 = http('--session=test', httpbin('/headers'), 'User-Agent:custom',
                  env=self.env())
        assert HTTP_OK in r1
        assert r1.json['headers']['User-Agent'] == 'custom'

        r2 = http('--session=test', httpbin('/headers'), env=self.env())
        assert HTTP_OK in r2
        assert r2.json['headers']['User-Agent'] == 'custom'
开发者ID:AmyWeiner,项目名称:httpie,代码行数:10,代码来源:test_sessions.py

示例7: test_session_unicode

    def test_session_unicode(self):
        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:kkale,项目名称:httpie,代码行数:10,代码来源:test_sessions.py

示例8: test_download_in_session

 def test_download_in_session(self, httpbin):
     # https://github.com/jakubroztocil/httpie/issues/412
     self.start_session(httpbin)
     cwd = os.getcwd()
     os.chdir(gettempdir())
     try:
         http('--session=test', '--download',
              httpbin.url + '/get', env=self.env())
     finally:
         os.chdir(cwd)
开发者ID:JJCL2432,项目名称:d01-p07-cerna-vazquex,代码行数:10,代码来源:test_sessions.py

示例9: 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:AmyWeiner,项目名称:httpie,代码行数:11,代码来源:test_sessions.py

示例10: test_session_unicode

    def test_session_unicode(self):
        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:AmyWeiner,项目名称:httpie,代码行数:12,代码来源:test_sessions.py

示例11: test_session_default_header_value_overwritten

    def test_session_default_header_value_overwritten(self, httpbin):
        self.start_session(httpbin)
        # https://github.com/jkbrzt/httpie/issues/180
        r1 = http('--session=test',
                  httpbin.url + '/headers', 'User-Agent:custom',
                  env=self.env())
        assert HTTP_OK in r1
        assert r1.json['headers']['User-Agent'] == 'custom'

        r2 = http('--session=test', httpbin.url + '/headers', env=self.env())
        assert HTTP_OK in r2
        assert r2.json['headers']['User-Agent'] == 'custom'
开发者ID:08opt,项目名称:httpie,代码行数:12,代码来源:test_sessions.py

示例12: test_session_ignored_header_prefixes

    def test_session_ignored_header_prefixes(self, httpbin):
        self.start_session(httpbin)
        r1 = http('--session=test', 'GET', httpbin.url + '/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.url + '/get', env=self.env())
        assert HTTP_OK in r2
        assert no_content_type(r2.json['headers'])
        assert 'If-Unmodified-Since' not in r2.json['headers']
开发者ID:S0c5,项目名称:httpie,代码行数:12,代码来源:test_sessions.py

示例13: 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:konoshogo,项目名称:httpie,代码行数:15,代码来源:test_sessions.py

示例14: 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:Johnny2136,项目名称:httpie,代码行数:7,代码来源:test_exit_status.py

示例15: 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:Johnny2136,项目名称:httpie,代码行数:7,代码来源:test_exit_status.py


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