def test_unicode_decoding(self, text, expected):
     obfuscator = obfuscate_util.Obfuscator()
     user_info = {'name': ['Olav Øyaland'.decode('utf8'), 'Test User']}
     result = obfuscator.obfuscate_structure(text,
                                             'root',
                                             user_info=user_info)
     self.assertEquals(result, expected)
 def test_entity_flags(self, text, entities):
     obfuscator = obfuscate_util.Obfuscator()
     result = obfuscator.obfuscate_text(
         text,
         user_info={
             'username': ['testusername'],
             'user_id': [12345],
             'name': ['Test User'],
         },
         entities=entities,
     )
     self.assertTrue(result.startswith('<<'))
     self.assertTrue(result.endswith('>>'))
 def test_obfuscate_email_before_username(self):
     obfuscator = obfuscate_util.Obfuscator()
     input_text = "Email is [email protected]."
     result = obfuscator.obfuscate_text(
         input_text,
         user_info={'username': ['testusername']},
     )
     self.assertEquals(result, 'Email is <<EMAIL>>.')
     result = obfuscator.obfuscate_text(
         input_text,
         user_info={'username': ['testusername']},
         entities=['username'],
     )
     self.assertEquals(result, 'Email is <<USERNAME>>@example.com.')
 def test_obfuscate_list(self):
     input_obj = {
         'key': [
             {'email': '*****@*****.**'},
             {'dummy': 'unchanging value'},
             {'phone': '213-456-7890'},
             {'list': ['unchanging list value']},
         ]
     }
     obfuscator = obfuscate_util.Obfuscator()
     result = obfuscator.obfuscate_structure(input_obj, 'root')
     expected = {'key': [
         {'email': '<<EMAIL>>'},
         {'dummy': 'unchanging value'},
         {'phone': '<<PHONE_NUMBER>>'},
         {'list': ['unchanging list value']},
     ]}
     self.assertEquals(result, expected)
 def test_backslash_decoding(self, text, expected):
     obfuscator = obfuscate_util.Obfuscator()
     result = obfuscator.obfuscate_structure(text, 'root')
     self.assertEquals(result, expected)