<commit_before>import test_utils
from nose.tools import eq_

from addons.models import Addon
from stats import tasks
from stats.models import GlobalStat, Contribution


class TestGlobalStats(test_utils.TestCase):

    fixtures = ['stats/test_models']

    def test_stats_for_date(self):

        date = '2009-06-01'
        job = 'addon_total_downloads'

        eq_(GlobalStat.objects.no_cache().filter(date=date,
                                                 name=job).count(), 0)
        tasks.update_global_totals(job, date)
        eq_(len(GlobalStat.objects.no_cache().filter(date=date,
                                                 name=job)), 1)


class TestTotalContributions(test_utils.TestCase):
    fixtures = ['base/fixtures']

    def test_total_contributions(self):

        c = Contribution()
        c.addon_id = 3615
        c.amount = '9.99'
        c.save()

        tasks.addon_total_contributions(3615)
        a = Addon.objects.no_cache().get(pk=3615)
        eq_(float(a.total_contributions), 9.99)

        c = Contribution()
        c.addon_id = 3615
        c.amount = '10.00'
        c.save()

        tasks.addon_total_contributions(3615)
        a = Addon.objects.no_cache().get(pk=3615)
        eq_(float(a.total_contributions), 19.99)

<commit_msg>stats.cron tests take <3s instead of >3s<commit_after>import test_utils
from nose.tools import eq_

from addons.models import Addon
from stats import tasks
from stats.models import GlobalStat, Contribution


class TestGlobalStats(test_utils.TestCase):

    fixtures = ['stats/test_models']

    def test_stats_for_date(self):

        date = '2009-06-01'
        job = 'addon_total_downloads'

        eq_(GlobalStat.objects.no_cache().filter(date=date,
                                                 name=job).count(), 0)
        tasks.update_global_totals(job, date)
        eq_(len(GlobalStat.objects.no_cache().filter(date=date,
                                                 name=job)), 1)


class TestTotalContributions(test_utils.TestCase):
    fixtures = ['base/addon_3615']

    def test_total_contributions(self):

        c = Contribution()
        c.addon_id = 3615
        c.amount = '9.99'
        c.save()

        tasks.addon_total_contributions(3615)
        a = Addon.objects.no_cache().get(pk=3615)
        eq_(float(a.total_contributions), 9.99)

        c = Contribution()
        c.addon_id = 3615
        c.amount = '10.00'
        c.save()

        tasks.addon_total_contributions(3615)
        a = Addon.objects.no_cache().get(pk=3615)
        eq_(float(a.total_contributions), 19.99)


{'fraction_non_alphanumeric': 0.10880430603613994, 'fraction_numerical': 0.0392156862745098, 'mean_word_length': 2.2443890274314215, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1437434', 'n_tokens_mistral': 895, 'n_tokens_neox': 799, 'n_words': 140}