Esempio n. 1
0
async def test_json_parser(mocker):
    headers = HttpHeaders()
    _add_header(headers, 'Content-Type', 'application/json')

    # python<=3.7 compatible mock
    async def mocked(*args, **kwargs):
        mock = mocker.MagicMock()
        mock(*args, **kwargs)
        return mock

    mocker.patch('aiosonic.HTTPClient.request', new=mocked)
    instance = HTTPClient()

    res = await instance.post('foo', json=[])
    res.assert_called_once_with(instance,
                                'foo',
                                'POST',
                                headers,
                                None,
                                '[]',
                                False,
                                verify=True,
                                ssl=None,
                                follow=False,
                                timeouts=None,
                                http2=False)
Esempio n. 2
0
def test_add_header_list_replace():
    """Test add header method into list with replace True."""
    headers = []
    _add_header(headers, 'foo', 'bar')
    _add_header(headers, 'foo', 'baz', True)
    assert headers == [('foo', 'baz')]
Esempio n. 3
0
def test_add_header_list():
    """Test add header method into list."""
    headers = []
    _add_header(headers, 'content-type', 'application/json')
    assert headers == [('content-type', 'application/json')]
Esempio n. 4
0
def test_add_header():
    """Test add header method."""
    headers = HttpHeaders()
    _add_header(headers, 'content-type', 'application/json')
    assert headers == {'content-type': 'application/json'}