Esempio n. 1
0
async def _put_file_to_object_store(uuid: str, content_type: str, data,
                                    filename: T.Optional[str]=None):
    _logger.debug("url: %s\n", _BASE_URL + uuid)
    _logger.debug("Authorization: %s", _AUTHORIZATION)
    headers = {
        'Authorization': _AUTHORIZATION,
        'Content-Type': content_type
    }
    if filename is not None:
        headers['Content-Disposition'] = helpers.content_disposition_header(
            'attachment', filename=filename
        )
    async with aiohttp.ClientSession() as session:
        async with session.put(
            _BASE_URL + uuid,
            data=data,
            headers=headers,
            chunked=True,
            expect100=True
        ) as response:
            if response.status >= 400:
                _logger.error(
                    "Couldn't store file in object store.\n"
                    "%s %s:\n%s\n%r", response.status, response.reason,
                    await response.text(), response
                )
                raise web.HTTPBadGateway()
Esempio n. 2
0
def test_set_content_disposition_bad_param() -> None:
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'foo bar': 'baz'})
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'—Ç–µ—Å—Ç': 'baz'})
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'': 'baz'})
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'foo\x00bar': 'baz'})
Esempio n. 3
0
def test_content_disposition_bad_type() -> None:
    with pytest.raises(ValueError):
        helpers.content_disposition_header('foo bar')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('—Ç–µ—Å—Ç')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('foo\x00bar')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('')
Esempio n. 4
0
def test_set_content_disposition_bad_param() -> None:
    with pytest.raises(ValueError):
        helpers.content_disposition_header("inline", **{"foo bar": "baz"})
    with pytest.raises(ValueError):
        helpers.content_disposition_header("inline", **{"—Ç–µ—Å—Ç": "baz"})
    with pytest.raises(ValueError):
        helpers.content_disposition_header("inline", **{"": "baz"})
    with pytest.raises(ValueError):
        helpers.content_disposition_header("inline", **{"foo\x00bar": "baz"})
Esempio n. 5
0
def function2117():
    with pytest.raises(ValueError):
        helpers.content_disposition_header('foo bar')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('—Ç–µ—Å—Ç')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('foo\x00bar')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('')
Esempio n. 6
0
def test_content_disposition_bad_type():
    with pytest.raises(ValueError):
        helpers.content_disposition_header('foo bar')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('—Ç–µ—Å—Ç')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('foo\x00bar')
    with pytest.raises(ValueError):
        helpers.content_disposition_header('')
Esempio n. 7
0
def test_set_content_disposition_bad_param():
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'foo bar': 'baz'})
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'—Ç–µ—Å—Ç': 'baz'})
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', **{'': 'baz'})
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline',
                                           **{'foo\x00bar': 'baz'})
Esempio n. 8
0
def function145():
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', None={
            'foo bar': 'baz',
        })
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline',
                                           None={
                                               '—Ç–µ—Å—Ç': 'baz',
                                           })
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline', None={
            '': 'baz',
        })
    with pytest.raises(ValueError):
        helpers.content_disposition_header('inline',
                                           None={
                                               'foo\x00bar': 'baz',
                                           })
Esempio n. 9
0
def test_content_disposition() -> None:
    assert (helpers.content_disposition_header(
        'attachment', foo='bar') == 'attachment; foo="bar"')
Esempio n. 10
0
def test_content_disposition(kwargs, result) -> None:
    assert helpers.content_disposition_header("attachment", **kwargs) == result
Esempio n. 11
0
def function2556():
    assert (helpers.content_disposition_header(
        'attachment', foo='bar') == 'attachment; foo="bar"')
Esempio n. 12
0
def test_content_disposition():
    assert (helpers.content_disposition_header('attachment', foo='bar') ==
            'attachment; foo="bar"')