Ejemplo n.º 1
0
 def _apply_post(self, speaker, content):
     if speaker == csm.CONTACT:
         url = fake_twitter_url(self.contact_screen_name)
         return self._create_db_post(channel=self.sc.inbound,
                                     content=content,
                                     demand_matchables=False,
                                     url=url,
                                     user_profile=self.contact_user_profile)
     else:
         url = fake_twitter_url(self.brand_screen_name)
         return self._create_db_post(channel=self.sc.outbound,
                                     content="%s %s" %
                                     (self.contact_screen_name, content),
                                     url=url,
                                     user_profile=self.brand_user_profile)
Ejemplo n.º 2
0
    def _create_posts(self):
        """2 contacts posting 4 posts each.
        """
        posts = []
        posts_content = [
            "@test I need a laptop", "@test I like a laptop",
            "@test I need a foo.", "@test Can someone recommend a laptop?"
        ]

        def creation_loop(user_profile):
            for content in posts_content:
                url = fake_twitter_url(user_profile.screen_name)
                posts.append(
                    self._create_db_post(channel=self.inbound,
                                         content=content,
                                         demand_matchables=False,
                                         url=url,
                                         user_profile=user_profile))

        creation_loop(self.contact)

        self.contact2 = UserProfile.objects.upsert(
            'Twitter', dict(screen_name='@customer'))
        url = fake_twitter_url(self.contact.screen_name)
        creation_loop(self.contact2)
        return posts
Ejemplo n.º 3
0
 def creation_loop(user_profile):
     for content in posts_content:
         url = fake_twitter_url(user_profile.screen_name)
         posts.append(
             self._create_db_post(channel=self.inbound,
                                  content=content,
                                  demand_matchables=False,
                                  url=url,
                                  user_profile=user_profile))
Ejemplo n.º 4
0
    def _create_post(self, content):
        """
        Creates a post and appends it to ``self.posts``"""

        url = fake_twitter_url(self.user_profile.screen_name)
        self.posts.append(
            self._create_db_post(channel=self.inbound,
                                 content=content,
                                 demand_matchables=False,
                                 url=url,
                                 user_profile=self.user_profile))
Ejemplo n.º 5
0
    def test_multi_agent_scenario(self):
        # two inbound channels for an account
        # one is with two brands (brand1, brand2), another with one (brand1).
        sc1 = self.make_service_channel("SC1", ['brand1', 'brand2'])
        # sc2
        sc2 = self.make_service_channel("SC2", ['brand1'])
        # Create outbound channel with brand1
        # dc
        self.make_dispatch_channel("DC", 'brand1', self.user)
        # Create a post to brand2
        screen_name = 'Customer'
        user_profile = UserProfile.objects.upsert(
            'Twitter', dict(screen_name=screen_name))
        user_brand = UserProfile.objects.upsert('Twitter',
                                                dict(screen_name='brand1'))
        url = fake_twitter_url(screen_name)
        post = self._create_db_post(channel=sc1.inbound_channel,
                                    content="@brand2 I need a laptop",
                                    demand_matchables=True,
                                    url=url,
                                    user_profile=user_profile)

        # Reply to that post
        # with LoggerInterceptor() as logs:
        reply = self._create_tweet(
            user_profile=user_brand,
            channels=[sc1.outbound_channel, sc2.outbound_channel],
            content="Reply to inbound post about laptop",
            in_reply_to=post)
        # warning_message = "Post %s channels=%s is not from service channel %s(%s): inbound=%s, outbound=%s" % (
        #     post, map(str, post.channels), sc2, sc2.title, sc2.inbound, sc2.outbound)
        # for entry in logs:
        #     if entry.message == warning_message:
        #         self.assertEqual(entry.levelname, 'WARNING')
        #         break
        # else:
        #     self.fail("Did not find " + warning_message + " in logs " + str([l.message for l in logs]))
        post.reload()
        self.assertEqual(post.get_assignment(sc1.inbound_channel), 'replied')
        self.assertEqual(post.get_assignment(sc2.inbound_channel), None)
