def test_en_search_no_term(self, mock_ask_search):
     mock_ask_search.queryset = mock_queryset()
     response = self.client.get(reverse("ask-search-en"), {"q": ""})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context_data["page"], self.en_page)
     self.assertEqual(response.context_data["page"].query, "")
     self.assertEqual(response.context_data["page"].result_query, "")
 def test_en_search(self, mock_ask_search):
     mock_ask_search.queryset = mock_queryset(count=3)
     mock_ask_search.suggestion = None
     mock_ask_search.search_term = "payday"
     response = self.client.get(reverse("ask-search-en"), {"q": "payday"})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context_data["page"], self.en_page)
     self.assertEqual(mock_ask_search.call_count, 1)
     self.assertTrue(
         mock_ask_search.called_with(language="en", search_term="payday"))
 def test_search_page_en_selection(self, mock_search):
     mock_search.search_term = "tuition"
     mock_search.queryset = mock_queryset(count=1)
     response = self.client.get(reverse("ask-search-en"), {"q": "tuition"})
     self.assertEqual(mock_search.call_count, 1)
     self.assertEqual(response.context_data.get("page").language, "en")
     self.assertEqual(
         self.en_page.get_template(HttpRequest()),
         "ask-cfpb/answer-search-results.html",
     )
 def test_en_search_suggestion(self, mock_filter, mock_suggestion):
     # AskSearch.sugggest flips search_term and suggestion when called
     mock_filter.return_value = mock_queryset(count=0)
     mock_suggestion.return_value = "payday"
     response = self.client.get(reverse("ask-search-en"), {"q": "paydya"})
     self.assertEqual(response.status_code, 200)
     response_page = response.context_data["page"]
     self.assertEqual(response_page, self.en_page)
     self.assertEqual(response_page.result_query, "payday")
     self.assertEqual(response_page.query, "paydya")
 def test_search_page_es_selection(self, mock_search):
     mock_search.search_term = "hipotecas"
     mock_search.queryset = mock_queryset(count=5)
     response = self.client.get(
         reverse("ask-search-es", kwargs={"language": "es"}),
         {"q": "hipotecas"},
     )
     self.assertEqual(self.es_page.answers, [])
     self.assertEqual(mock_search.call_count, 1)
     self.assertEqual(response.context_data["page"].language, "es")
     self.assertEqual(
         self.es_page.get_template(HttpRequest()),
         "ask-cfpb/answer-search-results.html",
     )
 def test_en_search_no_term(self, mock_ask_search):
     from v1.util.migrations import get_or_create_page
     mock_page = get_or_create_page(apps,
                                    'ask_cfpb',
                                    'AnswerResultsPage',
                                    'Mock results page',
                                    'ask-cfpb-search-results',
                                    self.ROOT_PAGE,
                                    language='en')
     mock_ask_search.queryset = mock_queryset()
     response = self.client.get(reverse('ask-search-en'), {'q': ''})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context_data['page'], mock_page)
     self.assertEqual(response.context_data['page'].query, '')
     self.assertEqual(response.context_data['page'].result_query, '')
 def test_search_page_en_selection(self, mock_search):
     page = get_or_create_page(apps,
                               'ask_cfpb',
                               'AnswerResultsPage',
                               'Mock results page',
                               'ask-cfpb-search-results',
                               self.english_parent_page,
                               language='en',
                               live=True)
     mock_search.serch_term = 'tuition'
     mock_search.queryset = mock_queryset(count=1)
     response = self.client.get(reverse('ask-search-en'), {'q': 'tuition'})
     self.assertEqual(mock_search.call_count, 1)
     self.assertEqual(response.context_data.get('page').language, 'en')
     self.assertEqual(page.get_template(HttpRequest()),
                      'ask-cfpb/answer-search-results.html')
 def test_es_search(self, mock_ask_search):
     get_or_create_page(apps,
                        'ask_cfpb',
                        'AnswerResultsPage',
                        'Mock Spanish results page',
                        'respuestas',
                        self.spanish_parent_page,
                        language='es',
                        live=True)
     mock_ask_search.queryset = mock_queryset(count=1)
     mock_ask_search.suggestion = None
     mock_ask_search.search_term = 'payday'
     self.client.get(reverse('ask-search-es', kwargs={'language': 'es'}),
                     {'q': 'payday'})
     self.assertEqual(mock_ask_search.call_count, 1)
     self.assertTrue(
         mock_ask_search.called_with(language='es', search_term='payday'))
 def test_json_response(self, mock_filter, mock_suggestion):
     get_or_create_page(apps,
                        'ask_cfpb',
                        'AnswerResultsPage',
                        'Mock results page',
                        'ask-cfpb-search-results',
                        self.english_parent_page,
                        language='en',
                        live=True)
     mock_suggestion.return_value = 'tuition'
     mock_filter.count.return_value = 5
     mock_filter.return_value = mock_queryset(count=5)
     response = self.client.get(
         reverse('ask-search-en-json', kwargs={'as_json': 'json'}),
         {'q': 'tuition'})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(mock_filter.call_count, 1)
     self.assertEqual(json.loads(response.content)['query'], 'tuition')
