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_headers_retrival():
    """Test reading header with more than one ":" char ocurrence."""
    sample_header = b'Report-To: { "group": "wm_nel", "max_age": 86400, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }\r\n'
    assert len(HttpHeaders._clear_line(sample_header)) == 2
Esempio n. 3
0
def test_add_header():
    """Test add header method."""
    headers = HttpHeaders()
    _add_header(headers, 'content-type', 'application/json')
    assert headers == {'content-type': 'application/json'}
Esempio n. 4
0
def test_headers_parsing():
    """Test parsing header with no value."""
    parsing = HttpResponse()
    parsing._set_header(*HttpHeaders._clear_line(b'Expires: \r\n'))
    assert parsing.raw_headers == [('Expires', '')]
Esempio n. 5
0
def test_headers_retrival_common():
    """Test reading header with more than one ":" char ocurrence."""
    res = ['Authorization', 'Bearer foobar']
    sample_header = b': '.join([item.encode() for item in res]) + b'\r\n'
    assert HttpHeaders._clear_line(sample_header) == res