8000 Added drop_retention_policy() · marccardinal/influxdb-python@5dfecd1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5dfecd1

Browse files
committed
Added drop_retention_policy()
1 parent c101386 commit 5dfecd1

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

influxdb/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,20 @@ def alter_retention_policy(self, name, database=None,
548548

549549
self.query(query_string)
550550

551+
def drop_retention_policy(self, name, database=None):
552+
"""Drop an existing retention policy for a database.
553+
554+
:param name: the name of the retention policy to drop
555+
:type name: str
556+
:param database: the database for which the retention policy is
557+
dropped. Defaults to current client's database
558+
:type database: str
559+
"""
560+
query_string = (
561+
"DROP RETENTION POLICY {0} ON {1}"
562+
).format(name, database or self._database)
563+
self.query(query_string)
564+
551565
def get_list_retention_policies(self, database=None):
552566
"""Get the list of retention policies for a database.
553567

influxdb/tests/client_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,27 @@ def test_alter_retention_policy_invalid(self):
632632
with _mocked_session(cli, 'get', 400):
633633
self.cli.alter_retention_policy('somename', 'db')
634634

635+
def test_drop_retention_policy(self):
636+
example_response = '{"results":[{}]}'
637+
638+
with requests_mock.Mocker() as m:
639+
m.register_uri(
640+
requests_mock.GET,
641+
"http://localhost:8086/query",
642+
text=example_response
643+
)
644+
self.cli.drop_retention_policy('somename', 'db')
645+
self.assertEqual(
646+
m.last_request.qs['q'][0],
647+
'drop retention policy somename on db'
648+
)
649+
650+
@raises(Exception)
651+
def test_drop_retention_policy_fails(self):
652+
cli = InfluxDBClient('host', 8086, 'username', 'password')
653+
with _mocked_session(cli, 'delete', 401):
654+
cli.drop_retention_policy('default', 'db')
655+
635656
def test_get_list_retention_policies(self):
636657
example_response = \
637658
'{"results": [{"series": [{"values": [["fsfdsdf", "24h0m0s", 2]],'\

influxdb/tests/server_tests/client_test_with_server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,27 @@ def test_alter_retention_policy_invalid(self):
600600
rsp
601601
)
602602

603+
def test_drop_retention_policy(self):
604+
self.cli.create_retention_policy('somename', '1d', 1)
605+
606+
# Test drop retention
607+
self.cli.drop_retention_policy('somename', 'db')
608+
rsp = self.cli.get_list_retention_policies()
609+
self.assertEqual(
610+
[{'duration': '0', 'default': True,
611+
'replicaN': 1, 'name': 'default'}],
612+
rsp
613+
)
614+
615+
def test_drop_retention_policy_default(self):
616+
# Test drop default retention
617+
with self.assertRaises(InfluxDBClientError) as ctx:
618+
self.cli.drop_retention_policy('default', 'db')
619+
620+
self.assertEqual(400, ctx.exception.code)
621+
self.assertIn('{"error":"error parsing query: found DEFAULT, expected POLICY',
622+
ctx.exception.content)
623+
603624
def test_issue_143(self):
604625
pt = partial(point, 'a_serie_name', timestamp='2015-03-30T16:16:37Z')
605626
pts = [

0 commit comments

Comments
 (0)
0