Exemplo n.º 1
0
 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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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"
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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'
Exemplo n.º 11
0
    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'
Exemplo n.º 12
0
    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']
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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'
Exemplo n.º 15
0
    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']
Exemplo n.º 16
0
    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'
Exemplo n.º 17
0
    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"]
Exemplo n.º 18
0
 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."
Exemplo n.º 19
0
 def test_ignore_stdin_cannot_prompt_password(self):
     r = http('--ignore-stdin',
              '--auth=no-password',
              httpbin('/get'),
              error_exit_ok=True)
     assert r.exit_status == ExitStatus.ERROR
     assert 'because --ignore-stdin' in r.stderr
Exemplo n.º 20
0
 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."
Exemplo n.º 21
0
 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
Exemplo n.º 22
0
 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"]
Exemplo n.º 23
0
    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
Exemplo n.º 24
0
 def test_binary_stdin(self):
     with open(BIN_FILE_PATH, 'rb') as stdin:
         env = TestEnvironment(stdin=stdin,
                               stdin_isatty=False,
                               stdout_isatty=False)
         r = http('--print=B', 'POST', httpbin('/post'), env=env)
         assert r == BIN_FILE_CONTENT
Exemplo n.º 25
0
 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', auth='user:wrong')
     r = http('--auth=user:password', 'GET', url)
     assert HTTP_OK in r
     assert r.json == {'authenticated': True, 'user': '******'}
Exemplo n.º 26
0
 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']
Exemplo n.º 27
0
 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
Exemplo n.º 28
0
 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', auth='user:wrong')
     r = http('--auth=user:password', 'GET', url)
     assert HTTP_OK in r
     assert r.json == {'authenticated': True, 'user': '******'}
Exemplo n.º 29
0
 def test_5xx_check_status_exits_5(self):
     r = http('--check-status',
              'GET',
              httpbin('/status/500'),
              error_exit_ok=True)
     assert 'HTTP/1.1 500' in r
     assert r.exit_status == ExitStatus.ERROR_HTTP_5XX
Exemplo n.º 30
0
 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()
Exemplo n.º 31
0
 def test_timeout_exit_status(self):
     r = http('--timeout=0.5',
              'GET',
              httpbin('/delay/1'),
              error_exit_ok=True)
     assert HTTP_OK in r
     assert r.exit_status == ExitStatus.ERROR_TIMEOUT
Exemplo n.º 32
0
 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()
Exemplo n.º 33
0
 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
Exemplo n.º 34
0
 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']
Exemplo n.º 35
0
 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
Exemplo n.º 36
0
 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']
Exemplo n.º 37
0
 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
Exemplo n.º 38
0
 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
Exemplo n.º 39
0
 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']
Exemplo n.º 40
0
 def test_download_interrupted(self):
     devnull = open(os.devnull, 'w')
     download = Download(output_file=devnull, progress_file=devnull)
     download.start(
         Response(url=httpbin('/'), headers={'Content-Length': 5}))
     download.chunk_downloaded(b'1234')
     download.finish()
     assert download.interrupted
Exemplo n.º 41
0
 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
Exemplo n.º 42
0
 def test_download_no_Content_Length(self):
     devnull = open(os.devnull, 'w')
     download = Download(output_file=devnull, progress_file=devnull)
     download.start(Response(url=httpbin('/')))
     time.sleep(1.1)
     download.chunk_downloaded(b'12345')
     download.finish()
     assert not download.interrupted
Exemplo n.º 43
0
 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, error_exit_ok=True)
     assert 'Only terminal output can be colorized on Windows' in r.stderr
Exemplo n.º 44
0
 def test_request_body_from_file_by_path_no_field_name_allowed(self):
     env = TestEnvironment(stdin_isatty=True)
     r = http('POST',
              httpbin('/post'),
              'field-name@' + FILE_PATH_ARG,
              env=env,
              error_exit_ok=True)
     assert 'perhaps you meant --form?' in r.stderr
Exemplo n.º 45
0
    def test_subtype_based_pygments_lexer_match(self):
        """Test that media subtype is used if type/subtype doesn't
        match any lexer.

        """
        env = TestEnvironment(colors=256)
        r = http('--print=B', '--pretty=all', httpbin('/post'),
                 'Content-Type:text/foo+json', 'a=b', env=env)
        assert COLOR in r
