code: def test_get_cache_reports() -> None:
      kind = CACHE_KIND
      kind_2 = "test_kind_2"
      expected_cache_reports: CacheReportsPage = {
          "cache_reports": [],
          "next_cursor": "",
      }
      assert (
          get_cache_reports(kind=kind, cursor="", limit=2)
          == expected_cache_reports
      )
      expected_cache_reports_with_content: CacheReportsWithContentPage = {
          "cache_reports_with_content": [],
          "next_cursor": "",
      }
      assert (
          get_cache_reports_with_content(kind=kind, cursor="", limit=2)
          == expected_cache_reports_with_content
      )
  
      dataset_a = DATASET_NAME_A
      dataset_git_revision_a = DATASET_GIT_REVISION_A
      content_a = {"key": "a"}
      http_status_a = HTTPStatus.OK
      updated_at_a = datetime(2020, 1, 1, 0, 0, 0)
      upsert_response(
          kind=kind,
          dataset=dataset_a,
          dataset_git_revision=dataset_git_revision_a,
          content=content_a,
          http_status=http_status_a,
          updated_at=updated_at_a,
      )
  
      dataset_b = DATASET_NAME_B
      dataset_git_revision_b = DATASET_GIT_REVISION_B
      config_b = "test_config_b"
      content_b = {"key": "b"}
      http_status_b = HTTPStatus.INTERNAL_SERVER_ERROR
      error_code_b = "error_code_b"
      details_b = {
          "error": "error b",
      }
      job_runner_version_b = 0
      updated_at_b = datetime(2020, 1, 1, 0, 0, 1)
      upsert_response(
          kind=kind,
          dataset=dataset_b,
          dataset_git_revision=dataset_git_revision_b,
          config=config_b,
          content=content_b,
          details=details_b,
          http_status=http_status_b,
          error_code=error_code_b,
          job_runner_version=job_runner_version_b,
          updated_at=updated_at_b,
      )
  
      dataset_c = DATASET_NAME_C
      dataset_git_revision_c = DATASET_GIT_REVISION_C
      config_c = "test_config_c"
      split_c = "test_split_c"
      content_c = {"key": "c"}
      http_status_c = HTTPStatus.INTERNAL_SERVER_ERROR
      error_code_c = "error_code_c"
      details_c = {
          "error": "error c",
      }
      updated_at_c = datetime(2020, 1, 1, 0, 0, 2)
      upsert_response(
          kind=kind,
          dataset=dataset_c,
          dataset_git_revision=dataset_git_revision_c,
          config=config_c,
          split=split_c,
          content=content_c,
          details=details_c,
          http_status=http_status_c,
          error_code=error_code_c,
          updated_at=updated_at_c,
      )
      upsert_response(
          kind=kind_2,
          dataset=dataset_c,
          dataset_git_revision=dataset_git_revision_c,
          content=content_c,
          details=details_c,
          http_status=http_status_c,
          error_code=error_code_c,
          updated_at=updated_at_c,
      )
      upsert_response(
          kind=kind_2,
          dataset=dataset_c,
          dataset_git_revision=dataset_git_revision_c,
          config=config_c,
          split=split_c,
          content=content_c,
          details=details_c,
          http_status=http_status_c,
          error_code=error_code_c,
          updated_at=updated_at_c,
      )
  
      response = get_cache_reports(kind=kind, cursor="", limit=2)
      assert response["cache_reports"] == [
          {
              "kind": kind,
              "dataset": dataset_a,
              "config": None,
              "split": None,
              "http_status": http_status_a.value,
              "error_code": None,
              "details": {},
              "updated_at": updated_at_a,
              "job_runner_version": None,
              "dataset_git_revision": dataset_git_revision_a,
              "progress": None,
          },
          {
              "kind": kind,
              "dataset": dataset_b,
              "config": config_b,
              "split": None,
              "http_status": http_status_b.value,
              "error_code": error_code_b,
              "details": details_b,
              "updated_at": updated_at_b,
              "job_runner_version": job_runner_version_b,
              "dataset_git_revision": dataset_git_revision_b,
              "progress": None,
          },
      ]
      assert response["next_cursor"] != ""
      next_cursor = response["next_cursor"]
      response = get_cache_reports(
          kind=kind, cursor=next_cursor, limit=2
      )
      assert response == {
          "cache_reports": [
              {
                  "kind": kind,
                  "dataset": dataset_c,
                  "config": config_c,
                  "split": split_c,
                  "http_status": http_status_c.value,
                  "error_code": error_code_c,
                  "details": details_c,
                  "updated_at": updated_at_c,
                  "job_runner_version": None,
                  "dataset_git_revision": dataset_git_revision_c,
                  "progress": None,
              },
          ],
          "next_cursor": "",
      }
  
      response_with_content = get_cache_reports_with_content(
          kind=kind, cursor="", limit=2
      )
      # redact the response to make it simpler to compare with the expected
      assert response_with_content["cache_reports_with_content"] == [
          {
              "kind": kind,
              "dataset": dataset_a,
              "config": None,
              "split": None,
              "http_status": http_status_a.value,
              "error_code": None,
              "content": content_a,
              "job_runner_version": None,
              "dataset_git_revision": dataset_git_revision_a,
              "details": {},
              "updated_at": updated_at_a,
              "progress": None,
          },
          {
              "kind": kind,
              "dataset": dataset_b,
              "config": config_b,
              "split": None,
              "http_status": http_status_b.value,
              "error_code": error_code_b,
              "content": content_b,
              "job_runner_version": job_runner_version_b,
              "dataset_git_revision": dataset_git_revision_b,
              "details": details_b,
              "updated_at": updated_at_b,
              "progress": None,
          },
      ]
      assert response_with_content["next_cursor"] != ""
      next_cursor = response_with_content["next_cursor"]
      response_with_content = get_cache_reports_with_content(
          kind=kind, cursor=next_cursor, limit=2
      )
      assert response_with_content == {
          "cache_reports_with_content": [
              {
                  "kind": kind,
                  "dataset": dataset_c,
                  "config": config_c,
                  "split": split_c,
                  "http_status": http_status_c.value,
                  "error_code": error_code_c,
                  "content": content_c,
                  "job_runner_version": None,
                  "dataset_git_revision": dataset_git_revision_c,
                  "details": details_c,
                  "updated_at": updated_at_c,
                  "progress": None,
              },
          ],
          "next_cursor": "",
      }
  
      with pytest.raises(InvalidCursor):
          get_cache_reports(
              kind=kind, cursor="not an objectid", limit=2
          )
      with pytest.raises(InvalidLimit):
          get_cache_reports(kind=kind, cursor=next_cursor, limit=-1)
      with pytest.raises(InvalidLimit):
          get_cache_reports(kind=kind, cursor=next_cursor, limit=0)
  
      result_a = get_dataset_responses_without_content_for_kind(
          kind=kind, dataset=dataset_a
      )
      assert len(result_a) == 1
      assert result_a[0]["http_status"] == HTTPStatus.OK.value
      assert result_a[0]["error_code"] is None
      assert result_a[0]["details"] == {}
  
      assert not get_dataset_responses_without_content_for_kind(
          kind=kind_2, dataset=dataset_a
      )
  
      result_c = get_dataset_responses_without_content_for_kind(
          kind=kind_2, dataset=dataset_c
      )
      assert len(result_c) == 2
      for result in result_c:
          assert result["http_status"] == http_status_c.value
          assert result["error_code"] == error_code_c
          assert result["details"] == details_c
          assert result["updated_at"] == updated_at_c
  
