mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-02 17:12:18 +00:00
Feature: add export package with StreamingManifestWriter and _dumps
This commit is contained in:
committed by
Trenton Holmes
parent
3a0ca03544
commit
b9a22d12cd
@@ -0,0 +1,29 @@
|
||||
import io
|
||||
import json
|
||||
|
||||
from documents.export.sinks import StreamingManifestWriter
|
||||
from documents.export.sinks import _dumps
|
||||
|
||||
|
||||
class TestDumps:
|
||||
def test_dumps_is_indented_unicode_json(self) -> None:
|
||||
result: str = _dumps({"a": "é", "b": 1})
|
||||
assert '"é"' in result # ensure_ascii=False keeps unicode literal
|
||||
assert "\n" in result # indent=2 produces newlines
|
||||
assert json.loads(result) == {"a": "é", "b": 1}
|
||||
|
||||
|
||||
class TestStreamingManifestWriter:
|
||||
def test_writes_json_array_of_records(self) -> None:
|
||||
handle: io.StringIO = io.StringIO()
|
||||
writer: StreamingManifestWriter = StreamingManifestWriter(handle)
|
||||
writer.write_batch([{"pk": 1}, {"pk": 2}])
|
||||
writer.write_record({"pk": 3})
|
||||
writer.close()
|
||||
assert json.loads(handle.getvalue()) == [{"pk": 1}, {"pk": 2}, {"pk": 3}]
|
||||
|
||||
def test_empty_manifest_is_valid_empty_array(self) -> None:
|
||||
handle: io.StringIO = io.StringIO()
|
||||
writer: StreamingManifestWriter = StreamingManifestWriter(handle)
|
||||
writer.close()
|
||||
assert json.loads(handle.getvalue()) == []
|
||||
Reference in New Issue
Block a user