diff --git a/pii_scan.py b/pii_scan.py index 2fbeb48..08aac38 100644 --- a/pii_scan.py +++ b/pii_scan.py @@ -168,6 +168,14 @@ def create_analyzer(): patterns=[student_id_pattern]) registry.add_recognizer(student_id_recognizer) + american_phone_number_pattern = Pattern(name='american_phone_number', + regex=r'(\b)*1(-|.)?(\d{3}|\(\d{3}\))(-|.)?\d{3}(-|.)?\d{4}(\b)*', + score=0.85) + american_phone_number_recognizer = PatternRecognizer(supported_entity='AMERICAN_PHONE_NUMBER', + patterns=[american_phone_number_pattern]) + registry.add_recognizer(american_phone_number_recognizer) + + # Create a pattern to detect fourteen digit phone numbers international_pn_pattern = Pattern(name='international_pn', regex=r'^\d{3}-\d{3}-\d{4}-\d{4}', diff --git a/test_pii_scan.py b/test_pii_scan.py index 58fa7dd..6675d3a 100644 --- a/test_pii_scan.py +++ b/test_pii_scan.py @@ -69,8 +69,8 @@ def test_base_supported_entities(self): 'AU_ACN', 'ORGANIZATION', 'STUDENT_ID', - 'USERNAME' - ] + 'USERNAME', + 'AMERICAN_PHONE_NUMBER'] for entity in supported_entities: self.assertIn(entity, results) diff --git a/test_team_superior_coders.py b/test_team_superior_coders.py index 98443d0..944cab3 100644 --- a/test_team_superior_coders.py +++ b/test_team_superior_coders.py @@ -6,7 +6,7 @@ class TestSuperiorCoders(unittest.TestCase): def test_aggie_pride(self): """Test to make sure the Aggie Pride function works""" self.assertEqual('Aggie Pride - Worldwide', show_aggie_pride()) - + def test_political_standings(self): """ Test to make sure political standing is detected""" #positive testcase @@ -36,7 +36,34 @@ def test_student_id_detect(self): print(result) self.assertNotIn('STUDENT_ID', str(result)) + def test_american_phone_number_detect(self): + """Test to ensure an American Phone Number is detected""" + + #positive test case + results = analyze_text('My phone number is 1-(199)-555-9461') + print(results) + self.assertIn('AMERICAN_PHONE_NUMBER', str(results)) + + #positive test case + results = analyze_text('My phone number is 1.121.555.2962') + print(results) + self.assertIn('AMERICAN_PHONE_NUMBER', str(results)) + #positive test case + results = analyze_text('My phone number is 11215552962') + print(results) + self.assertIn('AMERICAN_PHONE_NUMBER', str(results)) + + #Test to ensure an American Phone Number is not detected + #negetive test case + results = analyze_text('My phone number is -120-555-9461') + print(results) + self.assertNotIn('AMERICAN_PHONE_NUMBER', str(results)) + + #negetive test case + results = analyze_text('My phone number is 555-9461') + print(results) + self.assertNotIn('AMERICAN_PHONE_NUMBER', str(results)) def test_passport_number_detect(self): """Test to show if a passport number is detected"""