Ejemplo n.º 1
0
    def test_extract_leads_from_chats(self):
        operator = Mock()
        operator.email = MagicMock(return_value='*****@*****.**')
        product_reference = 'PF12345'

        with patch.dict(CHAT1['Chat'], {'Operator': operator, 'Customs': {'Imovel': product_reference}}):
            chat_list = [CHAT1]
            actual = extract_leads_from_chats(chat_list)
        expected = {'name': 'Chat #11123 | Ivone Duarte', 'description': 'Can you help me?\nA', 'contact_name': 'Ivone Duarte',
                    'contact_phone': '967961100', 'contact_email': '*****@*****.**', 'operator': operator.email, 'group': 'groupid1', 'product_code': product_reference}
        self.assertEqual(1, len(actual))
        self.assertDictEqual(expected, actual[0])
Ejemplo n.º 2
0
    def test_extract_leads_from_chats_excluding_duplicates1(self):
        """
        Different chats between the same operator and the same client should be merged into a single lead where the
        description is the concatenation of the plain texts of the chats
        """
        operator = Mock()
        operator.email = MagicMock(return_value='*****@*****.**')

        with patch.dict(CHAT1['Chat'], {'Operator': operator}), patch.dict(CHAT2['Chat'], {'Operator': operator}):
            chat_list = [CHAT1, CHAT2]
            actual = extract_leads_from_chats(chat_list)
        expected = {'name': 'Chat #11123 | Ivone Duarte', 'description': 'Can you help me?\nA' + '\n' + 20 * '-' + '\n' + 'Can you help me?\nB', 'contact_name': 'Ivone Duarte',
                    'contact_phone': '967961100', 'contact_email': '*****@*****.**', 'operator': operator.email, 'group': 'groupid1', 'product_code': None}
        self.assertEqual(1, len(actual))
        self.assertDictEqual(expected, actual[0])