예제 #1
0
 def test_scrub_dict_remove_fields_in_place(self):
     data = {
         'email': '*****@*****.**',
         'text': 'hello'
     }
     scrubber.scrub_dict(data, remove_fields=['email'])
     eq_(data, {'text': 'hello'})
예제 #2
0
 def test_scrub_dict_clean_fields(self):
     data = {
         'email':
         '*****@*****.**',
         'text': ('this is my email address [email protected] and my website '
                  'http://www.example.org/ do you like it?')
     }
     scrubber.scrub_dict(data,
                         clean_fields=[('text', scrubber.EMAIL),
                                       ('text', scrubber.URL)])
     ok_('email' in data)
     ok_('text' in data)
     ok_('email address' in data['text'])
     ok_('*****@*****.**' not in data['text'])
     ok_('http://www.example.org/' not in data['text'])
예제 #3
0
 def test_scrub_dict_replace_fields(self):
     data = {
         'email': '*****@*****.**',
         'text': 'hello'
     }
     res = scrubber.scrub_dict(data, replace_fields=[('email', 'scrubbed')])
     eq_(res, {'email': 'scrubbed', 'text': 'hello'})
 def test_scrub_dict_replace_fields(self):
     data = {
         'email': '*****@*****.**',
         'text': 'hello'
     }
     res = scrubber.scrub_dict(data, replace_fields=[('email', 'scrubbed')])
     eq_(res, {'email': 'scrubbed', 'text': 'hello'})
 def test_scrub_dict_remove_fields(self):
     data = {
         'email': '*****@*****.**',
         'text': 'hello'
     }
     res = scrubber.scrub_dict(data, remove_fields=['email'])
     eq_(res, {'text': 'hello'})
예제 #6
0
 def test_scrub_dict_clean_fields(self):
     data = {
         'email': '*****@*****.**',
         'text': (
             'this is my email address [email protected] and my website '
             'http://www.example.org/ do you like it?'
         )
     }
     scrubber.scrub_dict(
         data,
         clean_fields=[('text', scrubber.EMAIL), ('text', scrubber.URL)]
     )
     ok_('email' in data)
     ok_('text' in data)
     ok_('email address' in data['text'])
     ok_('*****@*****.**' not in data['text'])
     ok_('http://www.example.org/' not in data['text'])
예제 #7
0
 def test_scrub_dict_remove_fields_copy(self):
     data = {'email': '*****@*****.**', 'text': 'hello'}
     res = scrubber.scrub_dict(data,
                               remove_fields=['email'],
                               make_copy=True)
     eq_(res, {'text': 'hello'})
     ok_('email' in data)
     ok_('text' in data)
예제 #8
0
    def _scrub_item(self, data, whitelist):
        for key in data.keys():
            if key not in whitelist:
                # warnings.warn() never redirects the same message to
                # the logger more than once in the same python
                # process. Doing this helps developers notice/remember
                # which fields are being left out
                if self.debug:
                    msg = 'Skipping %r' % (key,)
                    warnings.warn(msg)
                del data[key]

        if self.clean_scrub:
            scrubber.scrub_dict(
                data,
                clean_fields=self.clean_scrub,
            )
예제 #9
0
 def test_scrub_dict_remove_fields_copy(self):
     data = {
         'email': '*****@*****.**',
         'text': 'hello'
     }
     res = scrubber.scrub_dict(data, remove_fields=['email'],
                               make_copy=True)
     eq_(res, {'text': 'hello'})
     ok_('email' in data)
     ok_('text' in data)
예제 #10
0
 def test_scrub_dict_remove_fields_copy(self):
     data = {
         'email': '*****@*****.**',
         'text': 'hello'
     }
     res = scrubber.scrub_dict(data, remove_fields=['email'],
                               make_copy=True)
     assert res == {'text': 'hello'}
     assert 'email' in data
     assert 'text' in data
예제 #11
0
 def test_scrub_dict_remove_fields_in_place(self):
     data = {'email': '*****@*****.**', 'text': 'hello'}
     scrubber.scrub_dict(data, remove_fields=['email'])
     eq_(data, {'text': 'hello'})