<commit_before>from datetime import date
import re
from unittest import TestCase

from django.test.client import Client
from mock import patch

from regulations.views.partial_search import *


class PartialSearchTest(TestCase):
    """Integration tests for search"""

    @patch('regulations.views.partial_search.api_reader')
    @patch('regulations.views.partial_search.fetch_grouped_history')
    def test_get(self, fetch_grouped_history, api_reader):
        api_reader.ApiReader.return_value.search.return_value = {
            'total_hits': 3333,
            'results': [
                {'label': ['111', '22'], 'text': 'tttt', 'version': 'vvv', 'title':"consumer's"},
                {'label': ['111', '24', 'a'], 'text': 'o', 'version': 'vvv'},
                {'label': ['111', '25'], 'text': 'more', 'version': 'vvv'}
            ]
        }
        fetch_grouped_history.return_value = [
            {'notices': [{'document_number': 'bbb',
                          'effective_on': date(2012, 12, 12)}]},
            {'notices': [{'document_number': 'ccc',
                          'effective_on': date(2001, 1, 1)},
                         {'document_number': 'vvv',
                          'effective_on': date(2003, 4, 5)}],
             'timeline': 'timeytimey'}
        ]
        response = Client().get('/partial/search/111?version=vvv&q=none')
        self.assertTrue('111-22' in response.content)
        self.assertTrue('111.22' in response.content)
        self.assertTrue('111-24-a' in response.content)
        self.assertTrue('111.24(a)' in response.content)
        self.assertTrue('111-25' in response.content)
        self.assertTrue('111.25' in response.content)
        self.assertTrue('3333' in response.content)
        self.assertTrue('Consumer&#39;s' in response.content)

    @patch('regulations.views.partial_search.api_reader')
    @patch('regulations.views.partial_search.fetch_grouped_history')
    def test_root_info(self, fetch_grouped_history, api_reader):
        api_reader.ApiReader.return_value.search.return_value = {
            'total_hits': 3,
            'results': [
                {'label': ['111', '22'], 'text': 'tttt', 'version': 'vvv', 'title':"consumer's"},
                {'label': ['111', '24', 'a'], 'text': 'o', 'version': 'vvv'},
                {'label': ['111'], 'text': 'more', 'version': 'vvv'}
            ]
        }
        fetch_grouped_history.return_value = [
            {'notices': [{'document_number': 'bbb',
                          'effective_on': date(2012, 12, 12)}]},
            {'notices': [{'document_number': 'ccc',
                          'effective_on': date(2001, 1, 1)},
                         {'document_number': 'vvv',
                          'effective_on': date(2003, 4, 5)}],
             'timeline': 'timeytimey'}
        ]
        response = Client().get('/partial/search/111?version=vvv&q=none')
        self.assertTrue('2 results' in response.content)

    @patch('regulations.views.partial_search.api_reader')
    @patch('regulations.views.partial_search.fetch_grouped_history')
    def test_no_results(self, fetch_grouped_history, api_reader):
        api_reader.ApiReader.return_value.search.return_value = {
            'total_hits': 0,
            'results': []
        }
        fetch_grouped_history.return_value = [
            {'notices': [{'document_number': 'bbb',
                          'effective_on': date(2012, 12, 12)}]},<commit_msg>Caching messes up travis?<commit_after>from datetime import date
import re
from unittest import TestCase

from django.test.client import Client
from mock import patch

from regulations.views.partial_search import *


class PartialSearchTest(TestCase):
    """Integration tests for search"""

    @patch('regulations.views.partial_search.api_reader')
    @patch('regulations.views.partial_search.fetch_grouped_history')
    def test_get(self, fetch_grouped_history, api_reader):
        api_reader.ApiReader.return_value.search.return_value = {
            'total_hits': 3333,
            'results': [
                {'label': ['111', '22'], 'text': 'tttt', 'version': 'vvv', 'title':"consumer's"},
                {'label': ['111', '24', 'a'], 'text': 'o', 'version': 'vvv'},
                {'label': ['111', '25'], 'text': 'more', 'version': 'vvv'}
            ]
        }
        fetch_grouped_history.return_value = [
            {'notices': [{'document_number': 'bbb',
                          'effective_on': date(2012, 12, 12)}]},
            {'notices': [{'document_number': 'ccc',
                          'effective_on': date(2001, 1, 1)},
                         {'document_number': 'vvv',
                          'effective_on': date(2003, 4, 5)}],
             'timeline': 'timeytimey'}
        ]
        response = Client().get('/partial/search/111?version=vvv&q=none')
        self.assertTrue('111-22' in response.content)
        self.assertTrue('111.22' in response.content)
        self.assertTrue('111-24-a' in response.content)
        self.assertTrue('111.24(a)' in response.content)
        self.assertTrue('111-25' in response.content)
        self.assertTrue('111.25' in response.content)
        self.assertTrue('3333' in response.content)
        self.assertTrue('Consumer&#39;s' in response.content)

    @patch('regulations.views.partial_search.api_reader')
    @patch('regulations.views.partial_search.fetch_grouped_history')
    def test_root_info(self, fetch_grouped_history, api_reader):
        api_reader.ApiReader.return_value.search.return_value = {
            'total_hits': 3,
            'results': [
                {'label': ['444', '22'], 'text': 'tttt', 'version': 'vvv', 'title':"consumer's"},
                {'label': ['444', '24', 'a'], 'text': 'o', 'version': 'vvv'},
                {'label': ['444'], 'text': 'more', 'version': 'vvv'}
            ]
        }
        fetch_grouped_history.return_value = [
            {'notices': [{'document_number': 'bbb',
                          'effective_on': date(2012, 12, 12)}]},
            {'notices': [{'document_number': 'ccc',
                          'effective_on': date(2001, 1, 1)},
                         {'document_number': 'vvv',
                          'effective_on': date(2003, 4, 5)}],
             'timeline': 'timeytimey'}
        ]
        response = Client().get('/partial/search/444?version=vvv&q=none')
        self.assertTrue('2 results' in response.content)

    @patch('regulations.views.partial_search.api_reader')
    @patch('regulations.views.partial_search.fetch_grouped_history')
    def test_no_results(self, fetch_grouped_history, api_reader):
        api_reader.ApiReader.return_value.search.return_value = {
            'total_hits': 0,
            'results': []
        }
        fetch_grouped_history.return_value = [
            {'notices': [{'document_number': 'bbb',
                          'effective_on': date(2012, 12, 12)}]},
{'fraction_non_alphanumeric': 0.16075547866205306, 'fraction_numerical': 0.036043829296424454, 'mean_word_length': 2.410521140609636, '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': '5823457', 'n_tokens_mistral': 2244, 'n_tokens_neox': 2053, 'n_words': 378}