|
1 |
| -from influxdb_client import InfluxDBClient, Organization |
| 1 | +import pytest |
| 2 | + |
| 3 | +from influxdb_client import InfluxDBClient, Organization, PermissionResource, Permission |
2 | 4 | # noinspection PyProtectedMember
|
| 5 | +from influxdb_client.client.exceptions import InfluxDBError |
3 | 6 | from influxdb_client.client.util.helpers import get_org_query_param, _is_id
|
4 | 7 | from tests.base_test import BaseTest
|
5 | 8 |
|
@@ -36,3 +39,21 @@ def test_both_none(self):
|
36 | 39 | self.client = InfluxDBClient(url=self.client.url, token="my-token")
|
37 | 40 | org = get_org_query_param(None, self.client)
|
38 | 41 | self.assertIsNone(org)
|
| 42 | + |
| 43 | + def test_not_permission_to_read_org(self): |
| 44 | + # Create Token without permission to read Organizations |
| 45 | + resource = PermissionResource(type="buckets", org_id=self.find_my_org().id) |
| 46 | + authorization = self.client \ |
| 47 | + .authorizations_api() \ |
| 48 | + .create_authorization(org_id=self.find_my_org().id, |
| 49 | + permissions=[Permission(resource=resource, action="read"), |
| 50 | + Permission(resource=resource, action="write")]) |
| 51 | + self.client.close() |
| 52 | + |
| 53 | + # Initialize client without permission to read Organizations |
| 54 | + self.client = InfluxDBClient(url=self.client.url, token=authorization.token) |
| 55 | + |
| 56 | + with pytest.raises(InfluxDBError) as e: |
| 57 | + get_org_query_param("my-org", self.client, required_id=True) |
| 58 | + assert "The client cannot find organization with name: 'my-org' to determine their ID. Are you using token " \ |
| 59 | + "with sufficient permission?" in f"{e.value} " |
0 commit comments