|
1 | | -""" |
2 | | -Tests for :func:`opencontractserver.tasks.export_tasks.package_annotated_docs`. |
3 | | -
|
4 | | -Regression coverage for issue #1356: |
5 | | -
|
6 | | -``build_document_export()`` returns ``("", "", None, {}, {})`` for documents |
7 | | -whose export failed (e.g. underlying file could not be loaded or all |
8 | | -annotations were filtered out). Prior to the fix, ``package_annotated_docs`` |
9 | | -iterated those placeholder tuples without any guard, silently writing an |
10 | | -empty-named file to the zip and inserting ``annotated_docs[""] = None`` into |
11 | | -the final ``data.json``. The fix adds an explicit skip for failed |
12 | | -placeholders. These tests verify that behavior. |
13 | | -""" |
| 1 | +"""Regression tests for ``package_annotated_docs`` skipping failed placeholders.""" |
14 | 2 |
|
15 | 3 | from __future__ import annotations |
16 | 4 |
|
@@ -105,13 +93,20 @@ def test_skips_failed_placeholder_and_packages_successful_docs(self) -> None: |
105 | 93 | with patch( |
106 | 94 | "opencontractserver.tasks.export_tasks.finalize_export", |
107 | 95 | side_effect=capture_fn, |
108 | | - ): |
| 96 | + ), self.assertLogs( |
| 97 | + "opencontractserver.tasks.export_tasks", level="WARNING" |
| 98 | + ) as log_cm: |
109 | 99 | package_annotated_docs( |
110 | 100 | burned_docs=(good_doc, failed_doc), |
111 | 101 | export_id=self.export.id, |
112 | 102 | corpus_pk=self.corpus.id, |
113 | 103 | ) |
114 | 104 |
|
| 105 | + self.assertTrue( |
| 106 | + any("Skipping failed burned doc" in line for line in log_cm.output), |
| 107 | + f"Expected skip-warning log, got: {log_cm.output}", |
| 108 | + ) |
| 109 | + self.assertIn("bytes", captured, "finalize_export was not called") |
115 | 110 | zf = zipfile.ZipFile(io.BytesIO(captured["bytes"])) |
116 | 111 | names = set(zf.namelist()) |
117 | 112 |
|
@@ -148,6 +143,7 @@ def test_all_failed_produces_empty_annotated_docs_without_crashing(self) -> None |
148 | 143 | corpus_pk=self.corpus.id, |
149 | 144 | ) |
150 | 145 |
|
| 146 | + self.assertIn("bytes", captured, "finalize_export was not called") |
151 | 147 | zf = zipfile.ZipFile(io.BytesIO(captured["bytes"])) |
152 | 148 | # Only data.json, no empty-filename entry. |
153 | 149 | self.assertEqual(set(zf.namelist()), {"data.json"}) |
|
0 commit comments