<commit_before>from django.contrib.auth.models import User
from django.test import TestCase

from demo_esutils.models import Category
from demo_esutils.models import Article
from demo_esutils.mappings import ArticleMappingType as M


class MappingTestCase(TestCase):

    def setUp(self):

        M.update_mapping()

        self.florent = User.objects.create(username='florent',
                                           email='<EMAIL>')

        self.louise = User.objects.create(username='louise',
                                          email='<EMAIL>')

    def tearDown(self):
        self.florent.delete()
        self.louise.delete()

        Category.objects.all().delete()
        Article.objects.all().delete()
        M.refresh_index()

    def test_index(self):

        # keep previous indexed objec count
        prev_count = M.count()

        # create an article
        category = Category.objects.create(name='The Tests')

        article1 = Article()
        article1.author = self.florent
        article1.category = category
        article1.content = '!'
        article1.subject = 'make it works'

        article2 = Article()
        article2.author = self.louise
        article2.category = category
        article2.content = 'yo'
        article2.subject = 'My amazing article'

        for i, art in enumerate([article1, article2]):
            # save
            art.save()
            # refresh index
            M.refresh_index()
            # check added
            add_count = M.count()
            self.assertEqual(add_count, prev_count + i + 1)

        self.assertEqual(M.query(subject__match='My Am').count(), 1)
        self.assertEqual(M.query(subject__match='WorkS').count(), 1)
        self.assertEqual(M.query(subject__match='works').count(), 1)
        self.assertEqual(M.query(subject__prefix='amaz').count(), 1)
        self.assertEqual(M.query(subject__match='amaz').count(), 0)

        self.assertEqual(M.query(author__username__prefix='lo').count(), 1)
        self.assertEqual(M.query(author__username__match='Louise').count(), 1)

        self.assertEqual(M.query(category__name__prefix='tes').count(), 2)
        self.assertEqual(M.query(category__name__term='tes').count(), 0)
        self.assertEqual(M.query(category__name__term='tests').count(), 2)

        # update some contents
        Article.objects.filter(author=self.louise).update(subject='hey #tgif')

        # reindex all<commit_msg>Updates tests.<commit_after>from django.contrib.auth.models import User
from django.test import TestCase

from demo_esutils.models import Category
from demo_esutils.models import Article
from demo_esutils.mappings import ArticleMappingType as M


class MappingTestCase(TestCase):

    def setUp(self):

        M.update_mapping()

        self.florent = User.objects.create(username='florent',
                                           email='<EMAIL>')

        self.louise = User.objects.create(username='louise',
                                          email='<EMAIL>')

    def tearDown(self):
        self.florent.delete()
        self.louise.delete()

        Category.objects.all().delete()
        Article.objects.all().delete()
        M.refresh_index()

    def test_index(self):

        # keep previous indexed objec count
        prev_count = M.count()

        # create an article
        category = Category.objects.create(name='The Tests')

        article1 = Article()
        article1.author = self.florent
        article1.category = category
        article1.content = '!'
        article1.subject = 'make it works'

        article2 = Article()
        article2.author = self.louise
        article2.category = category
        article2.content = 'yo'
        article2.subject = 'My amazing article'

        for i, art in enumerate([article1, article2]):
            # save
            art.save()
            # refresh index
            M.refresh_index()
            # check added
            add_count = M.count()
            self.assertEqual(add_count, prev_count + i + 1)

        self.assertEqual(M.query(subject__match='My Am').count(), 1)
        self.assertEqual(M.query(subject__match='WorkS').count(), 1)
        self.assertEqual(M.query(subject__match='works').count(), 1)
        self.assertEqual(M.query(subject__prefix='amaz').count(), 1)
        self.assertEqual(M.query(subject__match='amaz').count(), 0)

        self.assertEqual(M.query(**{'author-username__prefix':'lo'}).count(), 1)
        self.assertEqual(M.query(**{'author-username__match':'Louise'}).count(), 1)

        self.assertEqual(M.query(**{'category-name__prefix': 'tes'}).count(), 2)
        self.assertEqual(M.query(**{'category-name__term': 'tes'}).count(), 0)
        self.assertEqual(M.query(**{'category-name__term': 'tests'}).count(), 2)

        # update some contents
        Article.objects.filter(author=self.louise).update(subject='hey #tgif')

        # reindex all
{'fraction_non_alphanumeric': 0.12790933009512245, 'fraction_numerical': 0.009309856304391824, 'mean_word_length': 2.4343293954134815, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '892859', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1339, 'n_words': 253}