<commit_before>from django.core.management import call_command
from django.test import TestCase

from haystack.query import SearchQuerySet

from .models import Note


class QueuedSearchIndexTestCase(TestCase):

    def assertSearchResultLength(self, count):
        self.assertEqual(count, len(SearchQuerySet()))

    def assertSearchResultContains(self, pk, text):
        results = SearchQuerySet().filter(id='tests.note.%s' % pk)
        self.assertTrue(results)
        self.assertTrue(text in results[0].text)

    def setUp(self):
        # Nuke the index.
        call_command('clear_index', interactive=False, verbosity=0)

        # Throw away all Notes
        Note.objects.all().delete()
<commit_msg>Use TransactionTestCase to run on_commit hooks<commit_after>from django.core.management import call_command
from django.test import TransactionTestCase

from haystack.query import SearchQuerySet

from .models import Note


class QueuedSearchIndexTestCase(TransactionTestCase):

    def assertSearchResultLength(self, count):
        self.assertEqual(count, len(SearchQuerySet()))

    def assertSearchResultContains(self, pk, text):
        results = SearchQuerySet().filter(id='tests.note.%s' % pk)
        self.assertTrue(results)
        self.assertTrue(text in results[0].text)

    def setUp(self):
        # Nuke the index.
        call_command('clear_index', interactive=False, verbosity=0)

        # Throw away all Notes
        Note.objects.all().delete()

{'fraction_non_alphanumeric': 0.0961408259986459, 'fraction_numerical': 0.002708192281651997, 'mean_word_length': 3.7987012987012987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2860849', 'n_tokens_mistral': 408, 'n_tokens_neox': 399, 'n_words': 99}