mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-11 02:54:23 +02:00
Ability to insert base64 binary data as JSON, closes #126
This commit is contained in:
parent
814d4a7f90
commit
1a61a6d3d6
5 changed files with 67 additions and 3 deletions
|
|
@ -554,6 +554,18 @@ def test_insert_not_null_default(db_path, tmpdir):
|
|||
) == db["dogs"].schema
|
||||
|
||||
|
||||
def test_insert_binary_base64(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["insert", db_path, "files", "-"],
|
||||
input=r'{"content": {"$base64": true, "encoded": "aGVsbG8="}}',
|
||||
)
|
||||
assert 0 == result.exit_code, result.output
|
||||
db = Database(db_path)
|
||||
actual = db.execute_returning_dicts("select content from files")
|
||||
assert actual == [{"content": b"hello"}]
|
||||
|
||||
|
||||
def test_insert_newline_delimited(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
|
|
|
|||
22
tests/test_utils.py
Normal file
22
tests/test_utils.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from sqlite_utils import utils
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"input,expected,should_be_is",
|
||||
[
|
||||
({}, None, True),
|
||||
({"foo": "bar"}, None, True),
|
||||
(
|
||||
{"content": {"$base64": True, "encoded": "aGVsbG8="}},
|
||||
{"content": b"hello"},
|
||||
False,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_decode_base64_values(input, expected, should_be_is):
|
||||
actual = utils.decode_base64_values(input)
|
||||
if should_be_is:
|
||||
assert actual is input
|
||||
else:
|
||||
assert actual == expected
|
||||
Loading…
Add table
Add a link
Reference in a new issue