diff --git a/CHANGELOG.md b/CHANGELOG.md index d03ebaf9..55090f0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 1.5.0 [unreleased] +### Features +1. [#59](https://github.com/influxdata/influxdb-client-python/issues/59): Set User-Agent to influxdb-client-python/VERSION for all requests + ## 1.4.0 [2020-02-14] ### Features diff --git a/influxdb_client/api_client.py b/influxdb_client/api_client.py index 8768e63a..808d8b96 100644 --- a/influxdb_client/api_client.py +++ b/influxdb_client/api_client.py @@ -75,7 +75,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None, self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = 'OpenAPI-Generator/1.5.0dev/python' + self.user_agent = 'influxdb-client-python/1.5.0dev' def __del__(self): if self._pool: diff --git a/openapi-generator/src/main/resources/python/api_client.mustache b/openapi-generator/src/main/resources/python/api_client.mustache index 1103c2bc..8d48c141 100644 --- a/openapi-generator/src/main/resources/python/api_client.mustache +++ b/openapi-generator/src/main/resources/python/api_client.mustache @@ -70,7 +70,7 @@ class ApiClient(object): self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/python{{/httpUserAgent}}' + self.user_agent = 'influxdb-client-python/{{{packageVersion}}}' def __del__(self): if self._pool: diff --git a/tests/test_TasksApi.py b/tests/test_TasksApi.py index da0bb31a..f16d892e 100644 --- a/tests/test_TasksApi.py +++ b/tests/test_TasksApi.py @@ -377,6 +377,7 @@ def test_cancel_run_not_exist(self): assert "failed to cancel run" in e.value.body assert "run not found" in e.value.body + @pytest.mark.skip(reason="uncomment after beta") def test_cancel_task_not_exist(self): with pytest.raises(ApiException) as e: assert self.tasks_api.cancel_run("020f755c3c082000", "020f755c3c082000") diff --git a/tests/test_WriteApiBatching.py b/tests/test_WriteApiBatching.py index 0411b799..393fa586 100644 --- a/tests/test_WriteApiBatching.py +++ b/tests/test_WriteApiBatching.py @@ -365,6 +365,19 @@ def test_default_tags(self): self.assertNotEqual(-1, request.find('customer=California\\\\ Miner')) self.assertNotEqual(-1, request.find('id=132-987-655')) + def test_user_agent_header(self): + httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204) + + self._write_client.write("my-bucket", "my-org", + ["h2o_feet,location=coyote_creek level\\ water_level=1.0 1", + "h2o_feet,location=coyote_creek level\\ water_level=2.0 2"]) + + time.sleep(1) + + requests = httpretty.httpretty.latest_requests + self.assertEqual(1, len(requests)) + self.assertEqual(f'influxdb-client-python/{influxdb_client.__version__}', requests[0].headers['User-Agent']) + if __name__ == '__main__': unittest.main()