imports: from collections.abc import Mapping
  from datetime import datetime
  from decimal import Decimal
  from http import HTTPStatus
  from time import process_time
  from typing import Any, Optional, TypedDict
  import pytest
  from pymongo.errors import DocumentTooLarge
  from libcommon.resources import CacheMongoResource
  from libcommon.simple_cache import CachedArtifactError, CachedResponseDocument, CacheEntryDoesNotExistError, CacheReportsPage, CacheReportsWithContentPage, CacheTotalMetricDocument, InvalidCursor, InvalidLimit, delete_dataset_responses, delete_response, fetch_names, get_best_response, get_cache_reports, get_cache_reports_with_content, get_dataset_responses_without_content_for_kind, get_datasets_with_last_updated_kind, get_outdated_split_full_names_for_step, get_response, get_response_with_details, get_response_without_content, get_responses_count_by_kind_status_and_error_code, has_any_successful_response, upsert_response
  from libcommon.utils import get_datetime
  from .utils import CACHE_KIND, CONFIG_NAME_1, CONFIG_NAME_2, CONTENT_ERROR, DATASET_GIT_REVISION_A, DATASET_GIT_REVISION_B, DATASET_GIT_REVISION_C, DATASET_NAME, DATASET_NAME_A, DATASET_NAME_B, DATASET_NAME_C, REVISION_NAME
label_desc: Use image node_id 15 for calling a global function with example usage: test_get_cache_reports() without return types