qase-tms/qase-python

QaseApi.suites.get_all() returns limited entities to 10

Closed this issue · 3 comments

When issuing a QaseApi call like below:

suites = QaseApi(token).suites.get_all(project_code)
len(suites.entities) # returns 10

even if the get_all() didn't specify any limit and the default limit is None.

Is it possible to get all of the suites and how?
My current workaround is to specify a limit of 100 but this will fail in the face of an increasing number of suites.
Many thanks for your support!

sklmx commented

Hi @EugenSusurrus! Currently, the client doesn’t support this feature. In further updates, we'll add a new field to the response - total. This will allow realizing pagination in a more explicit way. For now, I suggest using a loop until the response is empty.

Hi @sklmx , many thanks for the fast response, could you please provide a minimal example of how I could accomplish that?

if I correctly understand, I need to make a first "dummy request" in which I will get the total count of the suites then in a loop make subsequent get_all() requests with limit set until I deplete all the suites / cases?

In case someone else needs it:

  def _fetch_service_in_batches(self, service: BaseService, filters: DefaultFilter = None) -> Type[BaseService]:
      """Fetches all data for a given `Service` such as `Suites`, `Cases` in batches.

      NOTE: This is a workaround for the current qase api `100` items limitation.
      Args:
          service (BaseService): `Service` instance such as `Suites`, `Cases`, etc.
          filters (DefaultFilter, optional): `Filter` instance such as `TestCaseFilters`. Defaults to None.

      Returns:
          Type[BaseService]: Fetched `Service` data.
      """
      batch_size = 100
      fetched_service_data = getattr(service, 'get_all')(
          self.project_code, limit=batch_size, filters=filters
      )
      offset = fetched_service_data.count

      while True:
          # Offset the request so we don't include the previously fetched data
          currently_fetched_service_data = getattr(service, 'get_all')(
              self.project_code, limit=batch_size, offset=offset, filters=filters
          )
          if not currently_fetched_service_data.entities:
              break

          fetched_service_data.entities.extend(currently_fetched_service_data.entities)
          offset += currently_fetched_service_data.count

      return fetched_service_data