Skip to content

Commit

Permalink
feat: add paging to find functions (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
russorat authored May 5, 2021
1 parent f698030 commit e26e7b0
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.18.0 [unreleased]

### Features
1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination.

## 1.17.0 [2021-04-30]

### Features
Expand Down
2 changes: 1 addition & 1 deletion examples/buckets_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
The Bucket API uses as a parameter the Organization ID. We have to retrieve ID by Organization API.
"""
org_name = "my-org"
org = list(filter(lambda it: it.name == org_name, client.organizations_api().find_organizations()))[0]
org = client.organizations_api().find_organizations(org=org_name)[0]

"""
Create Bucket with retention policy set to 3600 seconds and name "bucket-by-python"
Expand Down
8 changes: 4 additions & 4 deletions influxdb_client/client/authorizations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def find_authorizations(self, **kwargs):
"""
Get a list of all authorizations.
:param str user_id: filter authorizations belonging to a user id
:param str user: filter authorizations belonging to a user name
:param str org_id: filter authorizations belonging to a org id
:param str org: filter authorizations belonging to a org name
:key str user_id: filter authorizations belonging to a user id
:key str user: filter authorizations belonging to a user name
:key str org_id: filter authorizations belonging to a org id
:key str org: filter authorizations belonging to a org name
:return: Authorizations
"""
authorizations = self._authorizations_service.get_authorizations(**kwargs)
Expand Down
16 changes: 13 additions & 3 deletions influxdb_client/client/bucket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def find_bucket_by_name(self, bucket_name):
else:
return None

def find_buckets(self):
"""Get all buckets."""
return self._buckets_service.get_buckets()
def find_buckets(self, **kwargs):
"""List buckets.
:key int offset: Offset for pagination
:key int limit: Limit for pagination
:key str after: The last resource ID from which to seek from (but not including).
This is to be used instead of `offset`.
:key str org: The organization name.
:key str org_id: The organization ID.
:key str name: Only returns buckets with a specific name.
:return: Buckets
"""
return self._buckets_service.get_buckets(**kwargs)
6 changes: 4 additions & 2 deletions influxdb_client/client/labels_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ def clone_label(self, cloned_name: str, label: Label) -> Label:

return self.create_label(name=cloned_name, properties=cloned_properties, org_id=label.org_id)

def find_labels(self) -> List['Label']:
def find_labels(self, **kwargs) -> List['Label']:
"""
Get all available labels.
:key str org_id: The organization ID.
:return: labels
"""
return self._service.get_labels().labels
return self._service.get_labels(**kwargs).labels

def find_label_by_id(self, label_id: str):
"""
Expand Down
15 changes: 12 additions & 3 deletions influxdb_client/client/organizations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ def find_organization(self, org_id):
"""Retrieve an organization."""
return self._organizations_service.get_orgs_id(org_id=org_id)

def find_organizations(self):
"""List all organizations."""
return self._organizations_service.get_orgs().orgs
def find_organizations(self, **kwargs):
"""
List all organizations.
:key int offset: Offset for pagination
:key int limit: Limit for pagination
:key bool descending:
:key str org: Filter organizations to a specific organization name.
:key str org_id: Filter organizations to a specific organization ID.
:key str user_id: Filter organizations to a specific user ID.
"""
return self._organizations_service.get_orgs(**kwargs).orgs

def create_organization(self, name: str = None, organization: Organization = None) -> Organization:
"""Create an organization."""
Expand Down
12 changes: 6 additions & 6 deletions influxdb_client/client/tasks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def find_task_by_id(self, task_id) -> Task:
def find_tasks(self, **kwargs):
"""List all tasks.
:param str name: only returns tasks with the specified name
:param str after: returns tasks after specified ID
:param str user: filter tasks to a specific user ID
:param str org: filter tasks to a specific organization name
:param str org_id: filter tasks to a specific organization ID
:param int limit: the number of tasks to return
:key str name: only returns tasks with the specified name
:key str after: returns tasks after specified ID
:key str user: filter tasks to a specific user ID
:key str org: filter tasks to a specific organization name
:key str org_id: filter tasks to a specific organization ID
:key int limit: the number of tasks to return
:return: Tasks
"""
return self._service.get_tasks(**kwargs).tasks
Expand Down
20 changes: 20 additions & 0 deletions tests/test_BucketsApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ def test_create_bucket_retention_list(self):

self.delete_test_bucket(my_bucket)

def test_pagination(self):
my_org = self.find_my_org()
buckets = self.buckets_api.find_buckets().buckets
size = len(buckets)

# create 2 buckets
self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id)
self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id)

buckets = self.buckets_api.find_buckets().buckets
self.assertEqual(size + 2, len(buckets))

# offset 1
buckets = self.buckets_api.find_buckets(offset=1).buckets
self.assertEqual(size + 1, len(buckets))

# count 1
buckets = self.buckets_api.find_buckets(limit=1).buckets
self.assertEqual(1, len(buckets))


if __name__ == '__main__':
unittest.main()

0 comments on commit e26e7b0

Please sign in to comment.