コード例 #1
0
def test_raw_body():
    r = http('--print=B',
             '--offline',
             'pie.dev',
             'AAA=BBB',
             env=MockEnvironment(stdout_isatty=False))
    assert_output_matches(r, RAW_BODY)
コード例 #2
0
def test_assert_output_matches_multiple_messages():
    assert_output_matches(
        (
            f'POST / HTTP/1.1{CRLF}'
            f'AAA:BBB{CRLF}'
            f'{CRLF}'

            f'CCC'
            f'{MESSAGE_SEPARATOR}'

            f'HTTP/1.1 200 OK{CRLF}'
            f'EEE:FFF{CRLF}'
            f'{CRLF}'

            f'GGG'
            f'{MESSAGE_SEPARATOR}'
        ), [
            Expect.REQUEST_HEADERS,
            Expect.BODY,
            Expect.SEPARATOR,
            Expect.RESPONSE_HEADERS,
            Expect.BODY,
            Expect.SEPARATOR,
        ]
    )
コード例 #3
0
def test_raw_exchange(httpbin):
    r = http('--verbose',
             httpbin + '/post',
             'a=b',
             env=MockEnvironment(stdout_isatty=False))
    assert HTTP_OK in r
    assert_output_matches(r, RAW_EXCHANGE)
コード例 #4
0
def test_assert_output_matches_response_headers():
    assert_output_matches(
        (
            f'HTTP/1.1 200 OK{CRLF}'
            f'AAA:BBB{CRLF}'
            f'{CRLF}'
        ),
        [Expect.RESPONSE_HEADERS],
    )
コード例 #5
0
def test_assert_output_matches_request_headers():
    assert_output_matches(
        (
            f'GET / HTTP/1.1{CRLF}'
            f'AAA:BBB{CRLF}'
            f'{CRLF}'
        ),
        [Expect.REQUEST_HEADERS],
    )
コード例 #6
0
def test_raw_headers_and_body():
    r = http(
        '--print=HB',
        '--offline',
        'pie.dev',
        'AAA=BBB',
        env=MockEnvironment(stdout_isatty=False),
    )
    assert_output_matches(r, RAW_REQUEST)
コード例 #7
0
def test_assert_output_matches_headers_with_body_and_separator():
    assert_output_matches(
        (
            f'HTTP/1.1 {CRLF}'
            f'AAA:BBB{CRLF}{CRLF}'
            f'CCC{MESSAGE_SEPARATOR}'
        ),
        [Expect.RESPONSE_HEADERS, Expect.BODY, Expect.SEPARATOR]
    )
コード例 #8
0
def test_assert_output_matches_headers_and_body():
    assert_output_matches(
        (
            f'HTTP/1.1{CRLF}'
            f'AAA:BBB{CRLF}'
            f'{CRLF}'
            f'CCC'
        ),
        [Expect.RESPONSE_HEADERS, Expect.BODY]
    )
コード例 #9
0
def test_redirected_headers_multipart_no_separator():
    r = http(
        '--print=HB',
        '--multipart',
        '--offline',
        'pie.dev',
        'AAA=BBB',
        env=MockEnvironment(stdout_isatty=False),
    )
    assert_output_matches(r, RAW_REQUEST)
コード例 #10
0
def test_verbose_redirected_stdout_separator(httpbin):
    """

    <https://github.com/httpie/httpie/issues/1006>
    """
    r = http(
        '-v',
        httpbin.url + '/post',
        'a=b',
        env=MockEnvironment(stdout_isatty=False),
    )
    assert '}HTTP/' not in r
    assert_output_matches(r, [
        Expect.REQUEST_HEADERS,
        Expect.BODY,
        Expect.SEPARATOR,
        Expect.RESPONSE_HEADERS,
        Expect.BODY,
    ])
