Пример #1
0
def test_build_correct_url(req_params):
    config = req_params['config']
    req = Request(**req_params)

    major_ver = config.version.split('.', 1)[0]
    path = '/' + req.path if len(req.path) > 0 else ''

    assert req.build_url() == urljoin(config.endpoint, major_ver + path)
Пример #2
0
def test_send_with_appropriate_method(mocker, req_params):
    req = Request(**req_params)
    methods = Request._allowed_methods
    for method in methods:
        req.method = method

        mock_reqfunc = mocker.patch.object(requests.Session,
                                           method.lower(),
                                           autospec=True)

        assert mock_reqfunc.call_count == 0
        req.send()
        mock_reqfunc.assert_called_once_with(mocker.ANY,
                                             req.build_url(),
                                             data=req._content,
                                             headers=req.headers)
Пример #3
0
async def test_asend_with_appropriate_method(mocker, req_params):
    req = Request(**req_params)
    methods = Request._allowed_methods
    for method in methods:
        req.method = method

        mock_reqfunc = mocker.patch.object(aiohttp.ClientSession,
                                           method.lower(),
                                           autospec=True)

        assert mock_reqfunc.call_count == 0
        try:
            # Ignore exceptions in `async with` statement. We're only
            # interested in request call here.
            await req.asend()
        except BackendAPIError:
            pass
        mock_reqfunc.assert_called_once_with(mocker.ANY,
                                             req.build_url(),
                                             data=req._content,
                                             headers=req.headers)