Skip to content

Commit a5cc337

Browse files
committed
feat: add possibility to update Organization from API
1 parent edae745 commit a5cc337

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## 1.24.0 [unreleased]
22

33
### Features
4-
1. [#358](https://github.com/influxdata/influxdb-client-python/pull/358): Add possibility to update `Bucket` from API
4+
1. [#358](https://github.com/influxdata/influxdb-client-python/pull/358): Add possibility to update `Bucket`, `Organization` from API
55

66
## 1.23.0 [2021-10-26]
77

influxdb_client/client/bucket_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru
5858

5959
return self._buckets_service.post_buckets(post_bucket_request=bucket)
6060

61-
def update_bucket(self, bucket: Bucket):
61+
def update_bucket(self, bucket: Bucket) -> Bucket:
6262
"""Update a bucket.
6363
6464
:param bucket: Bucket update to apply (required)

influxdb_client/client/organizations_api.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
All dashboards, tasks, buckets, members, etc., belong to an organization.
55
"""
66

7-
8-
from influxdb_client import OrganizationsService, UsersService, Organization
7+
from influxdb_client import OrganizationsService, UsersService, Organization, PatchOrganizationRequest
98

109

1110
class OrganizationsApi(object):
@@ -45,6 +44,17 @@ def create_organization(self, name: str = None, organization: Organization = Non
4544
organization = Organization(name=name)
4645
return self._organizations_service.post_orgs(post_organization_request=organization)
4746

47+
def update_organization(self, organization: Organization) -> Organization:
48+
"""Update an organization.
49+
50+
:param organization: Organization update to apply (required)
51+
:return: Organization
52+
"""
53+
request = PatchOrganizationRequest(name=organization.name,
54+
description=organization.description)
55+
56+
return self._organizations_service.patch_orgs_id(org_id=organization.id, patch_organization_request=request)
57+
4858
def delete_organization(self, org_id: str):
4959
"""Delete an organization."""
5060
return self._organizations_service.delete_orgs_id(org_id=org_id)

tests/base_test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212

1313
def generate_bucket_name():
14-
return "test_bucket_" + str(datetime.datetime.now().timestamp()) + "_IT"
14+
return generate_name(key="bucket")
15+
16+
17+
def generate_name(key: str):
18+
return f"test_{key}_" + str(datetime.datetime.now().timestamp()) + "_IT"
1519

1620

1721
class BaseTest(unittest.TestCase):

tests/test_OrganizationsApi.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from tests.base_test import BaseTest, generate_name
2+
3+
4+
class OrganizationsApiTests(BaseTest):
5+
6+
def setUp(self) -> None:
7+
super(OrganizationsApiTests, self).setUp()
8+
organizations_api = self.client.organizations_api()
9+
organizations = organizations_api.find_organizations()
10+
11+
for organization in organizations:
12+
if organization.name.endswith("_IT"):
13+
print("Delete organization: ", organization.name)
14+
organizations_api.delete_organization(org_id=organization.id)
15+
16+
def test_update_organization(self):
17+
organizations_api = self.client.organizations_api()
18+
19+
organization = organizations_api.create_organization(name=generate_name(key='org'))
20+
self.assertEqual("", organization.description)
21+
22+
organization.description = "updated description"
23+
organization = organizations_api.update_organization(organization=organization)
24+
self.assertEqual("updated description", organization.description)

0 commit comments

Comments
 (0)