Ejemplo n.º 6
0
    def setUp(self):
        super(UnsubscribeTestCase, self).setUp()
        self.i = self.sc.inbound_channel
        self.o = self.sc.outbound_channel
        self.o.usernames = ['solariat']
        self.o.save()

        # Create 2 Smart Tags, for different use keywords
        self.laptop_tag = self._create_smart_tag(self.i,
                                                 'Laptops Tag',
                                                 status='Active',
                                                 keywords=['laptop'])
        self.laptop_tag_outbound = self._create_smart_tag(self.o,
                                                          'Laptops Tag',
                                                          status='Active',
                                                          keywords=['laptop'])
        self.other_tag = self._create_smart_tag(self.i,
                                                'Other Tag',
                                                status='Active',
                                                keywords=['support', 'help'])
        self.other_tag_outbound = self._create_smart_tag(
            self.o, 'Other Tag', status='Active', keywords=['support', 'help'])

        url = fake_twitter_url(self.customer.user_name)
Ejemplo n.º 7
0
 def setUp(self):
     super(ConversationSTMPolicyCase, self).setUp()
     csm.POLICY_MAP['DEFAULT'] = csm.SimplePolicy()
     fake_twitter_url(self.contact_screen_name)
     fake_twitter_url(self.brand_screen_name)
Ejemplo n.º 8
0
    def test_stats_recompute(self):
        url = fake_twitter_url(self.contact.screen_name)
        posts_content = [
            "@test I need a laptop", "@test I like a laptop",
            "@test I need a foo.", "@test Can someone recommend a laptop?"
        ]

        previous_post = None
        for content in posts_content:
            url = fake_twitter_url(self.contact.screen_name)
            previous_post = self._create_db_post(channel=self.inbound,
                                                 content=content,
                                                 demand_matchables=False,
                                                 url=url,
                                                 user_profile=self.contact)
        # reply to some posts - first posts from the first contact
        self._create_tweet(user_profile=self.support,
                           content="We are doing our best",
                           channel=self.outbound,
                           in_reply_to=previous_post,
                           url=fake_twitter_url(self.support.screen_name))
        url = fake_twitter_url(self.contact.screen_name)
        last_post = self._create_db_post(
            channel=self.inbound,
            content="I am also having car problems!",
            demand_matchables=False,
            url=url,
            user_profile=self.contact)
        last_post.handle_reject(self.support, [self.inbound])

        stats_tasks.MAX_BATCH_SIZE = 1

        to_date = now()
        from_date = now() - relativedelta(days=30)
        self._store_existing_data()
        # Just recomputing the stats should give us the same results
        do_it(account_name=self.inbound.account.name,
              ignore_purging=False,
              from_date=from_date,
              to_date=to_date)
        self.assertTrue(ChannelTopicTrends.objects.count() == self.ctt_count)
        self.assertTrue(ChannelHotTopics.objects.count() == self.cht_count)
        self.assertEqual(ChannelTrends.objects.count(), self.ct_count)
        self._compare_existing_data()
        do_it(account_name=self.inbound.account.name,
              ignore_purging=True,
              from_date=from_date,
              to_date=to_date)
        self.assertTrue(ChannelTopicTrends.objects.count() == self.ctt_count)
        self.assertTrue(ChannelHotTopics.objects.count() == self.cht_count)
        self.assertEqual(ChannelTrends.objects.count(), self.ct_count)
        self._compare_existing_data()

        # Now if we remove existing data we should get rhoughly the same results
        # Stats with counts of 0 won't matter anymore
        self._clear_existing_data()
        do_it(account_name=self.inbound.account.name,
              ignore_purging=True,
              from_date=from_date,
              to_date=to_date)
        # We had actionable switched to actual / rejected. In db we don't remove entries where count=0
        # So now that we cleared all then recomputed (recovery mode) we will have less entries
        self.assertTrue(ChannelTopicTrends.objects.count() < self.ctt_count)
        self.assertTrue(ChannelHotTopics.objects.count() < self.cht_count)
        self.assertTrue(ChannelTrends.objects.count() < self.ct_count)
        self._compare_existing_data()