From e68cf1a2030bc33c9619907227615adebe2070cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavl=C3=ADna=20Rolincov=C3=A1?= <43566406+rolincova@users.noreply.github.com> Date: Mon, 11 May 2020 09:57:49 +0200 Subject: [PATCH] fix: Fixed parameters in delete api #86 (#91) --- CHANGELOG.md | 1 + influxdb_client/client/delete_api.py | 8 ++--- tests/test_DeleteApi.py | 53 ++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55aba4dc..5122bb1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug Fixes 1. [#85](https://github.com/influxdata/influxdb-client-python/issues/85): Fixed a possibility to generate empty write batch +2. [#86](https://github.com/influxdata/influxdb-client-python/issues/86): BREAKING CHANGE: Fixed parameters in delete api - now delete api accepts also bucket name and org name instead of only ids ## 1.6.0 [2020-04-17] diff --git a/influxdb_client/client/delete_api.py b/influxdb_client/client/delete_api.py index 25a3d287..5ddb2155 100644 --- a/influxdb_client/client/delete_api.py +++ b/influxdb_client/client/delete_api.py @@ -9,15 +9,15 @@ def __init__(self, influxdb_client): self._influxdb_client = influxdb_client self._service = DefaultService(influxdb_client.api_client) - def delete(self, start: datetime, stop: object, predicate: object, bucket_id: str, org_id: str) -> None: + def delete(self, start: datetime, stop: object, predicate: object, bucket: str, org: str) -> None: """ Delete Time series data from InfluxDB. :param start: start time :param stop: stop time :param predicate: predicate - :param bucket_id: bucket id from which data will be deleted - :param org_id: organization id + :param bucket: bucket id or name from which data will be deleted + :param org: organization id or name :return: """ predicate_request = DeletePredicateRequest(start=start, stop=stop, predicate=predicate) - return self._service.delete_post(delete_predicate_request=predicate_request, bucket_id=bucket_id, org_id=org_id) + return self._service.delete_post(delete_predicate_request=predicate_request, bucket=bucket, org=org) diff --git a/tests/test_DeleteApi.py b/tests/test_DeleteApi.py index cbc67a09..f326cf9c 100644 --- a/tests/test_DeleteApi.py +++ b/tests/test_DeleteApi.py @@ -31,6 +31,44 @@ def setUp(self) -> None: def test_delete_buckets(self): + self._write_data() + + q = f'from(bucket:\"{self.bucket.name}\") |> range(start: 1970-01-01T00:00:00.000000001Z)' + print(q) + flux_tables = self.client.query_api().query(query=q, org=self.organization.id) + self.assertEqual(len(flux_tables), 1) + self.assertEqual(len(flux_tables[0].records), 12) + + start = "1970-01-01T00:00:00.000000001Z" + stop = "1970-01-01T00:00:00.000000012Z" + self.delete_api.delete(start, stop, "", bucket=self.bucket.id, org=self.organization.id) + + flux_tables2 = self.client.query_api().query( + f'from(bucket:"{self.bucket.name}") |> range(start: 1970-01-01T00:00:00.000000001Z)', + org=self.organization.id) + self.assertEqual(len(flux_tables2), 0) + + def test_delete_buckets_by_name(self): + + self._write_data() + + q = f'from(bucket:\"{self.bucket.name}\") |> range(start: 1970-01-01T00:00:00.000000001Z)' + print(q) + flux_tables = self.client.query_api().query(query=q, org=self.organization.id) + self.assertEqual(len(flux_tables), 1) + self.assertEqual(len(flux_tables[0].records), 12) + + start = "1970-01-01T00:00:00.000000001Z" + stop = "1970-01-01T00:00:00.000000012Z" + self.delete_api.delete(start, stop, "", bucket=self.bucket.name, org=self.organization.name) + + flux_tables2 = self.client.query_api().query( + f'from(bucket:"{self.bucket.name}") |> range(start: 1970-01-01T00:00:00.000000001Z)', + org=self.organization.id) + self.assertEqual(len(flux_tables2), 0) + + def _write_data(self): + write_api = self.client.write_api(write_options=SYNCHRONOUS) p1 = Point(measurement_name="h2o").tag("location", "coyote_creek").field("watter_level", 7.0).time(1) write_api.write(bucket=self.bucket.name, org=self.organization.name, record=p1) @@ -58,18 +96,3 @@ def test_delete_buckets(self): p11 = Point(measurement_name="h2o").tag("location", "coyote_creek").field("watter_level", 11.0).time(11) p12 = Point(measurement_name="h2o").tag("location", "coyote_creek").field("watter_level", 13.0).time(12) write_api.write(bucket=self.bucket.name, org=self.organization.name, record=[p11, p12]) - - q = f'from(bucket:\"{self.bucket.name}\") |> range(start: 1970-01-01T00:00:00.000000001Z)' - print(q) - flux_tables = self.client.query_api().query(query=q, org=self.organization.id) - self.assertEqual(len(flux_tables), 1) - self.assertEqual(len(flux_tables[0].records), 12) - - start = "1970-01-01T00:00:00.000000001Z" - stop = "1970-01-01T00:00:00.000000012Z" - self.delete_api.delete(start, stop, "", bucket_id=self.bucket.id, org_id=self.organization.id) - - flux_tables2 = self.client.query_api().query( - f'from(bucket:"{self.bucket.name}") |> range(start: 1970-01-01T00:00:00.000000001Z)', - org=self.organization.id) - self.assertEqual(len(flux_tables2), 0)