Skip to content

Commit

Permalink
fix: Fixed parameters in delete api #86 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolincova authored May 11, 2020
1 parent 58f653a commit e68cf1a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
8 changes: 4 additions & 4 deletions influxdb_client/client/delete_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
53 changes: 38 additions & 15 deletions tests/test_DeleteApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit e68cf1a

Please sign in to comment.