Page MenuHomeSoftware Heritage
Paste P708

non bytes extra_headers
ActivePublic

Authored by olasd on Jul 1 2020, 5:12 PM.
```
lang=python
@pytest.mark.parametrize(
"value", [pytest.param("foo", id="str"), pytest.param(1, id="int")]
)
def test_revision_add_non_bytes_headers(self, swh_storage, value):
extra_headers = [["foo", b"baz"], ["foo", value]]
swh_storage.revision_add(
[{**data.revision, "metadata": {"extra_headers": extra_headers}}]
)
(r,) = swh_storage.revision_get([data.revision["id"]])
assert r["metadata"]["extra_headers"] == extra_headers
```
output:
```
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_api_client.py::TestStorage::test_revision_add_non_bytes_headers[str] PASSED [ 12%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_api_client.py::TestStorage::test_revision_add_non_bytes_headers[int] PASSED [ 25%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_cassandra.py::TestCassandraStorage::test_revision_add_non_bytes_headers[str] FAILED [ 37%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_cassandra.py::TestCassandraStorage::test_revision_add_non_bytes_headers[int] FAILED [ 50%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_in_memory.py::TestStorage::test_revision_add_non_bytes_headers[str] PASSED [ 62%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_in_memory.py::TestStorage::test_revision_add_non_bytes_headers[int] PASSED [ 75%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py::TestStorage::test_revision_add_non_bytes_headers[str] FAILED [ 87%]
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py::TestStorage::test_revision_add_non_bytes_headers[int] FAILED [100%]
=================================================================================================================================== FAILURES ===================================================================================================================================
________________________________________________________________________________________________________ TestCassandraStorage.test_revision_add_non_bytes_headers[str] _________________________________________________________________________________________________________
self = <swh.storage.tests.test_cassandra.TestCassandraStorage object at 0x7f1757f0ac50>, swh_storage = <swh.storage.validate.ValidatingProxyStorage object at 0x7f175415d0d0>, value = 'foo'
@pytest.mark.parametrize(
"value", [pytest.param("foo", id="str"), pytest.param(1, id="int")]
)
def test_revision_add_non_bytes_headers(self, swh_storage, value):
extra_headers = [["foo", b"baz"], ["foo", value]]
swh_storage.revision_add(
> [{**data.revision, "metadata": {"extra_headers": extra_headers}}]
)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add
[dict_converter(Revision, r) for r in revisions]
.tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/storage.py:431: in revision_add
revobject = revision_to_db(revision)
.tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/converters.py:38: in revision_to_db
metadata["extra_headers"]
.tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db
ret.append([key, decode_with_escape(values)])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = 'foo'
def decode_with_escape(value):
"""Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences
as \\x<hex value>. We also escape NUL bytes as they are invalid in JSON
strings.
"""
# escape backslashes
> value = value.replace(b"\\", b"\\\\")
E TypeError: replace() argument 1 must be str, not bytes
.tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: TypeError
------------------------------------------------------------------------------------------------------------------------------ Captured log setup ------------------------------------------------------------------------------------------------------------------------------
WARNING cassandra.cluster:cql.py:67 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
WARNING cassandra.cluster:cql.py:67 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
---------------------------------------------------------------------------------------------------------------------------- Captured log teardown -----------------------------------------------------------------------------------------------------------------------------
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
________________________________________________________________________________________________________ TestCassandraStorage.test_revision_add_non_bytes_headers[int] _________________________________________________________________________________________________________
self = <swh.storage.tests.test_cassandra.TestCassandraStorage object at 0x7f17547840d0>, swh_storage = <swh.storage.validate.ValidatingProxyStorage object at 0x7f1754ad5150>, value = 1
@pytest.mark.parametrize(
"value", [pytest.param("foo", id="str"), pytest.param(1, id="int")]
)
def test_revision_add_non_bytes_headers(self, swh_storage, value):
extra_headers = [["foo", b"baz"], ["foo", value]]
swh_storage.revision_add(
> [{**data.revision, "metadata": {"extra_headers": extra_headers}}]
)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add
[dict_converter(Revision, r) for r in revisions]
.tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/storage.py:431: in revision_add
revobject = revision_to_db(revision)
.tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/converters.py:38: in revision_to_db
metadata["extra_headers"]
.tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db
ret.append([key, decode_with_escape(values)])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = 1
def decode_with_escape(value):
"""Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences
as \\x<hex value>. We also escape NUL bytes as they are invalid in JSON
strings.
"""
# escape backslashes
> value = value.replace(b"\\", b"\\\\")
E AttributeError: 'int' object has no attribute 'replace'
.tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: AttributeError
------------------------------------------------------------------------------------------------------------------------------ Captured log setup ------------------------------------------------------------------------------------------------------------------------------
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
---------------------------------------------------------------------------------------------------------------------------- Captured log teardown -----------------------------------------------------------------------------------------------------------------------------
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version
_____________________________________________________________________________________________________________ TestStorage.test_revision_add_non_bytes_headers[str] _____________________________________________________________________________________________________________
self = <swh.storage.tests.test_storage.TestStorage object at 0x7f17549d9590>, swh_storage = <swh.storage.validate.ValidatingProxyStorage object at 0x7f175418ec90>, value = 'foo'
@pytest.mark.parametrize(
"value", [pytest.param("foo", id="str"), pytest.param(1, id="int")]
)
def test_revision_add_non_bytes_headers(self, swh_storage, value):
extra_headers = [["foo", b"baz"], ["foo", value]]
swh_storage.revision_add(
> [{**data.revision, "metadata": {"extra_headers": extra_headers}}]
)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add
[dict_converter(Revision, r) for r in revisions]
.tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:24: in d
return f(*a, **kw)
.tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:77: in d
r = f(*a, **kw)
.tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:62: in _meth
return meth(self, *args, db=db, cur=cur, **kwargs)
.tox/py3/lib/python3.7/site-packages/swh/storage/storage.py:564: in revision_add
revisions_filtered = list(map(converters.revision_to_db, revisions_filtered))
.tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:175: in revision_to_db
extra_headers = git_headers_to_db(metadata["extra_headers"])
.tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db
ret.append([key, decode_with_escape(values)])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = 'foo'
def decode_with_escape(value):
"""Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences
as \\x<hex value>. We also escape NUL bytes as they are invalid in JSON
strings.
"""
# escape backslashes
> value = value.replace(b"\\", b"\\\\")
E TypeError: replace() argument 1 must be str, not bytes
.tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: TypeError
_____________________________________________________________________________________________________________ TestStorage.test_revision_add_non_bytes_headers[int] _____________________________________________________________________________________________________________
self = <swh.storage.tests.test_storage.TestStorage object at 0x7f17547732d0>, swh_storage = <swh.storage.validate.ValidatingProxyStorage object at 0x7f17542cd810>, value = 1
@pytest.mark.parametrize(
"value", [pytest.param("foo", id="str"), pytest.param(1, id="int")]
)
def test_revision_add_non_bytes_headers(self, swh_storage, value):
extra_headers = [["foo", b"baz"], ["foo", value]]
swh_storage.revision_add(
> [{**data.revision, "metadata": {"extra_headers": extra_headers}}]
)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add
[dict_converter(Revision, r) for r in revisions]
.tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:24: in d
return f(*a, **kw)
.tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:77: in d
r = f(*a, **kw)
.tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:62: in _meth
return meth(self, *args, db=db, cur=cur, **kwargs)
.tox/py3/lib/python3.7/site-packages/swh/storage/storage.py:564: in revision_add
revisions_filtered = list(map(converters.revision_to_db, revisions_filtered))
.tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:175: in revision_to_db
extra_headers = git_headers_to_db(metadata["extra_headers"])
.tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db
ret.append([key, decode_with_escape(values)])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = 1
def decode_with_escape(value):
"""Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences
as \\x<hex value>. We also escape NUL bytes as they are invalid in JSON
strings.
"""
# escape backslashes
> value = value.replace(b"\\", b"\\\\")
E AttributeError: 'int' object has no attribute 'replace'
.tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: AttributeError
```

Event Timeline

olasd updated the paste's language from autodetect to remarkup.
olasd edited the content of this paste. (Show Details)