Exemplo n.º 1
0
    def test_active_contributors(self):
        """Test active contributors API call."""
        # 2 en-US revisions by 2 contributors:
        r1 = revision(creator=user(save=True), save=True)
        r2 = revision(creator=user(save=True), save=True)
        # A translation with 2 contributors (translator + reviewer):
        d = document(parent=r1.document, locale='es', save=True)
        revision(document=d, reviewed=datetime.now(),
                 reviewer=r1.creator, creator=r2.creator, save=True)
        # 1 active support forum contributor:
        # A user with 10 answers
        u1 = user(save=True)
        for x in range(10):
            answer(save=True, creator=u1)
        # A user with 9 answers
        u2 = user(save=True)
        for x in range(9):
            answer(save=True, creator=u2)
        # A user with 1 answer
        u3 = user(save=True)
        answer(save=True, creator=u3)

        # An AoA reply (1 contributor):
        reply(save=True)

        r = self._get_api_result('kpi_active_contributors')
        eq_(r['objects'][0]['en_us'], 2)
        eq_(r['objects'][0]['non_en_us'], 2)
        eq_(r['objects'][0]['support_forum'], 1)
        eq_(r['objects'][0]['aoa'], 1)
Exemplo n.º 2
0
    def test_active_aoa_contributors(self):
        """Test active AOA contributors API call."""
        # Create a reply
        reply(save=True)

        # There should be only one active contributor.
        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_active_aoa_contributors',
                              'api_name': 'v1'})

        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['contributors'], 1)
Exemplo n.º 3
0
    def setUp(self):
        now = datetime.now()
        two_days_ago = now - timedelta(days=2)
        two_weeks_ago = now - timedelta(days=14)
        two_months_ago = now - timedelta(days=60)

        # Moe has the most in the last day, curly has the most in the last week,
        # larry has the most in the last month, and moe has the most overall.
        data = {
            'moe': [(now, 3), (two_days_ago, 2), (two_months_ago, 20)],
            'curly': [(two_days_ago, 6), (two_weeks_ago, 2)],
            'larry': [(two_weeks_ago, 10), (two_months_ago, 4)]
        }
        for who, what in data.items():
            for when, how_many in what:
                for _ in range(how_many):
                    reply(created=when, twitter_username=who, save=True)
Exemplo n.º 4
0
    def test_active_contributors(self):
        """Test active contributors API call."""
        # 2 en-US revisions by 2 contributors:
        r1 = revision(creator=user(save=True), save=True)
        r2 = revision(creator=user(save=True), save=True)
        # A translation with 2 contributors (translator + reviewer):
        d = document(parent=r1.document, locale='es', save=True)
        revision(document=d,
                 reviewed=datetime.now(),
                 reviewer=r1.creator,
                 creator=r2.creator,
                 save=True)
        # 1 active support forum contributor:
        # A user with 10 answers
        u1 = user(save=True)
        for x in range(10):
            answer(save=True, creator=u1)
        # A user with 9 answers
        u2 = user(save=True)
        for x in range(9):
            answer(save=True, creator=u2)
        # A user with 1 answer
        u3 = user(save=True)
        answer(save=True, creator=u3)

        # An AoA reply (1 contributor):
        reply(save=True)

        # Create metric kinds and update metrics for tomorrow (today's
        # activity shows up tomorrow).
        self._make_contributor_metric_kinds()
        update_contributor_metrics(day=date.today() + timedelta(days=1))

        r = self._get_api_result('kpi_active_contributors')

        eq_(r['objects'][0]['en_us'], 2)
        eq_(r['objects'][0]['non_en_us'], 2)
        eq_(r['objects'][0]['support_forum'], 1)
        eq_(r['objects'][0]['aoa'], 1)
Exemplo n.º 5
0
    def test_active_contributors(self):
        """Test active contributors API call."""
        # 2 en-US revisions by 2 contributors:
        r1 = revision(creator=user(save=True), save=True)
        r2 = revision(creator=user(save=True), save=True)
        # A translation with 2 contributors (translator + reviewer):
        d = document(parent=r1.document, locale='es', save=True)
        revision(document=d, reviewed=datetime.now(),
                 reviewer=r1.creator, creator=r2.creator, save=True)
        # 1 active support forum contributor:
        # A user with 10 answers
        u1 = user(save=True)
        for x in range(10):
            answer(save=True, creator=u1)
        # A user with 9 answers
        u2 = user(save=True)
        for x in range(9):
            answer(save=True, creator=u2)
        # A user with 1 answer
        u3 = user(save=True)
        answer(save=True, creator=u3)

        # An AoA reply (1 contributor):
        reply(save=True)

        # Create metric kinds and update metrics for tomorrow (today's
        # activity shows up tomorrow).
        self._make_contributor_metric_kinds()
        update_contributor_metrics(day=date.today() + timedelta(days=1))

        r = self._get_api_result('kpi_active_contributors')

        eq_(r['objects'][0]['en_us'], 2)
        eq_(r['objects'][0]['non_en_us'], 2)
        eq_(r['objects'][0]['support_forum'], 1)
        eq_(r['objects'][0]['aoa'], 1)
Exemplo n.º 6
0
    def test_count_replies(self):
        """Test filtering when counting tweets"""
        tweet(save=True)
        id = Tweet.latest().tweet_id

        reply(reply_to_tweet_id=id, created=datetime.now(), save=True)
        reply(reply_to_tweet_id=id, created=datetime.now(), save=True)
        reply(created=datetime.now() - timedelta(days=1, minutes=1), save=True)

        yesterday = datetime.now() - timedelta(days=1)
        count_recent_answered = _count_answered_tweets(since=yesterday)
        eq_(count_recent_answered, 1)
Exemplo n.º 7
0
    def test_count_replies(self):
        """Test filtering when counting tweets"""
        tweet(save=True)
        id = Tweet.latest().tweet_id

        reply(reply_to_tweet_id=id, created=datetime.now(), save=True)
        reply(reply_to_tweet_id=id, created=datetime.now(), save=True)
        reply(created=datetime.now() - timedelta(days=1, minutes=1), save=True)

        yesterday = datetime.now() - timedelta(days=1)
        count_recent_answered = _count_answered_tweets(since=yesterday)
        eq_(count_recent_answered, 1)