Exemplo n.º 46
0
 def test_upload_ok(self):
     r = http('--form', '--verbose', 'POST', httpbin('/post'),
              'test-file@%s' % FILE_PATH_ARG, 'foo=bar')
     assert HTTP_OK in r
     assert 'Content-Disposition: form-data; name="foo"' in r
     assert 'Content-Disposition: form-data; name="test-file";' \
            ' filename="%s"' % os.path.basename(FILE_PATH) in r
     assert r.count(FILE_CONTENT) == 2
     assert '"foo": "bar"' in r
Exemplo n.º 47
0
    def test_subtype_based_pygments_lexer_match(self):
        """Test that media subtype is used if type/subtype doesn't
        match any lexer.

        """
        env = TestEnvironment(colors=256)
        r = http('--print=B', '--pretty=all', httpbin('/post'),
                 'Content-Type:text/foo+json', 'a=b', env=env)
        assert COLOR in r
Exemplo n.º 48
0
 def test_binary_file_form(self):
     env = TestEnvironment(stdin_isatty=True, stdout_isatty=False)
     r = http('--print=B',
              '--form',
              'POST',
              httpbin('/post'),
              'test@' + BIN_FILE_PATH_ARG,
              env=env)
     assert bytes(BIN_FILE_CONTENT) in bytes(r)
Exemplo n.º 49
0
 def test_3xx_check_status_redirects_allowed_exits_0(self):
     r = http('--check-status',
              '--follow',
              'GET',
              httpbin('/status/301'),
              error_exit_ok=True)
     # The redirect will be followed so 200 is expected.
     assert 'HTTP/1.1 200 OK' in r
     assert r.exit_status == ExitStatus.OK
Exemplo n.º 50
0
 def test_upload_ok(self):
     r = http('--form', '--verbose', 'POST', httpbin('/post'),
              'test-file@%s' % FILE_PATH_ARG, 'foo=bar')
     assert HTTP_OK in r
     assert 'Content-Disposition: form-data; name="foo"' in r
     assert 'Content-Disposition: form-data; name="test-file";' \
            ' filename="%s"' % os.path.basename(FILE_PATH) in r
     assert r.count(FILE_CONTENT) == 2
     assert '"foo": "bar"' in r
Exemplo n.º 51
0
 def test_request_body_from_file_by_path_no_data_items_allowed(self):
     env = TestEnvironment(stdin_isatty=False)
     r = http('POST',
              httpbin('/post'),
              '@' + FILE_PATH_ARG,
              'foo=bar',
              env=env,
              error_exit_ok=True)
     assert 'cannot be mixed' in r.stderr
Exemplo n.º 52
0
 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
Exemplo n.º 53
0
 def test_binary_stdin(self):
     with open(BIN_FILE_PATH, 'rb') as stdin:
         env = TestEnvironment(
             stdin=stdin,
             stdin_isatty=False,
             stdout_isatty=False
         )
         r = http('--print=B', 'POST', httpbin('/post'), env=env)
         assert r == BIN_FILE_CONTENT
Exemplo n.º 54
0
 def test_force_pretty(self):
     env = TestEnvironment(stdout_isatty=False, colors=256)
     r = http(
         '--pretty=all',
         'GET',
         httpbin('/get'),
         env=env,
     )
     assert COLOR in r
Exemplo n.º 55
0
    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'])
Exemplo n.º 56
0
 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
Exemplo n.º 57
0
 def test_redirected_stream(self):
     """Test that --stream works with non-prettified
     redirected terminal output."""
     with open(BIN_FILE_PATH, 'rb') as f:
         env = TestEnvironment(stdout_isatty=False,
                               stdin_isatty=False,
                               stdin=f)
         r = http('--pretty=none', '--stream', '--verbose', 'GET',
                  httpbin('/get'), env=env)
     assert BIN_FILE_CONTENT in r
Exemplo n.º 58
0
 def test_binary_file_path(self):
     env = TestEnvironment(stdin_isatty=True, stdout_isatty=False)
     r = http(
         '--print=B',
         'POST',
         httpbin('/post'),
         '@' + BIN_FILE_PATH_ARG,
         env=env,
     )
     assert r == BIN_FILE_CONTENT
Exemplo n.º 59
0
    def setup_method(self, method):
        """
        Start a full-blown session with a custom request header,
        authorization, and response cookies.

        """
        super(TestSessionFlow, self).setup_method(method)
        r1 = http('--follow', '--session=test', '--auth=username:password',
                  'GET', httpbin('/cookies/set?hello=world'), 'Hello:World',
                  env=self.env())
        assert HTTP_OK in r1
Exemplo n.º 60
0
    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"]