Repository: oppia/oppia
File: core/tests/test_utils.py (Python)

Code before:
            'throttled_millis': 0,
            'total': index_size,
            'batches': 1,
            'requests_per_second': -1.0,
            'retries': {'search': 0, 'bulk': 0},
            'timed_out': False,
            'deleted': index_size,
        }

    # Here we use type Any because the argument 'body' can accept dictionaries
    # that can possess different types of values like int, List[...], nested
    # dictionaries and other types too.
    def mock_search(
        self,
        body: Optional[Dict[str, Dict[str, Dict[str, Any]]]] = None,
        index: Optional[str] = None,
        size: Optional[int] = None,
        from_: Optional[int] = None,
    ) -> SearchDocumentDict:
        """Searches and returns documents that match the given query.

        Args:
            body: dict|None. A dictionary search definition that uses Query DSL.
            index: str|None. The name of the index to search.
            size: int|None. The number of results to fetch.
            from_:int|None. The offset from which the results are to be fetched.

        Returns:
            dict. A dict representing the ElasticSearch response.

        Raises:
            AssertionError. The given arguments are not supported by this mock.
            elasticsearch.NotFoundError. The given index name was not found.
        """
        assert body is not None
        # "_all" and "" are special index names that are used to search across
        # all indexes. We do not allow their use.
        assert index not in ['_all', '']
        assert index is not None
        assert size is not None
        assert from_ is not None

        if index not in self._DB:
            self._generate_index_not_found_error(index)

        result_docs = []
        result_doc_ids = set([])
        for doc in self._DB[index]:
            if not doc['id'] in result_doc_ids:
                result_docs.append(doc)
                result_doc_ids.add(doc['id'])

Review comment (suggestion):
```suggestion
            from_: int|None. The offset from which the results are to be fetched.
```

Code after:
            'throttled_millis': 0,
            'total': index_size,
            'batches': 1,
            'requests_per_second': -1.0,
            'retries': {'search': 0, 'bulk': 0},
            'timed_out': False,
            'deleted': index_size,
        }

    # Here we use type Any because the argument 'body' can accept dictionaries
    # that can possess different types of values like int, List[...], nested
    # dictionaries and other types too.
    def mock_search(
        self,
        body: Optional[Dict[str, Dict[str, Dict[str, Any]]]] = None,
        index: Optional[str] = None,
        size: Optional[int] = None,
        from_: Optional[int] = None,
    ) -> SearchDocumentDict:
        """Searches and returns documents that match the given query.

        Args:
            body: dict|None. A dictionary search definition that uses Query DSL.
            index: str|None. The name of the index to search.
            size: int|None. The number of results to fetch.
            from_: int|None. The offset from which the results are to be fetched.

        Returns:
            dict. A dict representing the ElasticSearch response.

        Raises:
            AssertionError. The given arguments are not supported by this mock.
            elasticsearch.NotFoundError. The given index name was not found.
        """
        assert body is not None
        # "_all" and "" are special index names that are used to search across
        # all indexes. We do not allow their use.
        assert index not in ['_all', '']
        assert index is not None
        assert size is not None
        assert from_ is not None

        if index not in self._DB:
            self._generate_index_not_found_error(index)

        result_docs = []
        result_doc_ids = set([])
        for doc in self._DB[index]:
            if not doc['id'] in result_doc_ids:
                result_docs.append(doc)
                result_doc_ids.add(doc['id'])