# Path: deliver/tests/test_base.py
# class BaseTest(unittest.TestCase):
# 
#     def setUp(self):
#         from test_data.test_config import py
#         self.config = py.copy()
# 
#     def tearDown(self):
#         super(BaseTest,self).tearDown()
#         if os.path.isfile(self.config['db_name']):
#             os.remove(self.config['db_name'])
# 
# def load_msg(fileName):
#     '''Loads the message contained in the given file and returns it as
#     an UnicodeMessage.'''
#     return UnicodeMessage(email.message_from_file(open_data(fileName)))
# 
# def load_all_msg():
#     '''Loads all the available sample messages and returns them as a list.'''
#     return [load_msg(fileName) for fileName in ['sample', 'sample2',
#                                                 'sample3',
#                                                 'sample4', # content base64
#                                                 'sample5', # content base64 utf-8
#                                                 'sample6', # empty content
#                                                 'sample7', # invalid sender
#                                                 'sample8', # whitelisted sender
#                                                 'sample9',  # blacklisted sender
#                                                 'sample10', # get www.google.com
#                                                 'sample11', # no header/body encoding
#                                                 'sample13' # msg without subject
#                                                 ]]


from deliver.tests.test_base import BaseTest, load_msg, load_all_msg

    def test_get_payload_empty(self):
        self.msg = load_msg('sample6')
        self._test_get(u'\n', u'\n')

    def test_clean_word_no_replace(self):
        self.assertEqual(self.msg._clean_word(u'panic', {}), u'panic')

    def test_clean_word_replace(self):
        self.assertEqual(self.msg._clean_word(u'panic', {u'panic' : u'don\'t'}), u'don\'t')

    def test_clean_word_replace_case(self):
        self.assertEqual(self.msg._clean_word(u'Panic', {u'panic' : u'don\'t'}), u'don\'t')

    def test_clean_word_replace_special_chars(self):
        self.assertEqual(self.msg._clean_word(u'Pánico', {u'pánico' : u'don\'t'}), u'don\'t')

    def test_clean_word_surrounded(self):
        self.assertEqual(self.msg._clean_word(u'*Pánico*?', {u'pánico' : u'don\'t'}), u'*don\'t*?')

    def test_get_clean_payload(self):
        words = self.config['forbidden_words']
        payload = self.get_clean_text(words)

        for word in words.keys():
            self.assertFalse(word in payload, 'word %s was not removed' % word)
        for replacement in words.values():
            self.assertTrue(replacement in payload, 'word %s was not inserted' % word)

    def test_walk(self):

# Path: deliver/tests/test_base.py
# class BaseTest(unittest.TestCase):
# 
#     def setUp(self):
#         from test_data.test_config import py
#         self.config = py.copy()
# 
#     def tearDown(self):
#         super(BaseTest,self).tearDown()
#         if os.path.isfile(self.config['db_name']):
#             os.remove(self.config['db_name'])
# 
# def load_msg(fileName):
#     '''Loads the message contained in the given file and returns it as
#     an UnicodeMessage.'''
#     return UnicodeMessage(email.message_from_file(open_data(fileName)))
# 
# def load_all_msg():
#     '''Loads all the available sample messages and returns them as a list.'''
#     return [load_msg(fileName) for fileName in ['sample', 'sample2',
#                                                 'sample3',
#                                                 'sample4', # content base64
#                                                 'sample5', # content base64 utf-8
#                                                 'sample6', # empty content
#                                                 'sample7', # invalid sender
#                                                 'sample8', # whitelisted sender
#                                                 'sample9',  # blacklisted sender
#                                                 'sample10', # get www.google.com
#                                                 'sample11', # no header/body encoding
#                                                 'sample13' # msg without subject
#                                                 ]]


# Path: deliver/tests/converter/test_converter.py
from deliver.tests.test_base import BaseTest, load_msg, load_all_msg


    def test_get_payload_empty(self):
        self.msg = load_msg('sample6')
        self._test_get(u'\n', u'\n')

    def test_clean_word_no_replace(self):
        self.assertEqual(self.msg._clean_word(u'panic', {}), u'panic')

    def test_clean_word_replace(self):
        self.assertEqual(self.msg._clean_word(u'panic', {u'panic' : u'don\'t'}), u'don\'t')

    def test_clean_word_replace_case(self):
        self.assertEqual(self.msg._clean_word(u'Panic', {u'panic' : u'don\'t'}), u'don\'t')

    def test_clean_word_replace_special_chars(self):
        self.assertEqual(self.msg._clean_word(u'Pánico', {u'pánico' : u'don\'t'}), u'don\'t')

    def test_clean_word_surrounded(self):
        self.assertEqual(self.msg._clean_word(u'*Pánico*?', {u'pánico' : u'don\'t'}), u'*don\'t*?')

    def test_get_clean_payload(self):
        words = self.config['forbidden_words']
        payload = self.get_clean_text(words)

        for word in words.keys():
            self.assertFalse(word in payload, 'word %s was not removed' % word)
        for replacement in words.values():
            self.assertTrue(replacement in payload, 'word %s was not inserted' % word)

    def test_walk(self):

        for mail in load_all_msg():