Exemple #1
0
    def test_creation_datetime(self):
        time_window_start = time_utils.now() - datetime.timedelta(weeks=1)
        time_window_end = time_utils.now() - datetime.timedelta(days=1)
        created_after = time_utils.now() - datetime.timedelta(hours=1)
        time_window_start_millis = time_utils.epoch_millis(time_window_start)
        time_window_end_millis = time_utils.epoch_millis(time_window_end)
        created_after_millis = time_utils.epoch_millis(created_after)

        # as datetime
        sample_query = SummarySampleQuery(
            time_window_start=time_window_start,
            time_window_end=time_window_end,
            created_after=created_after,
        )
        proto_request = sample_query._to_proto_request()
        assert (proto_request.filter.time_window_start_at_millis ==
                time_window_start_millis)
        assert proto_request.filter.time_window_end_at_millis == time_window_end_millis
        assert proto_request.filter.created_at_after_millis == created_after_millis

        # as millis
        sample_query = SummarySampleQuery(
            time_window_start=time_window_start_millis,
            time_window_end=time_window_end_millis,
            created_after=created_after_millis,
        )
        proto_request = sample_query._to_proto_request()
        assert (proto_request.filter.time_window_start_at_millis ==
                time_window_start_millis)
        assert proto_request.filter.time_window_end_at_millis == time_window_end_millis
        assert proto_request.filter.created_at_after_millis == created_after_millis
    def test_empty_query(self):
        empty_query = SummarySampleQuery()
        empty_to_proto = empty_query._to_proto_request()
        empty_from_proto = SummarySampleQuery._from_proto_request(empty_to_proto)
        assert empty_query == empty_from_proto

        # ensure that the aggregation submessage isn't set when not provided,
        # which has caused backend errors in the past
        assert not empty_to_proto.HasField("aggregation")
        assert empty_from_proto.aggregation is None