2020-07-26 20:59:15 -07:00
|
|
|
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
|
2020-08-21 13:30:02 -07:00
|
|
|
|
|
|
|
|
|
2022-01-08 13:16:34 -08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"size,expected",
|
|
|
|
|
(
|
|
|
|
|
(1, [["a"], ["b"], ["c"], ["d"]]),
|
|
|
|
|
(2, [["a", "b"], ["c", "d"]]),
|
|
|
|
|
(3, [["a", "b", "c"], ["d"]]),
|
|
|
|
|
(4, [["a", "b", "c", "d"]]),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
def test_chunks(size, expected):
|
|
|
|
|
input = ["a", "b", "c", "d"]
|
|
|
|
|
chunks = list(map(list, utils.chunks(input, size)))
|
|
|
|
|
assert chunks == expected
|
2022-03-01 16:00:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hash_record():
|
|
|
|
|
expected = "d383e7c0ba88f5ffcdd09be660de164b3847401a"
|
|
|
|
|
assert utils.hash_record({"name": "Cleo", "twitter": "CleoPaws"}) == expected
|
|
|
|
|
assert (
|
|
|
|
|
utils.hash_record(
|
|
|
|
|
{"name": "Cleo", "twitter": "CleoPaws", "age": 7}, keys=("name", "twitter")
|
|
|
|
|
)
|
|
|
|
|
== expected
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
utils.hash_record({"name": "Cleo", "twitter": "CleoPaws", "age": 7}) != expected
|
|
|
|
|
)
|