Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pii_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
AuAbnRecognizer,
AuAcnRecognizer,
AuTfnRecognizer,
AuMedicareRecognizer
AuMedicareRecognizer,
InPanRecognizer,
InAadhaarRecognizer,
InVehicleRegistrationRecognizer,
InPassportRecognizer,
InVoterRecognizer,
UkNinoRecognizer
)

from presidio_anonymizer import AnonymizerEngine
Expand Down Expand Up @@ -59,6 +65,12 @@
registry.add_recognizer(AuAcnRecognizer(supported_language='en'))
registry.add_recognizer(AuTfnRecognizer(supported_language='en'))
registry.add_recognizer(AuMedicareRecognizer(supported_language='en'))
registry.add_recognizer(InPanRecognizer(supported_language='en'))
registry.add_recognizer(InAadhaarRecognizer(supported_language='en'))
registry.add_recognizer(InVehicleRegistrationRecognizer(supported_language='en'))
registry.add_recognizer(InPassportRecognizer(supported_language='en'))
registry.add_recognizer(InVoterRecognizer(supported_language='en'))
registry.add_recognizer(UkNinoRecognizer(supported_language='en'))


# Create an analyzer object
Expand Down Expand Up @@ -102,7 +114,9 @@ def anonymize_data(data: list) -> None:
print(f'ID:{i}:Anonymized: {anonymize_text(item, [])}')


def analyze_text(text: str, entity_list: list, show_supported=False) -> list[str] | list[RecognizerResult]:
def analyze_text(text: str,
entity_list: list,
show_supported=False) -> list[str] | list[RecognizerResult]:
"""
Analyze the text using the entity list
:param text: the text to be analyzed
Expand Down
76 changes: 76 additions & 0 deletions test_pii_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Some unit tests for the PII scan module."""
import unittest
import os
import ast
from pii_scan import show_aggie_pride, analyze_text


class TestPIIScan(unittest.TestCase):
"""Test cases for PII scan module."""
def test_aggie_pride(self):
"""Test to make sure the Aggie Pride function works"""
self.assertEqual('Aggie Pride - Worldwide', show_aggie_pride())

def test_base_supported_entities(self):
"""Test to make sure the default expected supported entities are returned"""
results = analyze_text('', [], show_supported=True)
Comment thread
claesmk marked this conversation as resolved.
Outdated
supported_entities = ['IP_ADDRESS',
'MEDICAL_LICENSE',
'LOCATION',
'EMAIL_ADDRESS',
'DATE_TIME',
'ORGANIZATION',
'CREDIT_CARD',
'CRYPTO',
'AU_MEDICARE',
'AU_ABN',
'PHONE_NUMBER',
'US_PASSPORT',
'IBAN_CODE',
'AU_TFN',
'US_BANK_NUMBER',
'NRP',
'UK_NHS',
'UK_NINO',
'US_SSN',
'PERSON',
'URL',
'US_ITIN',
'US_DRIVER_LICENSE',
'AU_ACN',
'IT_VAT_CODE',
'IT_IDENTITY_CARD',
'IT_DRIVER_LICENSE',
'IT_PASSPORT',
'IT_FISCAL_CODE',
'FI_PERSONAL_IDENTITY_CODE',
'PL_PESEL',
'ES_NIE',
'ES_NIF',
'ABA_ROUTING_NUMBER',
'IN_VEHICLE_REGISTRATION',
'IN_PASSPORT',
'IN_VOTER',
'IN_AADHAAR',
'IN_PAN']
Comment thread
claesmk marked this conversation as resolved.
Outdated

for entity in supported_entities:
self.assertIn(entity, results)

def test_starts_with_test(self):
"""Test to make sure all test methods start with test"""
# In order to run as a test case the method name must start with test
# This test checks to make sure all defines within test files start with test
# This is a common mistake that can cause tests to be skipped
from pathlib import Path
for file in Path(os.path.dirname(__file__)).glob('test_*.py'):
with file.open(encoding='utf-8') as f:
tree = ast.parse(f.read(), filename=file)
for node in ast.walk(tree):
Comment thread
claesmk marked this conversation as resolved.
Outdated
if isinstance(node, ast.FunctionDef):
method_name = node.name
# Skip legitimate non-test methods like setUp, tearDown, and private methods
if method_name in {'setUp', 'tearDown'} or method_name.startswith('_'):
continue
self.assertTrue(method_name.startswith('test'),
f'Method name does not start with test: def {method_name} in {file}')
1 change: 0 additions & 1 deletion test_team_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_credit_card(self):
# Check to make sure there is no result
self.assertEqual(len(result), 0, "Negative test case should not find a result")


def test_crypto(self):
"""Test CRYPTO functionality"""

Expand Down