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()
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()
def test_search_query(self, mock_get): mock_get.return_value.ok = True search('query') mock_get.return_value.json.assert_called()
def test_search_sort_by_out_of_bounds(self): with self.assertRaises(ValueError): search('query', sort_by='alpha')
def test_search_offset_out_of_bounds(self): with self.assertRaises(ValueError): search('query', offset=-1) with self.assertRaises(ValueError): search('query', offset=1000)
def test_search_limit_out_of_bounds(self): with self.assertRaises(ValueError): search('query', limit=0) with self.assertRaises(ValueError): search('query', limit=51)
def test_search_query_bad_upstream_response(self, mock_get): mock_get.return_value.ok = False result = search('') self.assertEqual(result, {})
def test_search_query_bad_upstream_response(self, mock_get): mock_get.return_value.ok = False result = search('') self.assertEquals(result, {})