def __init__(self, *args, **kwargs): super(PrivacyFilterBiggerTest, self).__init__(*args, **kwargs) self.TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is 0 (888) 87-70-50. In interantional format it is writen as +359 888 87 70 50 or 00359 (888) 877050. My email is [email protected] and alternative [email protected]. I have a problem with order from Amazon. The e-mail of their support is [email protected]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.FILTERED_TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [EMAIL] and alternative [EMAIL]. I have a problem with order from Amazon. The e-mail of their support is [EMAIL]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.FILTERED_TEXT_PRESERVE_COUNTRY_CODE_AND_HOSTNAME = textwrap.dedent( """\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as +359 [FILTERED] or 00359 [FILTERED]. My email is [FILTERED]@gmail.com and alternative [FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is [FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.FILTERED_TEXT_PARTIALLY_PRESERVE_USERNAME = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [FILTERED]@gmail.com and alternative iva[FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is sup[FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.filter = PrivacyFilter(self.TEXT)
class PrivacyFilterBiggerTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(PrivacyFilterBiggerTest, self).__init__(*args, **kwargs) self.TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is 0 (888) 87-70-50. In interantional format it is writen as +359 888 87 70 50 or 00359 (888) 877050. My email is [email protected] and alternative [email protected]. I have a problem with order from Amazon. The e-mail of their support is [email protected]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.FILTERED_TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [EMAIL] and alternative [EMAIL]. I have a problem with order from Amazon. The e-mail of their support is [EMAIL]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.FILTERED_TEXT_PRESERVE_COUNTRY_CODE_AND_HOSTNAME = textwrap.dedent( """\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as +359 [FILTERED] or 00359 [FILTERED]. My email is [FILTERED]@gmail.com and alternative [FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is [FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.FILTERED_TEXT_PARTIALLY_PRESERVE_USERNAME = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [FILTERED]@gmail.com and alternative iva[FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is sup[FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""" ) self.filter = PrivacyFilter(self.TEXT) def test_filter(self): self.filter.preserve_phone_country_code = False self.filter.preserve_email_hostname = False self.filter.partially_preserve_email_username = False self.assertEqual(self.FILTERED_TEXT, self.filter.filtered()) def test_filter_preserve_country_code_and_hostname(self): self.filter.preserve_phone_country_code = True self.filter.preserve_email_hostname = True self.filter.partially_preserve_email_username = False self.assertEqual(self.FILTERED_TEXT_PRESERVE_COUNTRY_CODE_AND_HOSTNAME, self.filter.filtered()) def test_filter_partially_preserve_username(self): self.filter.preserve_phone_country_code = False self.filter.preserve_email_hostname = False self.filter.partially_preserve_email_username = True self.assertEqual(self.FILTERED_TEXT_PARTIALLY_PRESERVE_USERNAME, self.filter.filtered())
def __init__(self, *args, **kwargs): super(PrivacyFilterBiggerTest, self).__init__(*args, **kwargs) self.TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is 0 (888) 87-70-50. In interantional format it is writen as +359 888 87 70 50 or 00359 (888) 877050. My email is [email protected] and alternative [email protected]. I have a problem with order from Amazon. The e-mail of their support is [email protected]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.FILTERED_TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [EMAIL] and alternative [EMAIL]. I have a problem with order from Amazon. The e-mail of their support is [EMAIL]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.FILTERED_TEXT_PRESERVE_COUNTRY_CODE_AND_HOSTNAME = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as +359 [FILTERED] or 00359 [FILTERED]. My email is [FILTERED]@gmail.com and alternative [FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is [FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.FILTERED_TEXT_PARTIALLY_PRESERVE_USERNAME = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [FILTERED]@gmail.com and alternative iva[FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is sup[FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.filter = PrivacyFilter(self.TEXT)
class PrivacyFilterBiggerTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(PrivacyFilterBiggerTest, self).__init__(*args, **kwargs) self.TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is 0 (888) 87-70-50. In interantional format it is writen as +359 888 87 70 50 or 00359 (888) 877050. My email is [email protected] and alternative [email protected]. I have a problem with order from Amazon. The e-mail of their support is [email protected]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.FILTERED_TEXT = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [EMAIL] and alternative [EMAIL]. I have a problem with order from Amazon. The e-mail of their support is [EMAIL]. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.FILTERED_TEXT_PRESERVE_COUNTRY_CODE_AND_HOSTNAME = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as +359 [FILTERED] or 00359 [FILTERED]. My email is [FILTERED]@gmail.com and alternative [FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is [FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.FILTERED_TEXT_PARTIALLY_PRESERVE_USERNAME = textwrap.dedent("""\ Hi my name is Ivan and my phone is [PHONE]. In interantional format it is writen as [PHONE] or [PHONE]. My email is [FILTERED]@gmail.com and alternative iva[FILTERED]@abv.bg. I have a problem with order from Amazon. The e-mail of their support is sup[FILTERED]@amazon.co.uk. My social sequrity number is 0-1-2-3-4-5 and EGN 8510135927.""") self.filter = PrivacyFilter(self.TEXT) def test_filter(self): self.filter.preserve_phone_country_code = False self.filter.preserve_email_hostname = False self.filter.partially_preserve_email_username = False self.assertEqual(self.FILTERED_TEXT, self.filter.filtered()) def test_filter_preserve_country_code_and_hostname(self): self.filter.preserve_phone_country_code = True self.filter.preserve_email_hostname = True self.filter.partially_preserve_email_username = False self.assertEqual(self.FILTERED_TEXT_PRESERVE_COUNTRY_CODE_AND_HOSTNAME, self.filter.filtered()) def test_filter_partially_preserve_username(self): self.filter.preserve_phone_country_code = False self.filter.preserve_email_hostname = False self.filter.partially_preserve_email_username = True self.assertEqual(self.FILTERED_TEXT_PARTIALLY_PRESERVE_USERNAME, self.filter.filtered())
def test_do_not_replace_invalid_phone_numbers(self): filter = PrivacyFilter("Phone 0012345 is invalid.") self.assertEqual("Phone 0012345 is invalid.", filter.filtered())
def test_allows_country_code_to_be_preserved_for_internationally_formatted_phone_numbers(self): filter = PrivacyFilter('Phone: +35925551212') filter.preserve_phone_country_code = True self.assertEqual('Phone: +359 [FILTERED]', filter.filtered())
def test_do_not_preserve_local_format_phome_prefix(self): filter = PrivacyFilter('Phone: 025551212') filter.preserve_phone_country_code = True self.assertEqual('Phone: [PHONE]', filter.filtered())
def test_allows_email_usernames_to_be_partially_preserved(self): filter = PrivacyFilter('*****@*****.**') filter.partially_preserve_email_username = True self.assertEqual('som[FILTERED]@example.com', filter.filtered())
def test_allows_country_code_to_be_preserved_for_internationally_formatted_phone_numbers( self): filter = PrivacyFilter('Phone: +35925551212') filter.preserve_phone_country_code = True self.assertEqual('Phone: +359 [FILTERED]', filter.filtered())
def test_filters_phone_numbers(self): self.assertEqual('Reach me at: [PHONE]', PrivacyFilter('Reach me at: 0885123123').filtered())
def test_obfuscates_simple_emails(self): self.assertEqual( 'Contact: [EMAIL]', PrivacyFilter('Contact: [email protected]').filtered())