-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_team_null.py
38 lines (31 loc) · 1.41 KB
/
test_team_null.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Unit test file for Team TeamNull"""
import unittest
from pii_scan import anonymize_text
class TestTeamNull(unittest.TestCase):
"""Test the Team TeamNull PII functions"""
def test_anonymize_text(self):
"""Test the anonymize_text function"""
self.assertEqual('I live in <LOCATION>',
anonymize_text('I live in New York', ['LOCATION']))
def test_us_ssn(self):
"""Test us_ssn functionality"""
# positive testcases
prefix = ['123', '245', '532']
mid = ['44', '55', '66']
suffix = ['6789', '2233', '3344']
# generate test cases using list comprehension
test_cases = [f"My SSN is {p}-{m}-{s}" for p in prefix for m in mid for s in suffix]
for test_string in test_cases:
expected = 'My SSN is <US_SSN>'
actual = anonymize_text(test_string, ['US_SSN'])
self.assertEqual(expected, actual)
# negative testcase - this will not be replaced
test_string = 'My SSN is 123-45-6789'
expected = 'My SSN is 123-45-6789'
actual = anonymize_text(test_string, ['US_SSN'])
self.assertEqual(expected, actual)
# another negative testcase - this will not be replaced
test_string = 'My SSN is 245-00-6789'
expected = 'My SSN is 245-00-6789'
actual = anonymize_text(test_string, ['US_SSN'])
self.assertEqual(expected, actual)