Beispiel #10
0
    def test_en_search_no_term(self, mock_ask_search):
        from v1.util.migrations import get_or_create_page

        mock_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerResultsPage",
            "Mock results page",
            "ask-cfpb-search-results",
            self.ROOT_PAGE,
            language="en",
        )
        mock_ask_search.queryset = mock_queryset()
        response = self.client.get(reverse("ask-search-en"), {"q": ""})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data["page"], mock_page)
        self.assertEqual(response.context_data["page"].query, "")
        self.assertEqual(response.context_data["page"].result_query, "")
 def test_search_page_es_selection(self, mock_search):
     page = get_or_create_page(apps,
                               'ask_cfpb',
                               'AnswerResultsPage',
                               'Mock Spanish results page',
                               'respuestas',
                               self.spanish_parent_page,
                               language='es',
                               live=True)
     mock_search.serch_term = 'hipotecas'
     mock_search.queryset = mock_queryset(count=5)
     response = self.client.get(
         reverse('ask-search-es', kwargs={'language': 'es'}),
         {'q': 'hipotecas'})
     self.assertEqual(page.answers, [])
     self.assertEqual(mock_search.call_count, 1)
     self.assertEqual(response.context_data['page'].language, 'es')
     self.assertEqual(page.get_template(HttpRequest()),
                      'ask-cfpb/answer-search-results.html')
    def test_en_search(self, mock_ask_search):
        from v1.util.migrations import get_or_create_page
        mock_page = get_or_create_page(apps,
                                       'ask_cfpb',
                                       'AnswerResultsPage',
                                       'Mock results page',
                                       'ask-cfpb-search-results',
                                       self.ROOT_PAGE,
                                       language='en')

        mock_ask_search.queryset = mock_queryset(count=3)
        mock_ask_search.suggestion = None
        mock_ask_search.search_term = 'payday'
        response = self.client.get(reverse('ask-search-en'), {'q': 'payday'})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['page'], mock_page)
        self.assertEqual(mock_ask_search.call_count, 1)
        self.assertTrue(
            mock_ask_search.called_with(language='en', search_term='payday'))
Beispiel #13
0
 def test_search_page_en_selection(self, mock_search):
     page = get_or_create_page(
         apps,
         "ask_cfpb",
         "AnswerResultsPage",
         "Mock results page",
         "ask-cfpb-search-results",
         self.english_parent_page,
         language="en",
         live=True,
     )
     mock_search.serch_term = "tuition"
     mock_search.queryset = mock_queryset(count=1)
     response = self.client.get(reverse("ask-search-en"), {"q": "tuition"})
     self.assertEqual(mock_search.call_count, 1)
     self.assertEqual(response.context_data.get("page").language, "en")
     self.assertEqual(
         page.get_template(HttpRequest()),
         "ask-cfpb/answer-search-results.html",
     )
    def test_en_search_suggestion(self, mock_filter, mock_suggestion):
        from v1.util.migrations import get_or_create_page
        mock_page = get_or_create_page(apps,
                                       'ask_cfpb',
                                       'AnswerResultsPage',
                                       'Mock results page',
                                       'ask-cfpb-search-results',
                                       self.english_parent_page,
                                       language='en',
                                       live=True)

        # AskSearch.sugggest flips search_term and suggestion when called
        mock_filter.return_value = mock_queryset(count=0)
        mock_suggestion.return_value = 'payday'
        response = self.client.get(reverse('ask-search-en'), {'q': 'paydya'})
        self.assertEqual(response.status_code, 200)
        response_page = response.context_data['page']
        self.assertEqual(response_page, mock_page)
        self.assertEqual(response_page.result_query, 'payday')
        self.assertEqual(response_page.query, 'paydya')
