Ejemplo n.º 1
0
    def test_query_events(
        self,
        monkeypatch: MonkeyPatch,
        events_querier: EventsQuerier,
        now: int,
    ) -> None:
        # note: this data is of course incomplete, but sufficient for this test
        events_data = [
            {
                "title": "event1",
            },
            {
                "title": "event2",
            },
            {
                "title": "event3",
            },
        ]

        def patch_get_request_json_decoded(_api_endpoint, params):
            if params["page"] == 0:
                return {"events": events_data}
            if params["page"] == 1:
                return {"events": []}
            raise RuntimeError

        monkeypatch.setattr(
            events_querier._datadog_api,
            "get_request_json_decoded",
            patch_get_request_json_decoded,
        )

        assert list(events_querier.query_events([])) == events_data
        assert events_querier._read_last_events_timestamp() == now
Ejemplo n.º 2
0
 def test_query_events_no_previous_ids(
     self,
     events_querier: EventsQuerier,
     events: Sequence[DatadogAPIResponse],
 ) -> None:
     assert list(events_querier.query_events([])) == events
     assert events_querier._read_last_event_ids() == frozenset({1, 2, 3})
Ejemplo n.º 3
0
 def test_query_events_with_previous_ids(
     self,
     events_querier: EventsQuerier,
     events: Sequence[DatadogAPIResponse],
 ) -> None:
     events_querier._store_last_event_ids([1, 2, 5])
     assert list(events_querier.query_events([])) == events[-1:]
     assert events_querier._read_last_event_ids() == frozenset({1, 2, 3})
Ejemplo n.º 4
0
 def test_events_query_time_range_too_old_previous_timestamp(
     self,
     events_querier: EventsQuerier,
     now: int,
 ) -> None:
     events_querier._store_events_timestamp(now - 7200)
     assert events_querier._events_query_time_range() == (
         now - 3600,
         now,
     )
Ejemplo n.º 5
0
 def test_events_query_time_range_ok_previous_timestamp(
     self,
     events_querier: EventsQuerier,
     now: int,
 ) -> None:
     last_timestamp = now - 120
     events_querier._store_events_timestamp(last_timestamp)
     assert events_querier._events_query_time_range() == (
         last_timestamp,
         now,
     )
Ejemplo n.º 6
0
 def fixture_events_querier(
     self,
     datadog_api: DatadogAPI,
 ) -> EventsQuerier:
     return EventsQuerier(
         datadog_api,
         "host_name",
     )
Ejemplo n.º 7
0
 def test_events_query_time_range_no_previous_timestamp(
     self,
     events_querier: EventsQuerier,
     now: int,
 ) -> None:
     assert events_querier._events_query_time_range() == (
         now - 3600,
         now,
     )
Ejemplo n.º 8
0
 def test_events_query_time_range(
     self,
     monkeypatch: MonkeyPatch,
     events_querier: EventsQuerier,
 ) -> None:
     now = 1601310544
     monkeypatch.setattr(
         agent_datadog.time,
         "time",
         lambda: now,
     )
     assert events_querier._events_query_time_range() == (
         now - events_querier._max_age,
         now,
     )