Example #1
0
def test_quoted_variable():
    req = ra.build_request([
        'set name "Sherlock Holmes"',
        'GET /get name',
    ], 1)

    assert req.params == {'name': 'Sherlock Holmes'}
Example #2
0
def test_variable_interpolation_in_params():
    req = ra.build_request([
        'set answer 42',
        'GET https://httpbin.org/get answer=num_{answer}',
    ], 1)

    assert req.params == {'answer': 'num_42'}
Example #3
0
def test_interpolation_shortcut_in_params():
    req = ra.build_request([
        'set answer 42',
        'GET https://httpbin.org/get answer',
    ], 1)

    assert req.params == {'answer': '42'}
Example #4
0
def test_heredoc_jinja2():
    req = ra.build_request([
        'set payload test',
        'POST /post <<JINJA2',
        '{"payload": "{{payload}}"}',
        'JINJA2',
    ], 1)
    assert req.data == '{"payload": "test"}'
Example #5
0
def test_json_heredoc_should_be_raw():
    req = ra.build_request([
        'set payload test',
        'POST /post <<JSON',
        '{"payload": "my val"}',
        'JSON',
    ], 1)
    assert req.data == '{"payload": "my val"}'
Example #6
0
def test_interpolation_in_headers():
    req = ra.build_request([
        'set fmt javascript',
        'Accept: application/{fmt}',
        'GET /get',
    ], 2)

    assert req.headers['accept'] == 'application/javascript'
Example #7
0
def test_host_header():
    req = ra.build_request([
        'Host: https://httpbin.org',
        'GET /get',
    ], 1)

    assert req.method == 'GET'
    assert 'host' not in req.headers
    assert req.url == 'https://httpbin.org/get'
Example #8
0
def test_variable_with_json_value():
    req = ra.build_request([
        'set payload \'{{"username": "******", "password": "******"}}\'',
        'POST /post <<END',
        '{payload}',
        'END',
    ], 1)

    assert req.data == '{"username": "******", "password": "******"}'
Example #9
0
def test_header_removal():
    req = ra.build_request([
        'Accept: application/json',
        'X-Custom-Header: nonsense',
        'Accept:',
        'GET https://httpbin.org/get',
    ], 3)

    assert 'accept' not in req.headers
Example #10
0
def test_use_url_prefix():
    req = ra.build_request([
        'use url_prefix https://httpbin.org',
        'GET /get name=Sherlock',
    ], -1)

    assert req.method == 'GET'
    assert req.url == 'https://httpbin.org/get'
    assert req.params == {'name': 'Sherlock'}
    assert req.headers == {}
Example #11
0
def test_header_collection():
    req = ra.build_request([
        'Accept: application/json',
        'X-Custom-Header: nonsense',
        'GET https://httpbin.org/get',
    ], 2)

    assert req.method == 'GET'
    assert req.headers['x-custom-header'] == 'nonsense'
    assert req.url == 'https://httpbin.org/get'
Example #12
0
def run(*, use=None):
    request = roast_api.build_request(vim.current.buffer,
                                      vim.current.range.end,
                                      use_overrides=use)
    if IS_NEOVIM:
        run_th(request, vim.current.buffer.number, vim.current.range.end)
    else:
        Thread(target=run_th,
               args=(request, vim.current.buffer.number,
                     vim.current.range.end),
               daemon=True).start()
Example #13
0
def run():
    request = roast_api.build_request(vim.current.buffer, vim.current.range.end)

    try:
        response = sessions[vim.current.buffer.number].send(request.prepare())
    except requests.ConnectionError as e:
        vim.current.buffer.vars['_roast_error'] = repr(e)
        vim.command(f"echoerr b:_roast_error")
    else:
        show_response(response)
        highlight_line_text('RoastCurrentSuccess' if response.ok else 'RoastCurrentFailure')
Example #14
0
def test_post_body_with_space_heredoc():
    req = ra.build_request([
        'POST https://httpbin.org/post << body',
        'one=1',
        'two=2',
        'body',
        'three=3',
    ], 0)

    assert req.method == 'POST'
    assert req.data == 'one=1\ntwo=2'
Example #15
0
def test_headers_in_heredoc_should_be_ignored():
    req = ra.build_request([
        'POST /post <<END',
        'x: y',
        'END',
        '',
        'GET https://httpbin.org/get name=Sherlock',
    ], -1)

    assert req.method == 'GET'
    assert req.url == 'https://httpbin.org/get'
    assert req.params == {'name': 'Sherlock'}
    assert req.headers == {}
Example #16
0
def test_rest_methods_request():
    assert ra.build_request(['PUT https://httpbin.org/put'], 0).method == 'PUT'
    assert ra.build_request(['PATCH https://httpbin.org/PATCH'],
                            0).method == 'PATCH'
    assert ra.build_request(['DELETE https://httpbin.org/DELETE'],
                            0).method == 'DELETE'
Example #17
0
def test_params_with_special():
    req = ra.build_request([
        'GET https://httpbin.org/get answer="forty two" more="one=two=three"',
    ], 0)

    assert req.params == {'answer': 'forty two', 'more': 'one=two=three'}
Example #18
0
def test_interpolation_with_other_params():
    req = ra.build_request([
        'GET https://httpbin.org/get name=stark answer=ans_by_{@name}',
    ], 0)

    assert req.params == {'name': 'stark', 'answer': 'ans_by_stark'}