Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def test_states_exclude__valid(self, mock_count, mock_search):
     body = load("states_agg__valid")
     mock_search.return_value = {
         "hits": {"total": {"value": 100, "relation": "eq"}}
     }
     res = states_agg(["zip_code"])
     self.assertEqual(len(mock_search.call_args), 2)
     self.assertEqual(0, len(mock_search.call_args[0]))
     self.assertEqual(2, len(mock_search.call_args[1]))
     assertBodyEqual(body, mock_search.call_args_list[0][1]["body"])
     self.assertEqual(mock_search.call_args[1]["index"], "INDEX")
     self.assertEqual(res["hits"]["total"]["relation"], "eq")
Exemplo n.º 3
0
    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"])
Exemplo n.º 4
0
    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"])
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def test_states_date_filters__valid(self, mock_search):
        params = {
            "date_received_min": "2020-01-01",
            "date_received_max": "2020-05-05",
            "company_received_min": "2020-01-01",
            "company_received_max": "2020-05-05",
            "state": ["VA"],
            "size": 0,
        }
        body = load("states_date_filters__valid")

        mock_search.return_value = {
            "hits": {"total": {"value": 100, "relation": "eq"}}
        }
        res = states_agg(**params)
        self.assertEqual(len(mock_search.call_args), 2)
        self.assertEqual(0, len(mock_search.call_args[0]))
        self.assertEqual(2, len(mock_search.call_args[1]))
        assertBodyEqual(body, mock_search.call_args_list[0][1]["body"])
        self.assertEqual(mock_search.call_args[1]["index"], "INDEX")
        self.assertEqual(res, mock_search.return_value)
Exemplo n.º 8
0
    def request_test(self, expected, agg_exclude=None, **kwargs):
        if agg_exclude is None:
            agg_exclude = ["company", "zip_code"]
        body = load(expected)

        with mock.patch(
            "complaint_search.es_interface._COMPLAINT_ES_INDEX", "INDEX"
        ), mock.patch(
            "complaint_search.es_interface._get_meta"
        ) as mock_get_meta, mock.patch.object(
            Elasticsearch, "search"
        ) as mock_search, mock.patch.object(
            Elasticsearch, "count"
        ) as mock_count, mock.patch.object(
            Elasticsearch, "scroll"
        ) as mock_scroll:
            mock_search.side_effect = copy.deepcopy(
                self.MOCK_SEARCH_SIDE_EFFECT
            )
            mock_count.return_value = self.MOCK_COUNT_RETURN_VALUE
            mock_get_meta.return_value = copy.deepcopy(
                self.MOCK_SEARCH_RESULT["_meta"]
            )
            mock_scroll.return_value = self.MOCK_SEARCH_SIDE_EFFECT[0]

            res = search(agg_exclude, **kwargs)

        self.assertEqual(1, len(mock_search.call_args_list))
        self.assertEqual(2, len(mock_search.call_args_list[0]))
        self.assertEqual(0, len(mock_search.call_args_list[0][0]))
        self.assertEqual(2, len(mock_search.call_args_list[0][1]))

        assertBodyEqual(body, mock_search.call_args_list[0][1]["body"])
        self.assertEqual(mock_search.call_args_list[0][1]["index"], "INDEX")
        mock_scroll.assert_not_called()
        self.assertDictEqual(self.MOCK_SEARCH_RESULT, res)
Exemplo n.º 9
0
 def setUp(self):
     self.test_data = load("break_point_data")