コード例 #11
0
def test_assert_output_matches_multipart_body():
    output = (
        'POST / HTTP/1.1\r\n'
        'User-Agent: HTTPie/2.4.0-dev\r\n'
        'Accept-Encoding: gzip, deflate\r\n'
        'Accept: */*\r\n'
        'Connection: keep-alive\r\n'
        'Content-Type: multipart/form-data; boundary=1e22169de43e4a2e8d9e41c0a1c93cc5\r\n'
        'Content-Length: 212\r\n'
        'Host: pie.dev\r\n'
        '\r\n'
        '--1e22169de43e4a2e8d9e41c0a1c93cc5\r\n'
        'Content-Disposition: form-data; name="AAA"\r\n'
        '\r\n'
        'BBB\r\n'
        '--1e22169de43e4a2e8d9e41c0a1c93cc5\r\n'
        'Content-Disposition: form-data; name="CCC"\r\n'
        '\r\n'
        'DDD\r\n'
        '--1e22169de43e4a2e8d9e41c0a1c93cc5--\r\n'
    )
    assert_output_matches(output, [Expect.REQUEST_HEADERS, Expect.BODY])
コード例 #12
0
def test_assert_output_matches_body_and_separator():
    assert_output_matches(f'AAA{MESSAGE_SEPARATOR}', [Expect.BODY, Expect.SEPARATOR])
コード例 #13
0
def test_terminal_request_body_response_body(httpbin):
    r = http('--print=Hh', httpbin + '/get')
    assert_output_matches(r, [Expect.REQUEST_HEADERS, Expect.RESPONSE_HEADERS])
コード例 #14
0
def test_raw_request_headers_response_headers(httpbin):
    r = http('--print=Hh',
             httpbin + '/get',
             env=MockEnvironment(stdout_isatty=False))
    assert_output_matches(r, [Expect.REQUEST_HEADERS, Expect.RESPONSE_HEADERS])
コード例 #15
0
def test_raw_request_headers_response_body(httpbin):
    r = http('--print=Hb',
             httpbin + '/get',
             env=MockEnvironment(stdout_isatty=False))
    assert_output_matches(r, RAW_REQUEST)
コード例 #16
0
def test_terminal_request_headers_response_body(httpbin):
    r = http('--print=Hb', httpbin + '/get')
    assert_output_matches(r, TERMINAL_REQUEST)
コード例 #17
0
def test_terminal_headers_and_body():
    r = http('--print=HB', '--offline', 'pie.dev', 'AAA=BBB')
    assert_output_matches(r, TERMINAL_REQUEST)
コード例 #18
0
def test_redirected_headers():
    r = http('--print=H',
             '--offline',
             'pie.dev',
             env=MockEnvironment(stdout_isatty=False))
    assert_output_matches(r, [Expect.REQUEST_HEADERS])
コード例 #19
0
def test_headers():
    r = http('--print=H', '--offline', 'pie.dev')
    assert_output_matches(r, [Expect.REQUEST_HEADERS])
コード例 #20
0
def test_verbose_chunked():
    r = http('--verbose', '--chunked', HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
             'hello=world')
    assert HTTP_OK in r
    assert 'Transfer-Encoding: chunked' in r
    assert_output_matches(r, TERMINAL_EXCHANGE)
コード例 #21
0
def test_assert_output_matches_body_r():
    assert_output_matches(f'AAA\r', [Expect.BODY])
コード例 #22
0
def test_headers_multipart_body_separator():
    r = http('--print=HB', '--multipart', '--offline', 'pie.dev', 'AAA=BBB')
    assert_output_matches(r, TERMINAL_REQUEST)
コード例 #23
0
def test_terminal_exchange(httpbin):
    r = http('--verbose', httpbin + '/post', 'a=b')
    assert HTTP_OK in r
    assert_output_matches(r, TERMINAL_EXCHANGE)
コード例 #24
0
def test_assert_output_matches_multiple_separators():
    assert_output_matches(
        MESSAGE_SEPARATOR + MESSAGE_SEPARATOR + 'AAA' + MESSAGE_SEPARATOR + MESSAGE_SEPARATOR,
        [Expect.SEPARATOR, Expect.SEPARATOR, Expect.BODY, Expect.SEPARATOR, Expect.SEPARATOR]
    )
コード例 #25
0
def test_assert_output_matches_body_n_body():
    assert_output_matches(f'AAA\nBBB', [Expect.BODY])