-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtest_team_t1.py
188 lines (145 loc) · 7.95 KB
/
test_team_t1.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import unittest
from pii_team_t1 import *
class TeamFrostTests(unittest.TestCase):
def test_find_us_phone_number(self):
# test a single phone number at the end of a string
results_list = find_us_phone_number('My phone number is 123-456-7890')
self.assertEqual(results_list[0], '123-456-7890')
# test a single phone number at the beginning of a string
results_list = find_us_phone_number('123-456-7890 is my phone number')
self.assertEqual(results_list[0], '123-456-7890')
# test a single phone number in the middle of a string
results_list = find_us_phone_number('You can reach me at 123-456-7890. That is my number')
self.assertEqual(results_list[0], '123-456-7890')
# test multiple phone numbers
results_list = find_us_phone_number('123-456-7890 is my phone number. Her number is 987-654-3210')
self.assertEqual(results_list[0], '123-456-7890')
self.assertEqual(results_list[1], '987-654-3210')
# test an invalid phone number
results_list = find_us_phone_number('1234567890 is my phone number')
# result_list should be empty
self.assertFalse(results_list)
def test_find_visa_mastercard(self):
# return results at end of string
results_list = find_visa_mastercard('My credit card number is 1234-5678-9012-3456')
self.assertEqual(results_list[0], '1234-5678-9012-3456')
# return results at beginning of string
results_list = find_visa_mastercard('1234-5678-9012-3456 is my credit card number')
self.assertEqual(results_list[0], '1234-5678-9012-3456')
# return results with multiple numbers
results_list = find_visa_mastercard(
'I have 2 cards. one number is 1234-5678-9012-3456 the other is 3210-9876-5432-1098')
self.assertEqual(results_list[0], '1234-5678-9012-3456')
self.assertEqual(results_list[1], '3210-9876-5432-1098')
# test wrong format
results_list = find_visa_mastercard('My credit card number is 1234-5678-3456')
self.assertFalse(results_list)
# test with letter inside
results_list = find_visa_mastercard('My credit card number is 1234-5678-9TF2-3456')
self.assertFalse(results_list)
def test_find_amex(self):
results_list = find_amex('My credit card number is 1234-567890-12345')
self.assertEqual(results_list[0], '1234-567890-12345')
#return results in middle of string
results_list = find_amex('My new card number is 1234-567890-54321. This is a new card')
self.assertEqual(results_list[0], '1234-567890-54321')
#return wrong number format
results_list = find_amex('The card number is 1234-5678-90123')
self.assertFalse(results_list)
#return number from end of string
results_list = find_amex('Her card number is 0987-654321-23456')
self.assertEqual(results_list[0], '0987-654321-23456')
def test_find_us_ssn(self):
results_list = find_us_ssn('My social security number is 123-45-6789')
self.assertEqual(results_list[0], '123-45-6789')
# tests with a SSN at the end of the string
results_list = find_us_ssn('My social security number is 123-45-6789')
self.assertEqual(results_list[0], '123-45-6789')
# tests with a SSN at the beginning of a string
results_list = find_us_ssn('123-45-6789 is my social security number')
self.assertEqual(results_list[0], '123-45-6789')
# tests with a SSN in the middle of a string
results_list = find_us_ssn('Can the number 123-45-6789 be my new SSN')
self.assertEqual(results_list[0], '123-45-6789')
# tests with a different number for SSN
results_list = find_us_ssn('My social security number is 012-01-0123')
self.assertEqual(results_list[0], '012-01-0123')
# tests with multiple SSN in the string
results_list = find_us_ssn('Is my SSN 123-45-6789 or is 123-12-1234 my SSN')
self.assertEqual(results_list[0], '123-45-6789')
self.assertEqual(results_list[1], '123-12-1234')
# tests SSN without dashes
results_list = find_us_ssn('My SSN is 123456789')
# US SSNs must have dashes after the third digit and after the 5th digit
self.assertFalse(results_list)
# tests with letters entered instead of digits
results_list = find_us_ssn('my SSN is 123-four5-6789')
self.assertFalse(results_list)
def test_find_email(self):
# test an email given at the end of string
results_list = find_email("My email address is [email protected]")
self.assertEqual(results_list[0], '[email protected]')
# test an email given at the beginning of string
results_list = find_email("[email protected] is my email")
self.assertEqual(results_list[0], '[email protected]')
# test multiple emails given
results_list = find_email("My email address is [email protected] , her's is [email protected]")
self.assertEqual(results_list[0], '[email protected]')
self.assertEqual(results_list[1], '[email protected]')
# test with new email address
results_list = find_email("My new email addrees is [email protected]")
self.assertEqual(results_list[0], '[email protected]')
# test invalid email
results_list = find_email("My email address is jim.jones.com")
self.assertFalse(results_list)
def test_find_instagram_handle(self):
# test an ig handle at the end of a string
results_list = find_instagram_handle('My instagram handle is @jimjones')
self.assertEqual(results_list, ['@jimjones'])
# test an ig handle given at the beginning of a string
results_list = find_instagram_handle('@jimjones is my instagram handle')
self.assertEqual(results_list, ['@jimjones'])
# test multiple ig handles given
results_list = find_instagram_handle('My instagram handle is @jimjones. My cousin\'s is @caryjones.')
self.assertEqual(results_list, ['@jimjones', '@caryjones'])
# test with special characters handle
results_list = find_instagram_handle('My instagram handle is @jim_jones')
self.assertEqual(results_list, ['@jim_jones'])
# test with an invalid ig handle given
results_list = find_instagram_handle('My instagram handle is jimjones')
self.assertEqual(results_list, [])
def test_replace_us_phone_number(self):
string = 'My phone number is 336-123-8945'
expected = 'My phone number is <PHONE_NUMBER>'
result = anonymize_pii(string)
self.assertEqual(expected, result.text)
def test_replace_us_ssn(self):
string = 'My ssn is 123-45-6789'
expected = 'My ssn is <US_SSN>'
output = anonymize_pii(string)
self.assertEqual(string, output.text)
def test_replace_name(self):
test_str = 'My name is Jane Doe'
expected = 'My name is <PERSON>'
result = anonymize_pii(test_str)
self.assertEqual(expected, result.text)
def test_replace_name(self):
test_str = 'My instagram is @jane_doe'
expected = 'My instagram is <IG_HANDLE>'
result = anonymize_pii(test_str)
self.assertEqual(expected, result.text)
def test_replace_credit_card(self):
test_str = 'My credit card number is 4095-3434-2424-1414'
expected = 'My credit card number is <CREDIT_CARD>'
result = anonymize_pii(test_str)
self.assertEqual(expected, result.text)
def test_replace_amex_number(self):
test_str = 'My Amex card number is 1234-567890-54321'
expected = 'My Amex card number is <AMEX_NUMBER>'
def test_replace_email(self):
test_str = "My email is [email protected]"
expected = "My email is <EMAIL_ADDRESS>"
result = anonymize_pii(test_str)
self.assertEqual(expected, result.text)
if __name__ == '__main__':
unittest.main()