def test_trends_default_params__valid(self, mock_search, mock_count): trends_params = {"lens": "overview", "trend_interval": "year"} body = load("trends_default_params__valid") mock_count.return_value = {"count": body["hits"]["total"]["value"]} mock_search.return_value = body res = trends(**trends_params) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(mock_search.call_args[1]["index"], "INDEX") self.assertEqual(body, res)
def trends(request): data = _parse_query_params(request.query_params) serializer = TrendsInputSerializer(data=data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) results = es_interface.trends(agg_exclude=AGG_EXCLUDE_FIELDS, **serializer.validated_data) headers = _build_headers() return Response(results, headers=headers)
def test_trends_top_self_filter__valid(self, mock_search, mock_count): trends_params = { "lens": "overview", "trend_interval": "year", "trend_depth": 5, "issue": "Incorrect information on your report", } body = load("trends_filter__valid") mock_count.return_value = {"count": body["hits"]["total"]["value"]} mock_search.return_value = body res = trends(**trends_params) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(mock_search.call_args[1]["index"], "INDEX") self.assertEqual(body, res) self.assertTrue("company" not in res["aggregations"])
def test_trends_company_filter__valid(self, mock_search, mock_count): default_exclude = ["company", "zip_code"] trends_params = { "lens": "overview", "trend_interval": "year", "company": "EQUIFAX, INC.", } body = load("trends_company_filter__valid") mock_count.return_value = {"count": body["hits"]["total"]["value"]} mock_search.return_value = body res = trends(default_exclude, **trends_params) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(mock_search.call_args[1]["index"], "INDEX") self.assertTrue("company" in res["aggregations"])
def test_trends_exclude_and_date_filters__valid(self, mock_search, mock_count): trends_params = { "lens": "overview", "trend_interval": "year", "date_received_min": "2019-01-01", "date_received_max": "2020-01-01", "company_received_min": "2019-01-01", "company_received_max": "2020-01-01", } body = load("trends_exclude_and_date_filters__valid") mock_count.return_value = {"count": body["hits"]["total"]["value"]} mock_search.return_value = body res = trends(agg_exclude=["zip_code"], **trends_params) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(mock_search.call_args[1]["index"], "INDEX") self.assertEqual(body, res)
def test_trends_issue_focus__valid(self, mock_search, mock_count): default_exclude = ["company", "zip_code"] trends_params = { "lens": "issue", "trend_interval": "year", "trend_depth": 5, "focus": "Incorrect information on your report", } body = load("trends_issue_focus__valid") mock_count.return_value = {"count": body["hits"]["total"]["value"]} mock_search.return_value = body res = trends(default_exclude, **trends_params) self.assertEqual(len(mock_search.call_args), 2) self.assertEqual(mock_search.call_args[1]["index"], "INDEX") self.assertFalse("company" in res["aggregations"]) self.assertEqual(len(res["aggregations"]["issue"]["issue"]["buckets"]), 1)