Spaces:
Running
Running
solidprivacy-nl commited on
Commit ·
292d34e
1
Parent(s): 83f7ebb
Update two-mode tests for DOCX reinsert UI
Browse files- tests/test_two_mode_ui_patch.py +17 -13
tests/test_two_mode_ui_patch.py
CHANGED
|
@@ -15,6 +15,7 @@ def _generated_two_mode_source_snippet() -> str:
|
|
| 15 |
scrub_key_import_ui_block = _extract_triple_quoted_assignment("scrub_key_import_ui_block")
|
| 16 |
reinsert_ui_block = _extract_triple_quoted_assignment("reinsert_ui_block")
|
| 17 |
txt_reinsert_ui_block = _extract_triple_quoted_assignment("txt_reinsert_ui_block")
|
|
|
|
| 18 |
anonymization_flow = " with st.expander(\"Over deze app\", expanded=False):\n st.write(\"anonimiseren\")\n"
|
| 19 |
return (
|
| 20 |
"st.markdown(\"**Kies werkmodus**\")\n"
|
|
@@ -30,6 +31,7 @@ def _generated_two_mode_source_snippet() -> str:
|
|
| 30 |
+ scrub_key_import_ui_block
|
| 31 |
+ reinsert_ui_block
|
| 32 |
+ txt_reinsert_ui_block
|
|
|
|
| 33 |
+ "else:\n"
|
| 34 |
+ anonymization_flow
|
| 35 |
)
|
|
@@ -50,7 +52,6 @@ def test_two_mode_patch_uses_conditional_work_mode_rendering():
|
|
| 50 |
|
| 51 |
|
| 52 |
def test_generated_two_mode_source_compiles_without_indentation_or_syntax_error():
|
| 53 |
-
# Guards runtime failures in the generated mode branch.
|
| 54 |
compile(_generated_two_mode_source_snippet(), "generated_two_mode_source.py", "exec")
|
| 55 |
|
| 56 |
|
|
@@ -58,17 +59,20 @@ def test_reinsert_blocks_start_at_single_branch_indent():
|
|
| 58 |
scrub_key_import_ui_block = _extract_triple_quoted_assignment("scrub_key_import_ui_block")
|
| 59 |
reinsert_ui_block = _extract_triple_quoted_assignment("reinsert_ui_block")
|
| 60 |
txt_reinsert_ui_block = _extract_triple_quoted_assignment("txt_reinsert_ui_block")
|
|
|
|
| 61 |
assert scrub_key_import_ui_block.startswith(' st.markdown("**Scrub Key laden**")')
|
| 62 |
assert reinsert_ui_block.startswith(' st.markdown("**Originele waarden terugzetten**")')
|
| 63 |
assert txt_reinsert_ui_block.startswith(' st.markdown("**TXT-bestand terugzetten**")')
|
|
|
|
| 64 |
assert not scrub_key_import_ui_block.startswith(' st.markdown("**Scrub Key laden**")')
|
| 65 |
assert not reinsert_ui_block.startswith(' st.markdown("**Originele waarden terugzetten**")')
|
| 66 |
assert not txt_reinsert_ui_block.startswith(' st.markdown("**TXT-bestand terugzetten**")')
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
-
def
|
| 70 |
mode_index = PATCH_TEXT.index('if solidprivacy_work_mode == "Originele waarden terugzetten":')
|
| 71 |
-
import_index = PATCH_TEXT.index("scrub_key_import_ui_block + reinsert_ui_block + txt_reinsert_ui_block")
|
| 72 |
assert mode_index < import_index
|
| 73 |
assert "Scrub Key laden" in PATCH_TEXT
|
| 74 |
assert "Upload Scrub Key JSON (.json)" in PATCH_TEXT
|
|
@@ -84,6 +88,12 @@ def test_reinsert_mode_gets_own_scrub_key_reinsert_and_txt_content():
|
|
| 84 |
assert "Zet TXT-bestand lokaal terug" in PATCH_TEXT
|
| 85 |
assert "Herstelde TXT-tekst" in PATCH_TEXT
|
| 86 |
assert "Download hersteld TXT-bestand (.txt)" in PATCH_TEXT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
def test_anonymization_flow_is_under_else_branch():
|
|
@@ -108,8 +118,10 @@ def test_reinsert_flow_is_not_embedded_in_anonymization_review_summary_block():
|
|
| 108 |
assert "scrub_key_import_ui_block" not in review_summary_block
|
| 109 |
assert "reinsert_ui_block" not in review_summary_block
|
| 110 |
assert "txt_reinsert_ui_block" not in review_summary_block
|
|
|
|
| 111 |
assert "Download herstelde tekst (.txt)" not in review_summary_block
|
| 112 |
assert "Download hersteld TXT-bestand (.txt)" not in review_summary_block
|
|
|
|
| 113 |
|
| 114 |
|
| 115 |
def test_existing_scrub_key_export_and_import_labels_remain_present():
|
|
@@ -130,7 +142,6 @@ def test_existing_anonymization_and_download_markers_remain_present():
|
|
| 130 |
|
| 131 |
|
| 132 |
def test_scrubbed_download_behavior_markers_are_not_removed_or_rewired():
|
| 133 |
-
# The startup patch must not patch existing scrubbed download widgets directly.
|
| 134 |
assert "download_txt" not in PATCH_TEXT
|
| 135 |
assert "download_csv" not in PATCH_TEXT
|
| 136 |
assert "download_docx" not in PATCH_TEXT
|
|
@@ -140,14 +151,8 @@ def test_scrubbed_download_behavior_markers_are_not_removed_or_rewired():
|
|
| 140 |
assert "export_text = apply_replacements_to_text" not in PATCH_TEXT
|
| 141 |
|
| 142 |
|
| 143 |
-
def
|
| 144 |
forbidden_markers = [
|
| 145 |
-
"reinsert_docx_bytes",
|
| 146 |
-
"Upload DOCX",
|
| 147 |
-
"Upload .docx",
|
| 148 |
-
"hersteld DOCX",
|
| 149 |
-
"Download hersteld DOCX",
|
| 150 |
-
"download_docx_reinserted",
|
| 151 |
"download_pdf_reinserted",
|
| 152 |
"PDF reinsert",
|
| 153 |
"pdf reinsert",
|
|
@@ -156,13 +161,12 @@ def test_two_mode_patch_does_not_add_docx_or_pdf_reinsert_upload_ui():
|
|
| 156 |
assert marker not in PATCH_TEXT
|
| 157 |
|
| 158 |
|
| 159 |
-
def
|
| 160 |
lower_patch = PATCH_TEXT.lower()
|
| 161 |
for marker in [
|
| 162 |
"requests.post",
|
| 163 |
"httpx.post",
|
| 164 |
"cloud processing call",
|
| 165 |
-
"rehydrat",
|
| 166 |
"restore_original_document",
|
| 167 |
"server-side key storage",
|
| 168 |
"durable key vault",
|
|
|
|
| 15 |
scrub_key_import_ui_block = _extract_triple_quoted_assignment("scrub_key_import_ui_block")
|
| 16 |
reinsert_ui_block = _extract_triple_quoted_assignment("reinsert_ui_block")
|
| 17 |
txt_reinsert_ui_block = _extract_triple_quoted_assignment("txt_reinsert_ui_block")
|
| 18 |
+
docx_reinsert_ui_block = _extract_triple_quoted_assignment("docx_reinsert_ui_block")
|
| 19 |
anonymization_flow = " with st.expander(\"Over deze app\", expanded=False):\n st.write(\"anonimiseren\")\n"
|
| 20 |
return (
|
| 21 |
"st.markdown(\"**Kies werkmodus**\")\n"
|
|
|
|
| 31 |
+ scrub_key_import_ui_block
|
| 32 |
+ reinsert_ui_block
|
| 33 |
+ txt_reinsert_ui_block
|
| 34 |
+
+ docx_reinsert_ui_block
|
| 35 |
+ "else:\n"
|
| 36 |
+ anonymization_flow
|
| 37 |
)
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
def test_generated_two_mode_source_compiles_without_indentation_or_syntax_error():
|
|
|
|
| 55 |
compile(_generated_two_mode_source_snippet(), "generated_two_mode_source.py", "exec")
|
| 56 |
|
| 57 |
|
|
|
|
| 59 |
scrub_key_import_ui_block = _extract_triple_quoted_assignment("scrub_key_import_ui_block")
|
| 60 |
reinsert_ui_block = _extract_triple_quoted_assignment("reinsert_ui_block")
|
| 61 |
txt_reinsert_ui_block = _extract_triple_quoted_assignment("txt_reinsert_ui_block")
|
| 62 |
+
docx_reinsert_ui_block = _extract_triple_quoted_assignment("docx_reinsert_ui_block")
|
| 63 |
assert scrub_key_import_ui_block.startswith(' st.markdown("**Scrub Key laden**")')
|
| 64 |
assert reinsert_ui_block.startswith(' st.markdown("**Originele waarden terugzetten**")')
|
| 65 |
assert txt_reinsert_ui_block.startswith(' st.markdown("**TXT-bestand terugzetten**")')
|
| 66 |
+
assert docx_reinsert_ui_block.startswith(' st.markdown("**DOCX-bestand terugzetten**")')
|
| 67 |
assert not scrub_key_import_ui_block.startswith(' st.markdown("**Scrub Key laden**")')
|
| 68 |
assert not reinsert_ui_block.startswith(' st.markdown("**Originele waarden terugzetten**")')
|
| 69 |
assert not txt_reinsert_ui_block.startswith(' st.markdown("**TXT-bestand terugzetten**")')
|
| 70 |
+
assert not docx_reinsert_ui_block.startswith(' st.markdown("**DOCX-bestand terugzetten**")')
|
| 71 |
|
| 72 |
|
| 73 |
+
def test_reinsert_mode_gets_own_scrub_key_reinsert_txt_and_docx_content():
|
| 74 |
mode_index = PATCH_TEXT.index('if solidprivacy_work_mode == "Originele waarden terugzetten":')
|
| 75 |
+
import_index = PATCH_TEXT.index("scrub_key_import_ui_block + reinsert_ui_block + txt_reinsert_ui_block + docx_reinsert_ui_block")
|
| 76 |
assert mode_index < import_index
|
| 77 |
assert "Scrub Key laden" in PATCH_TEXT
|
| 78 |
assert "Upload Scrub Key JSON (.json)" in PATCH_TEXT
|
|
|
|
| 88 |
assert "Zet TXT-bestand lokaal terug" in PATCH_TEXT
|
| 89 |
assert "Herstelde TXT-tekst" in PATCH_TEXT
|
| 90 |
assert "Download hersteld TXT-bestand (.txt)" in PATCH_TEXT
|
| 91 |
+
assert "DOCX-bestand terugzetten" in PATCH_TEXT
|
| 92 |
+
assert "Upload een DOCX-bestand met placeholders" in PATCH_TEXT
|
| 93 |
+
assert "Zet DOCX-bestand lokaal terug" in PATCH_TEXT
|
| 94 |
+
assert "DOCX-bestand lokaal teruggezet" in PATCH_TEXT
|
| 95 |
+
assert "Download hersteld DOCX-bestand (.docx)" in PATCH_TEXT
|
| 96 |
+
assert "Controleverslag DOCX terugzetten" in PATCH_TEXT
|
| 97 |
|
| 98 |
|
| 99 |
def test_anonymization_flow_is_under_else_branch():
|
|
|
|
| 118 |
assert "scrub_key_import_ui_block" not in review_summary_block
|
| 119 |
assert "reinsert_ui_block" not in review_summary_block
|
| 120 |
assert "txt_reinsert_ui_block" not in review_summary_block
|
| 121 |
+
assert "docx_reinsert_ui_block" not in review_summary_block
|
| 122 |
assert "Download herstelde tekst (.txt)" not in review_summary_block
|
| 123 |
assert "Download hersteld TXT-bestand (.txt)" not in review_summary_block
|
| 124 |
+
assert "Download hersteld DOCX-bestand (.docx)" not in review_summary_block
|
| 125 |
|
| 126 |
|
| 127 |
def test_existing_scrub_key_export_and_import_labels_remain_present():
|
|
|
|
| 142 |
|
| 143 |
|
| 144 |
def test_scrubbed_download_behavior_markers_are_not_removed_or_rewired():
|
|
|
|
| 145 |
assert "download_txt" not in PATCH_TEXT
|
| 146 |
assert "download_csv" not in PATCH_TEXT
|
| 147 |
assert "download_docx" not in PATCH_TEXT
|
|
|
|
| 151 |
assert "export_text = apply_replacements_to_text" not in PATCH_TEXT
|
| 152 |
|
| 153 |
|
| 154 |
+
def test_two_mode_patch_does_not_add_pdf_reinsert_upload_ui():
|
| 155 |
forbidden_markers = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
"download_pdf_reinserted",
|
| 157 |
"PDF reinsert",
|
| 158 |
"pdf reinsert",
|
|
|
|
| 161 |
assert marker not in PATCH_TEXT
|
| 162 |
|
| 163 |
|
| 164 |
+
def test_two_mode_patch_does_not_add_ai_cloud_or_forbidden_rehydration_behavior():
|
| 165 |
lower_patch = PATCH_TEXT.lower()
|
| 166 |
for marker in [
|
| 167 |
"requests.post",
|
| 168 |
"httpx.post",
|
| 169 |
"cloud processing call",
|
|
|
|
| 170 |
"restore_original_document",
|
| 171 |
"server-side key storage",
|
| 172 |
"durable key vault",
|