Example #1
0
def reactivate_user(logged_user, user):
    email = user.email
    user_db = User.objects.coll.find({User.email.db_field: email}).next()
    reactivated_user = User(user_db)
    reactivated_user.is_archived = False
    logged_user.current_account.add_perm(reactivated_user)
    reactivated_user.save()
    return True
 def _make_agent(self, n, account):
     u = User(agent_id=n + 100, email="*****@*****.**" % (n + 100))
     u.save()
     account.add_user(u)
     return u
Example #3
0
    def test_status(self):
        from solariat_bottle.db.user import User
        agent = User(email='*****@*****.**')
        agent.signature = '^AG'
        agent.save()
        self.sc.account.add_user(agent)

        # Create inbound post
        self.inbound_post_created_at = parse_date("05/07/2013")
        parent_id = "123456789"
        twitter_data = {
            'twitter': {
                'id': parent_id,
                'created_at':
                datasift_date_format(self.inbound_post_created_at)
            }
        }
        self.inbound_post = self._create_db_post(
            channels=[self.inbound],
            content="@brand I need a foo. Does anyone have a foo? ",
            **twitter_data)
        self.inbound_post.reload()
        self.assertTrue(self.inbound.is_assigned(self.inbound_post))

        agents = None
        inbound_post = self.get_inbound_post()
        self.assertEqual(len(inbound_post.channel_assignments), 1)
        self.assertEqual(
            inbound_post.channel_assignments[str(self.inbound.id)],
            'highlighted')

        stats = self.get_inbound_stats(agents)
        self.assertEqual(stats[SpeechActMap.POTENTIAL], 0)
        self.assertEqual(stats[SpeechActMap.ACTUAL], 0)
        self.assertEqual(stats[SpeechActMap.ACTIONABLE], 2)
        self.assertEqual(stats[SpeechActMap.REJECTED], 0)

        # Reply to inbound post
        twitter_data['twitter']['id'] = '987654231'
        twitter_data['twitter']['in_reply_to_status_id'] = parent_id
        twitter_data['twitter']['created_at'] = datasift_date_format(now())
        self.outbound_post = self._create_db_post(
            user_profile={'user_name': 'agent_test_name'},
            channels=[self.outbound],
            content="Response content. ^AG",
            **twitter_data)

        self.inbound_post.reload()
        self.outbound_post.reload()

        for agents in (None, [agent]):
            stats = self.get_inbound_stats(agents)
            self.assertEqual(stats[SpeechActMap.POTENTIAL], 0)
            self.assertEqual(stats[SpeechActMap.ACTUAL], 2)
            self.assertEqual(stats[SpeechActMap.ACTIONABLE], 0)
            self.assertEqual(stats[SpeechActMap.REJECTED], 0)

            stats = self.get_outbound_stats(agents)
            self.assertEqual(stats[SpeechActMap.POTENTIAL], 0)
            self.assertEqual(stats[SpeechActMap.ACTUAL], 0)
            self.assertEqual(stats[SpeechActMap.ACTIONABLE], 1)
            self.assertEqual(stats[SpeechActMap.REJECTED], 0)

        self.assertEqual(
            self.inbound_post.channel_assignments[str(self.inbound.id)],
            'replied')
        self.assertEqual(len(self.inbound_post.channel_assignments), 1)

        inbound_post = self.get_inbound_post()
        self.assertEqual(len(inbound_post.channel_assignments), 1)
        self.assertEqual(
            inbound_post.channel_assignments[str(self.inbound.id)], 'replied')