import unittest

from message import Message


class TestMessage(unittest.TestCase):

    MENTION = '@test_mention'
    EMOTICON = '(test_emoticon)'
    LINK = 'http://example.com'

    def setUp(self):
        self.message = Message()

    def test_check_token_mention(self):
        result = self.message.check_token(TestMessage.MENTION).groupdict()
        mention_dict = {'mentions': TestMessage.MENTION,
                        'emoticons': None,
                        'links': None}
        self.assertEqual(result, mention_dict)

    def test_check_token_emoticon(self):
        min_emoticon = '(a)'
        result = self.message.check_token(min_emoticon).groupdict()
        emoticon_dict = {'mentions': None,
                         'emoticons': min_emoticon,
                         'links': None}
        self.assertEqual(result, emoticon_dict)

        max_emoticon = '(aaaaaaaaaaaaaaa)'
        result = self.message.check_token(max_emoticon).groupdict()
        emoticon_dict = {'mentions': None,
                         'emoticons': max_emoticon,
                         'links': None}
        self.assertEqual(result, emoticon_dict)

    def test_check_not_emoticon(self):
        no_emoticon = '()'
        result = self.message.check_token(no_emoticon)
        self.assertEqual(result, None)

        long_emoticon = '(aaaaaaaaaaaaaaaa)'
        result = self.message.check_token(long_emoticon)
        self.assertEqual(result, None)

    def test_check_token_link(self):
        result = self.message.check_token(TestMessage.LINK).groupdict()
        link_dict = {'mentions': None,
                     'emoticons': None,
                     'links': TestMessage.LINK}
        self.assertEqual(result, link_dict)

    def test_parse(self):
        self.message.message = ' '.join([TestMessage.MENTION,
                                         TestMessage.EMOTICON,
                                         TestMessage.LINK])
        result = self.message.parse()
        message_dict = {
                           'mentions': ['test_mention'],
                           'emoticons': ['test_emoticon'],
                           'links': [
                               {
                                   'title': 'Example Domain',
                                   'url': 'http://example.com'
                               }
                           ]
                       }
        self.assertEqual(result, message_dict)

    def test_add_attribute(self):
        data = {}
        self.message.add_attribute(data, 'key', 'value1')
        data_dict1 = {'key': ['value1']}
        self.assertEqual(data, data_dict1)

        self.message.add_attribute(data, 'key', 'value2')
        data_dict2 = {'key': ['value1', 'value2']}
        self.assertEqual(data, data_dict2)

    def test_get_mention(self):
        result = self.message.get_mention(TestMessage.MENTION)
        self.assertEqual(result, 'test_mention')

        result = self.message.get_mention(''.join([TestMessage.MENTION, '!']))
        self.assertEqual(result, 'test_mention')

    def test_get_emoticon(self):
        result = self.message.get_emoticon(TestMessage.EMOTICON)
        self.assertEqual(result, 'test_emoticon')

    def test_get_link(self):
        result = self.message.get_link(TestMessage.LINK)
        link_dict = {'url': TestMessage.LINK,
                     'title': 'Example Domain'}
        self.assertEqual(result, link_dict)

    def test_get_title(self):
        title = self.message.get_title(TestMessage.LINK)
        self.assertEqual(title, 'Example Domain')

    def test_get_title_unavailable(self):
        title = self.message.get_title('http://example')
        self.assertEqual(title, None)

@@ -117,67 +117,175 @@
     
-EMOTICON = '(test_emoticon)'%0A    LINK = 'http://example.com
+MENTION_RESULT = 'test_mention'%0A    EMOTICON = '(test_emoticon)'%0A    EMOTICON_RESULT = 'test_emoticon'%0A    LINK = 'http://example.com'%0A    LINK_TITLE = 'Example Domain
 '%0A%0A 
@@ -2155,30 +2155,42 @@
 ions': %5B
-'test_mention'
+TestMessage.MENTION_RESULT
 %5D,%0A     
@@ -2225,31 +2225,43 @@
 cons': %5B
-'test_emoticon'
+TestMessage.EMOTICON_RESULT
 %5D,%0A     
@@ -2370,32 +2370,38 @@
 title': 
-'Example Domain'
+TestMessage.LINK_TITLE
 ,%0A      
@@ -2436,36 +2436,32 @@
  'url': 
-'http://example.com'
+TestMessage.LINK
 %0A       
@@ -3060,38 +3060,50 @@
 ual(result, 
-'test_mention'
+TestMessage.MENTION_RESULT
 )%0A%0A        r
@@ -3168,11 +3168,121 @@
 ION,
- '!
+%0A                                                   '!',%0A                                                   'test
 '%5D))
@@ -3315,30 +3315,42 @@
 result, 
-'test_mention'
+TestMessage.MENTION_RESULT
 )%0A%0A    d
@@ -3475,31 +3475,43 @@
 result, 
-'test_emoticon'
+TestMessage.EMOTICON_RESULT
 )%0A%0A    d

Update test cases for mentions.