Beispiel #15
0
 def test_json_response(self, mock_filter, mock_suggestion):
     get_or_create_page(
         apps,
         "ask_cfpb",
         "AnswerResultsPage",
         "Mock results page",
         "ask-cfpb-search-results",
         self.english_parent_page,
         language="en",
         live=True,
     )
     mock_suggestion.return_value = "tuition"
     mock_filter.count.return_value = 5
     mock_filter.return_value = mock_queryset(count=5)
     response = self.client.get(
         reverse("ask-search-en-json", kwargs={"as_json": "json"}),
         {"q": "tuition"},
     )
     self.assertEqual(response.status_code, 200)
     self.assertEqual(mock_filter.call_count, 1)
     self.assertEqual(json.loads(response.content)["query"], "tuition")
Beispiel #16
0
 def test_es_search(self, mock_ask_search):
     get_or_create_page(
         apps,
         "ask_cfpb",
         "AnswerResultsPage",
         "Mock Spanish results page",
         "respuestas",
         self.spanish_parent_page,
         language="es",
         live=True,
     )
     mock_ask_search.queryset = mock_queryset(count=1)
     mock_ask_search.suggestion = None
     mock_ask_search.search_term = "payday"
     self.client.get(
         reverse("ask-search-es", kwargs={"language": "es"}),
         {"q": "payday"},
     )
     self.assertEqual(mock_ask_search.call_count, 1)
     self.assertTrue(
         mock_ask_search.called_with(language="es", search_term="payday"))
Beispiel #17
0
    def test_en_search(self, mock_ask_search):
        from v1.util.migrations import get_or_create_page

        mock_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerResultsPage",
            "Mock results page",
            "ask-cfpb-search-results",
            self.ROOT_PAGE,
            language="en",
        )

        mock_ask_search.queryset = mock_queryset(count=3)
        mock_ask_search.suggestion = None
        mock_ask_search.search_term = "payday"
        response = self.client.get(reverse("ask-search-en"), {"q": "payday"})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data["page"], mock_page)
        self.assertEqual(mock_ask_search.call_count, 1)
        self.assertTrue(
            mock_ask_search.called_with(language="en", search_term="payday"))
Beispiel #18
0
    def test_en_search_suggestion(self, mock_filter, mock_suggestion):
        from v1.util.migrations import get_or_create_page

        mock_page = get_or_create_page(
            apps,
            "ask_cfpb",
            "AnswerResultsPage",
            "Mock results page",
            "ask-cfpb-search-results",
            self.english_parent_page,
            language="en",
            live=True,
        )

        # AskSearch.sugggest flips search_term and suggestion when called
        mock_filter.return_value = mock_queryset(count=0)
        mock_suggestion.return_value = "payday"
        response = self.client.get(reverse("ask-search-en"), {"q": "paydya"})
        self.assertEqual(response.status_code, 200)
        response_page = response.context_data["page"]
        self.assertEqual(response_page, mock_page)
        self.assertEqual(response_page.result_query, "payday")
        self.assertEqual(response_page.query, "paydya")
Beispiel #19
0
 def test_search_page_es_selection(self, mock_search):
     page = get_or_create_page(
         apps,
         "ask_cfpb",
         "AnswerResultsPage",
         "Mock Spanish results page",
         "respuestas",
         self.spanish_parent_page,
         language="es",
         live=True,
     )
     mock_search.serch_term = "hipotecas"
     mock_search.queryset = mock_queryset(count=5)
     response = self.client.get(
         reverse("ask-search-es", kwargs={"language": "es"}),
         {"q": "hipotecas"},
     )
     self.assertEqual(page.answers, [])
     self.assertEqual(mock_search.call_count, 1)
     self.assertEqual(response.context_data["page"].language, "es")
     self.assertEqual(
         page.get_template(HttpRequest()),
         "ask-cfpb/answer-search-results.html",
     )