From 6d05e6d07b949a81bbe199b755b9100018065a1a Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Fri, 17 May 2019 11:25:22 +0200 Subject: [PATCH 1/3] Added prefix to tests and doc --- README.md | 2 +- demo.py | 4 +++- tests/test_client.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8236022..b235ff0 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Does not make any call to the server. from deepomatic.api.client import Client # If you don't have your credentials, contact us at support@deepomatic.com -client = Client(app_id, api_key) +client = Client(app_id, api_key, user_agent_prefix='my-app/1.0.0') ``` ### Client methods diff --git a/demo.py b/demo.py index 9b8f609..9961be2 100644 --- a/demo.py +++ b/demo.py @@ -8,6 +8,7 @@ import hashlib import requests +from deepomatic.api.version import __title__, __version__ from deepomatic.api.client import Client from deepomatic.api.inputs import ImageInput @@ -45,7 +46,7 @@ def demo(client=None): if client is None: app_id = os.getenv('DEEPOMATIC_APP_ID') api_key = os.getenv('DEEPOMATIC_API_KEY') - client = Client(app_id, api_key) # this would be equivalent to using `Client()` in this case. + client = Client(app_id, api_key, user_agent_prefix='{}-demo/{}'.format(__title__, __version__)) # this would be equivalent to using `Client()` in this case. ################### # Public networks # @@ -352,6 +353,7 @@ def download_file(url): shutil.copyfileobj(r.raw, f) return filename + def print_header(text): logger.info("**** {} ****".format(text)) diff --git a/tests/test_client.py b/tests/test_client.py index 5ae30e8..9724ba0 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -6,6 +6,7 @@ import hashlib import shutil import requests +from deepomatic.api.version import __title__, __version__ from deepomatic.api.client import Client from deepomatic.api.inputs import ImageInput from pytest_voluptuous import S @@ -42,7 +43,7 @@ def client(): api_host = os.getenv('DEEPOMATIC_API_URL') app_id = os.environ['DEEPOMATIC_APP_ID'] api_key = os.environ['DEEPOMATIC_API_KEY'] - yield Client(app_id, api_key, host=api_host) + yield Client(app_id, api_key, host=api_host, user_agent_prefix='{}-tests/{}'.format(__title__, __version__)) @pytest.fixture(scope='session') From 12873c8c2cca21acf06a527afd956867378cd41e Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Fri, 17 May 2019 11:31:24 +0200 Subject: [PATCH 2/3] comments --- demo.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/demo.py b/demo.py index 9961be2..80bd644 100644 --- a/demo.py +++ b/demo.py @@ -38,15 +38,16 @@ def demo(client=None): ######### # You can create a client in two ways: - # i) explicitly: you pass your APP_ID and API_KEY by calling `client = Client(app_id, api_key)` + # i) explicitly: you pass your APP_ID and API_KEY by calling `client = Client(app_id, api_key, user_agent_prefix='my-app/1.0.0')` # ii) implicitly: you define environment variables `DEEPOMATIC_APP_ID` and `DEEPOMATIC_API_KEY` - # and just call `client = Client()` + # and just call `client = Client(user_agent_prefix='my-app/1.0.0')` # + # In both ways `user_agent_prefix` parameter is optional but recommended to identify your app to the API # Here we actually use a mix of those two methods to illustrate: if client is None: app_id = os.getenv('DEEPOMATIC_APP_ID') api_key = os.getenv('DEEPOMATIC_API_KEY') - client = Client(app_id, api_key, user_agent_prefix='{}-demo/{}'.format(__title__, __version__)) # this would be equivalent to using `Client()` in this case. + client = Client(app_id, api_key, user_agent_prefix='{}-demo/{}'.format(__title__, __version__)) ################### # Public networks # From feec34941cdc4e07085c5470ef0a4996fcb55be7 Mon Sep 17 00:00:00 2001 From: Hugo Maingonnat Date: Fri, 17 May 2019 11:34:46 +0200 Subject: [PATCH 3/3] fix tests --- tests/test_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 9724ba0..86518cb 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -142,7 +142,7 @@ class TestClient(object): def test_headers(self, client): http_helper = client.http_helper session_headers = http_helper.session.headers - assert session_headers['User-Agent'].startswith('deepomatic-api/') + assert session_headers['User-Agent'].startswith('{}-tests/{} {}/{}'.format(__title__, __version__, __title__, __version__)) assert 'platform/' in session_headers['User-Agent'] assert 'python/' in session_headers['User-Agent'] assert session_headers['X-APP-ID']