Skip to content

Commit 3742a0e

Browse files
committed
Add tests for get_list_privileges()
These test check for correct return value and exception handling in case of incorrect usage.
1 parent a1287be commit 3742a0e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

influxdb/tests/client_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,31 @@ def test_revoke_privilege_invalid(self):
776776
with _mocked_session(cli, 'get', 400):
777777
self.cli.revoke_privilege('', 'testdb', 'test')
778778

779+
def test_get_list_privileges(self):
780+
data = {'results': [
781+
{'series': [
782+
{'columns': ['database', 'privilege'],
783+
'values': [
784+
['db1', 'READ'],
785+
['db2', 'ALL PRIVILEGES'],
786+
['db3', 'NO PRIVILEGES']]}
787+
]}
788+
]}
789+
790+
with _mocked_session(self.cli, 'get', 200, json.dumps(data)):
791+
self.assertListEqual(
792+
self.cli.get_list_privileges('test'),
793+
[{'database': 'db1', 'privilege': 'READ'},
794+
{'database': 'db2', 'privilege': 'ALL PRIVILEGES'},
795+
{'database': 'db3', 'privilege': 'NO PRIVILEGES'}]
796+
)
797+
798+
@raises(Exception)
799+
def test_get_list_privileges_fails(self):
800+
cli = InfluxDBClient('host', 8086, 'username', 'password')
801+
with _mocked_session(cli, 'get', 401):
802+
cli.get_list_privileges('test')
803+
779804
def test_invalid_port_fails(self):
780805
with self.assertRaises(ValueError):
781806
InfluxDBClient('host', '80/redir', 'username', 'password')

0 commit comments

Comments
 (0)