Spaces:
Sleeping
Sleeping
solidprivacy-nl commited on
Commit 路
83353e4
1
Parent(s): 9b872f1
Add Scrub Key import UI patch tests
Browse files
tests/test_scrub_key_import_ui_patch.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
PATCH_TEXT = Path("fix_streamlit_nested_expanders.py").read_text(encoding="utf-8")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_scrub_key_import_helper_is_used_by_streamlit_patch():
|
| 8 |
+
assert "from scrub_key_import import IMPORT_PRIVACY_WARNING, build_scrub_key_import_result" in PATCH_TEXT
|
| 9 |
+
assert "build_scrub_key_import_result(scrub_key_import_text)" in PATCH_TEXT
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_scrub_key_load_ui_label_and_input_paths_are_present():
|
| 13 |
+
assert "Scrub Key laden" in PATCH_TEXT
|
| 14 |
+
assert "Upload Scrub Key JSON (.json)" in PATCH_TEXT
|
| 15 |
+
assert "Of plak Scrub Key JSON" in PATCH_TEXT
|
| 16 |
+
assert "Valideer en laad Scrub Key" in PATCH_TEXT
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def test_scrub_key_load_ui_contains_pseudonymization_and_local_key_warnings():
|
| 20 |
+
assert "lokaal herleidbaar" in PATCH_TEXT
|
| 21 |
+
assert "pseudonimisering" in PATCH_TEXT
|
| 22 |
+
assert "geen volledige anonimisering" in PATCH_TEXT
|
| 23 |
+
assert "Bewaar deze sleutel lokaal" in PATCH_TEXT
|
| 24 |
+
assert "AI-diensten of derden" in PATCH_TEXT
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_imported_scrub_key_is_validated_before_rows_are_loaded():
|
| 28 |
+
validation_index = PATCH_TEXT.index("build_scrub_key_import_result(scrub_key_import_text)")
|
| 29 |
+
ok_check_index = PATCH_TEXT.index('scrub_key_import_result.get("ok")')
|
| 30 |
+
load_index = PATCH_TEXT.index('st.session_state["scrub_key_import_rows"]')
|
| 31 |
+
|
| 32 |
+
assert validation_index < ok_check_index < load_index
|
| 33 |
+
assert 'scrub_key_import_result.get("mapping_rows", [])' in PATCH_TEXT
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_imported_rows_are_loaded_into_review_table_without_silent_replacement():
|
| 37 |
+
assert 'if st.button("Valideer en laad Scrub Key", key="load_scrub_key_import")' in PATCH_TEXT
|
| 38 |
+
assert 'if "scrub_key_import_rows" in st.session_state' in PATCH_TEXT
|
| 39 |
+
assert "default_editor_rows.append(imported_row)" in PATCH_TEXT
|
| 40 |
+
assert "replacement_editor" in PATCH_TEXT
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_scrub_key_import_ui_does_not_add_ai_output_or_rehydrate_flow():
|
| 44 |
+
assert "AI-output" not in PATCH_TEXT
|
| 45 |
+
assert "rehydrat" not in PATCH_TEXT.lower()
|
| 46 |
+
assert "restore_original" not in PATCH_TEXT
|
| 47 |
+
assert "scrub_key_from_json" not in PATCH_TEXT
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def test_existing_scrub_key_export_block_is_kept():
|
| 51 |
+
assert "Scrub Key (JSON)" in PATCH_TEXT
|
| 52 |
+
assert "Download Scrub Key (.json)" in PATCH_TEXT
|
| 53 |
+
assert "scrub_key_to_json(scrub_key)" in PATCH_TEXT
|
| 54 |
+
assert "solidprivacy_scrub_key.json" in PATCH_TEXT
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_existing_download_and_export_markers_are_kept_unblocked():
|
| 58 |
+
assert 'st.subheader("4. Download opgeschoonde bestanden")' in PATCH_TEXT
|
| 59 |
+
assert "Eindcontrole v贸贸r download" in PATCH_TEXT
|
| 60 |
+
assert "Extra exportcontrole" in PATCH_TEXT
|
| 61 |
+
assert "st.warning(EXPORT_GUIDANCE)" in PATCH_TEXT
|
| 62 |
+
assert "st.stop()" not in PATCH_TEXT
|
| 63 |
+
assert "blocks_export = True" not in PATCH_TEXT
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_patch_does_not_alter_existing_replacement_application_or_download_functions():
|
| 67 |
+
assert "def apply_replacements_to_text" not in PATCH_TEXT
|
| 68 |
+
assert "apply_replacements_to_text =" not in PATCH_TEXT
|
| 69 |
+
assert "export_text = apply_replacements_to_text" not in PATCH_TEXT
|
| 70 |
+
assert "download_txt" not in PATCH_TEXT
|
| 71 |
+
assert "download_csv" not in PATCH_TEXT
|
| 72 |
+
assert "download_docx" not in PATCH_TEXT
|
| 73 |
+
assert "download_pdf" not in PATCH_TEXT
|