Upload files to "/"
This commit is contained in:
39
test_censor_pdfs.py
Normal file
39
test_censor_pdfs.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import pymupdf
|
||||
|
||||
from censor_pdfs import Profile, RectRule, _logo_images, redact_pdf
|
||||
|
||||
|
||||
class CensorPDFTests(unittest.TestCase):
|
||||
def test_redaction_replaces_sensitive_text(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / "source.pdf"
|
||||
output = Path(directory) / "output.pdf"
|
||||
document = pymupdf.open()
|
||||
page = document.new_page()
|
||||
page.insert_text((72, 72), "Well Name: SECRET-WELL")
|
||||
page.insert_text((72, 100), "Keep this text")
|
||||
document.save(source)
|
||||
document.close()
|
||||
|
||||
profile = Profile(terms={"well_name": ("SECRET-WELL",)}, not_applicable=("logo", "rig_name", "coordinates"))
|
||||
audit = redact_pdf(source, output, profile, (0.0, 0.0, 0.0))
|
||||
self.assertEqual(audit.status, "ok")
|
||||
redacted = pymupdf.open(output)
|
||||
text = "".join(page.get_text() for page in redacted)
|
||||
redacted.close()
|
||||
self.assertNotIn("SECRET-WELL", text)
|
||||
self.assertIn("WELL-", text)
|
||||
self.assertIn("Keep this text", text)
|
||||
|
||||
def test_rectangle_rule_tracks_logo_region(self):
|
||||
rule = RectRule("rig_name", (10, 20, 100, 40), (0,))
|
||||
self.assertEqual(rule.category, "rig_name")
|
||||
self.assertEqual(rule.pages, (0,))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user