Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: url attribute type validation #672

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.47.0 [unreleased]

### Bug Fixes
1. [#672](https://github.com/influxdata/influxdb-client-python/pull/672): Adding type validation to url attribute in client object

## 1.46.0 [2024-09-13]

### Bug Fixes
Expand Down
2 changes: 2 additions & 0 deletions influxdb_client/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
self.default_tags = default_tags

self.conf = _Configuration()
if not isinstance(self.url, str):
raise ValueError('"url" attribute is not str instance')
if self.url.endswith("/"):
self.conf.host = self.url[:-1]
else:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_InfluxDBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,35 @@ def test_version(self):
version = self.client.version()
self.assertTrue(len(version) > 0)

def test_url_attribute(self):
# Wrong URL attribute
wrong_types = [
None,
True, False,
123, 123.5,
dict({"url" : "http://localhost:8086"}),
list(["http://localhost:8086"]),
tuple(("http://localhost:8086"))
]
correct_types = [
"http://localhost:8086"
]
for url_type in wrong_types:
try:
client_not_running = InfluxDBClient(url=url_type, token="my-token", debug=True)
status = True
except ValueError as e:
status = False
self.assertFalse(status)
for url_type in correct_types:
try:
client_not_running = InfluxDBClient(url=url_type, token="my-token", debug=True)
status = True
except ValueError as e:
status = False
self.assertTrue(status)


def test_build(self):
build = self.client.build()
self.assertEqual('oss', build.lower())
Expand Down