Skip to content

Commit

Permalink
feat: add User-Agent request header (#60)
Browse files Browse the repository at this point in the history
* chore: fix tests (beta vs nightly)
  • Loading branch information
bednar authored Feb 27, 2020
1 parent 716b6b3 commit b0cb4ab
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion influxdb_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_TasksApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 13 additions & 0 deletions tests/test_WriteApiBatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit b0cb4ab

Please sign in to comment.