예제 #1
0
def results_view(request):
    query = request.GET.get('q', '')

    results = dotgov.search(query)

    context = {'q': query, 'results': results}

    response = TemplateResponse(request, 'search/results.html', context)
    return response.render()
예제 #2
0
파일: views.py 프로젝트: cfpb/cfgov-refresh
def results_view(request):
    query = request.GET.get('q', '')

    results = dotgov.search(query)

    context = {
        'q': query,
        'results': results
    }

    response = TemplateResponse(request, 'search/results.html', context)
    return response.render()
예제 #3
0
 def test_search_query(self, mock_get):
     mock_get.return_value.ok = True
     search('query')
     mock_get.return_value.json.assert_called()
예제 #4
0
 def test_search_sort_by_out_of_bounds(self):
     with self.assertRaises(ValueError):
         search('query', sort_by='alpha')
예제 #5
0
    def test_search_offset_out_of_bounds(self):
        with self.assertRaises(ValueError):
            search('query', offset=-1)

        with self.assertRaises(ValueError):
            search('query', offset=1000)
예제 #6
0
    def test_search_limit_out_of_bounds(self):
        with self.assertRaises(ValueError):
            search('query', limit=0)

        with self.assertRaises(ValueError):
            search('query', limit=51)
예제 #7
0
 def test_search_query_bad_upstream_response(self, mock_get):
     mock_get.return_value.ok = False
     result = search('')
     self.assertEqual(result, {})
예제 #8
0
 def test_search_sort_by_out_of_bounds(self):
     with self.assertRaises(ValueError):
         search('query', sort_by='alpha')
예제 #9
0
    def test_search_offset_out_of_bounds(self):
        with self.assertRaises(ValueError):
            search('query', offset=-1)

        with self.assertRaises(ValueError):
            search('query', offset=1000)
예제 #10
0
    def test_search_limit_out_of_bounds(self):
        with self.assertRaises(ValueError):
            search('query', limit=0)

        with self.assertRaises(ValueError):
            search('query', limit=51)
예제 #11
0
 def test_search_query_bad_upstream_response(self, mock_get):
     mock_get.return_value.ok = False
     result = search('')
     self.assertEquals(result, {})
예제 #12
0
 def test_search_query(self, mock_get):
     mock_get.return_value.ok = True
     search('query')
     mock_get.return_value.json.assert_called()