def test_fill_date_from_and_date_to(self):
        with freeze_time("2020-10-01T12:00:00Z"):
            filter = RetentionFilter(data={})
        self.assertEqual(filter.date_from.isoformat(),
                         "2020-09-21T00:00:00+00:00")
        self.assertEqual(filter.date_to.isoformat(),
                         "2020-10-02T00:00:00+00:00")
        #  Make sure these dates aren't present in final filter to ensure rolling retention
        self.assertEqual(
            filter.to_dict(),
            {
                "display": "RetentionTable",
                "insight": "RETENTION",
                "period": "Day",
                "retention_type": "retention_recurring",
                "total_intervals": 11,
            },
        )

        with freeze_time("2020-10-01T12:00:00Z"):
            filter = RetentionFilter(data={"date_to": "2020-08-01"})
        self.assertEqual(filter.date_from.isoformat(),
                         "2020-07-22T00:00:00+00:00")
        self.assertEqual(filter.date_to.isoformat(),
                         "2020-08-02T00:00:00+00:00")
        #  Make sure these dates aren't present in final filter to ensure rolling retention
        self.assertEqual(
            filter.to_dict(),
            {
                "date_to": "2020-08-02T00:00:00+00:00",
                "display": "RetentionTable",
                "insight": "RETENTION",
                "period": "Day",
                "retention_type": "retention_recurring",
                "total_intervals": 11,
            },
        )
Example #2
0
    def test_fill_date_from_and_date_to(self):
        with freeze_time("2020-10-01T12:00:00Z"):
            filter = RetentionFilter(data={})
            self.assertEqual(filter.date_from.isoformat(),
                             "2020-09-21T00:00:00+00:00")
            self.assertEqual(filter.date_to.isoformat(),
                             "2020-10-02T00:00:00+00:00")
        #  Make sure these dates aren't present in final filter to ensure rolling retention
        self.assertEqual(
            filter.to_dict(),
            {
                "display": "RetentionTable",
                "insight": "RETENTION",
                "period": "Day",
                "retention_type": "retention_recurring",
                "total_intervals": 11,
                "returning_entity": {
                    "id": "$pageview",
                    "math": None,
                    "math_property": None,
                    "math_group_type_index": None,
                    "name": "$pageview",
                    "custom_name": None,
                    "order": None,
                    "properties": {},
                    "type": "events",
                },
                "target_entity": {
                    "id": "$pageview",
                    "math": None,
                    "math_property": None,
                    "math_group_type_index": None,
                    "name": "$pageview",
                    "custom_name": None,
                    "order": None,
                    "properties": {},
                    "type": "events",
                },
            },
        )

        with freeze_time("2020-10-01T12:00:00Z"):
            filter = RetentionFilter(data={"date_to": "2020-08-01"})
        self.assertEqual(filter.date_from.isoformat(),
                         "2020-07-22T00:00:00+00:00")
        self.assertEqual(filter.date_to.isoformat(),
                         "2020-08-02T00:00:00+00:00")
        #  Make sure these dates aren't present in final filter to ensure rolling retention

        # The date_to below is the base value that's provided when the object was created (_date_to).
        # It doesn't match the date_to above because the retention filter will transform date_to to include one period ahead
        self.assertEqual(
            filter.to_dict(),
            {
                "date_to": "2020-08-01",
                "display": "RetentionTable",
                "insight": "RETENTION",
                "period": "Day",
                "retention_type": "retention_recurring",
                "total_intervals": 11,
                "returning_entity": {
                    "id": "$pageview",
                    "math": None,
                    "math_property": None,
                    "math_group_type_index": None,
                    "name": "$pageview",
                    "custom_name": None,
                    "order": None,
                    "properties": {},
                    "type": "events",
                },
                "target_entity": {
                    "id": "$pageview",
                    "math": None,
                    "math_property": None,
                    "math_group_type_index": None,
                    "name": "$pageview",
                    "custom_name": None,
                    "order": None,
                    "properties": {},
                    "type": "events",
                },
            },
        )